generated from Coding-Cuddles/bootstrap-python-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_expense_report.py
87 lines (66 loc) · 2.06 KB
/
test_expense_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pytest
import textwrap
from expense_report import ExpenseReport, Expense, ExpenseType, ReportPrinter
class MockReportPrinter(ReportPrinter):
def __init__(self):
self.text = ""
def print(self, text):
self.text += f"{text}\n"
@pytest.fixture
def report():
return ExpenseReport()
@pytest.fixture
def printer():
return MockReportPrinter()
def test_print_empty(report, printer):
report.print_report(printer)
expected_output = textwrap.dedent("""
Expense Report
--------------
--------------
Meal Total: 0.00
Total: 0.00
""").lstrip()
assert printer.text == expected_output
def test_print_one_dinner(report, printer):
report.add_expense(Expense(ExpenseType.DINNER, 3000))
report.print_report(printer)
expected_output = textwrap.dedent("""
Expense Report
--------------
Dinner\t30.00\t
--------------
Meal Total: 33.00
Total: 33.00
""").lstrip()
assert printer.text == expected_output
def test_print_two_meals_and_dinner_over(report, printer):
report.add_expense(Expense(ExpenseType.DINNER, 6000))
report.add_expense(Expense(ExpenseType.BREAKFAST, 1000))
report.print_report(printer)
expected_output = textwrap.dedent("""
Expense Report
--------------
Dinner\t60.00\tX
Breakfast\t10.00\t
--------------
Meal Total: 76.50
Total: 76.50
""").lstrip()
assert printer.text == expected_output
def test_print_mix_and_dinner_over(report, printer):
report.add_expense(Expense(ExpenseType.DINNER, 5000))
report.add_expense(Expense(ExpenseType.BREAKFAST, 2000))
report.add_expense(Expense(ExpenseType.LODGING, 3000))
report.print_report(printer)
expected_output = textwrap.dedent("""
Expense Report
--------------
Dinner\t50.00\t
Breakfast\t20.00\tX
Lodging\t30.00\t
--------------
Meal Total: 76.00
Total: 110.50
""").lstrip()
assert printer.text == expected_output