forked from Rishabh-0412/Re-ToDo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainTest.py
155 lines (124 loc) · 3.74 KB
/
MainTest.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import os
import unittest
from io import StringIO
from unittest.mock import patch
from Main import main
class Main_Test(unittest.TestCase):
@patch('builtins.input', side_effect=[1, "Complete the assignment", "\n", 2, 0])
def testing_console_for_one_task_and_viewing_it(self, mock_input):
expected_output = '''
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
Incomplete Tasks:
1. Complete the assignment
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
'''
with patch('sys.stdout', new=StringIO()) as fake_out:
main()
self.assertEqual(expected_output, fake_out.getvalue())
os.remove("dump.pkl")
@patch('builtins.input', side_effect=[1, "Complete the assignment", "\n", 1, "Meet Ema at 7", "\n", 3, 1, 2, 0])
def testing_console_for_two_task_and_marking_one_as_complete_then_viewing_it(self, mock_input):
expected_output = '''
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
Incomplete Tasks:
1. Complete the assignment
2. Meet Ema at 7
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
Incomplete Tasks:
1. Meet Ema at 7
Complete Tasks:
1. Complete the assignment
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
'''
with patch('sys.stdout', new=StringIO()) as fake_out:
main()
self.assertEqual(expected_output, fake_out.getvalue())
os.remove("dump.pkl")
@patch('builtins.input', side_effect=[1, "Complete the assignment", "\n", 1, "Meet Ema at 7", "\n", 3, 1, 2, 4, 0])
def testing_console_for_two_task_and_marking_one_as_complete_then_saving_it_to_file(self, mock_input):
with patch('sys.stdout', new=StringIO()) as fake_out:
main()
path_desktop = "." # os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
file_path = path_desktop + "/MyTasks.txt"
with open(file_path, "r") as file:
content = file.readlines()
all_tasks = ''.join([str(elem) for elem in content])
self.assertEqual("Incomplete Tasks:\n1. Meet Ema at 7\nComplete Tasks:\n1. Complete the assignment\n",
all_tasks)
os.remove(file_path)
os.remove("dump.pkl")
@patch('builtins.input', side_effect=[1, "Complete the assignment", "\n", 2, 0, 2, 0])
def testing_console_for_reloading_session(self, mock_input):
expected_output = '''
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
Incomplete Tasks:
1. Complete the assignment
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
Incomplete Tasks:
1. Complete the assignment
0. Exit
1. Add task
2. View task
3. Mark a task as complete
4. Save list to file
'''
with patch('sys.stdout', new=StringIO()) as fake_out:
main()
main()
self.assertEqual(expected_output, fake_out.getvalue())
os.remove("dump.pkl")
if __name__ == '__main__':
unittest.main()