-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_project.py
65 lines (44 loc) · 2.3 KB
/
test_project.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
import project
import pytest
from unittest.mock import patch
def test_display_menu():
main_menu: str = "---------- EXPENSES MANAGER ---------- \n ---------- MAIN MENU ---------- \n 1 - Add an expense \n 2 - See all expenses \n 3 - Stats Menu \n 4 - Exit program \n"
menu_all_expenses: str = "---------- EXPENSES MANAGER ---------- \n ---------- MENU ALL EXPENSES ---------- \n 1 - See a particular expense \n 2 - Back to main menu \n 3 - Exit program \n"
menu_single_expense: str = "---------- EXPENSES MANAGER ---------- \n ---------- MENU SINGLE EXPENSE ---------- \n 1 - Back to main menu \n 2 - Delete this expense \n 3 - Exit program \n"
menu_stats: str = "---------- EXPENSES MANAGER ---------- \n ---------- MENU SINGLE EXPENSE ---------- \n 1 - Back to main menu \n 2 - See total amount \n 3 - See total per months \n 4 - See average expenses per months \n 5 - See details per months \n 6 - Exit Programm\n"
assert project.display_menu("main_menu") == main_menu
assert project.display_menu("menu_all_expenses") == menu_all_expenses
assert project.display_menu("menu_single_expense") == menu_single_expense
assert project.display_menu("menu_stats") == menu_stats
with pytest.raises(ValueError):
project.display_menu("invalid menu")
@patch('builtins.input', return_value=1)
def test_get_user_choice_1(mock_input):
assert project.get_user_choice() == 1
@patch('builtins.input', return_value=2)
def test_get_user_choice_2(mock_input):
assert project.get_user_choice() == 2
@patch('builtins.input', return_value=3)
def test_get_user_choice_3(mock_input):
assert project.get_user_choice() == 3
def test_system_exit():
with pytest.raises(SystemExit):
project.exit_program()
@patch("project.main")
def test_menu_all_expenses(mock_main):
project.menu_all_expenses(2)
mock_main.assert_called_once()
with pytest.raises(SystemExit):
project.menu_all_expenses(3)
@patch("project.main")
def test_menu_single_expense(mock_main):
project.menu_single_expense(1)
mock_main.assert_called_once()
with pytest.raises(SystemExit):
project.menu_single_expense(3)
@patch("project.main")
def test_menu_stats(mock_main):
project.menu_stats(1)
mock_main.assert_called_once()
with pytest.raises(SystemExit):
project.menu_stats(6)