1+ import importlib
2+ import io
3+ import os
4+ import sys
5+ from pathlib import Path
6+ from unittest import TestCase , skipIf
7+ from unittest .mock import patch
8+ from datetime import date , timedelta
9+
10+ file_path = Path (__file__ ).absolute ().parent / 'main.py'
11+ is_file_empty = os .stat (file_path ).st_size == 0
12+
13+
14+ @skipIf (is_file_empty , 'Empty file. Test 013 Skipped' )
15+ class TestWhatColorIsThatSquare (TestCase ):
16+
17+ def setUp (self ) -> None :
18+ self .module_name = 'projects.m1.013-birth-date-to-astrological-sign.python.main'
19+
20+ @patch ('builtins.input' )
21+ def test_ok_capricorn (self , mock_inputs ):
22+ """
23+ Check if return 'capricorn' in the output
24+ """
25+
26+ min_date = date (2022 , 12 , 22 )
27+ max_date = date (2023 , 1 , 19 )
28+
29+ delta = max_date - min_date
30+
31+ for i in range (delta .days + 1 ):
32+ next_date = min_date + timedelta (days = i )
33+ month_ = next_date .strftime ('%B' ) # return the name of the month
34+ day_ = next_date .day
35+
36+ mock_inputs .side_effect = [month_ , day_ ]
37+
38+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
39+ sys .modules .pop (self .module_name , None )
40+ importlib .import_module (name = self .module_name , package = 'files' )
41+
42+ result = mock_print .getvalue ().lower ()
43+ self .assertIn ('capricorn' , result , f'{ month_ } { day_ } sign is capricorn.' )
44+
45+ @patch ('builtins.input' )
46+ def test_ok_aquarius (self , mock_inputs ):
47+ """
48+ Check if return 'aquarius' in the output
49+ """
50+
51+ min_date = date (2023 , 1 , 20 )
52+ max_date = date (2023 , 2 , 18 )
53+
54+ delta = max_date - min_date
55+
56+ for i in range (delta .days + 1 ):
57+ next_date = min_date + timedelta (days = i )
58+ month_ = next_date .strftime ('%B' ) # return the name of the month
59+ day_ = next_date .day
60+
61+ mock_inputs .side_effect = [month_ , day_ ]
62+
63+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
64+ sys .modules .pop (self .module_name , None )
65+ importlib .import_module (name = self .module_name , package = 'files' )
66+
67+ result = mock_print .getvalue ().lower ()
68+ self .assertIn ('aquarius' , result , f'The sign of { month_ } { day_ } is aquarius.' )
69+
70+ @patch ('builtins.input' )
71+ def test_ok_pisces (self , mock_inputs ):
72+ """
73+ Check if return 'pisces' in the output
74+ """
75+
76+ min_date = date (2023 , 2 , 19 )
77+ max_date = date (2023 , 3 , 20 )
78+
79+ delta = max_date - min_date
80+
81+ for i in range (delta .days + 1 ):
82+ next_date = min_date + timedelta (days = i )
83+ month_ = next_date .strftime ('%B' ) # return the name of the month
84+ day_ = next_date .day
85+
86+ mock_inputs .side_effect = [month_ , day_ ]
87+
88+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
89+ sys .modules .pop (self .module_name , None )
90+ importlib .import_module (name = self .module_name , package = 'files' )
91+
92+ result = mock_print .getvalue ().lower ()
93+ self .assertIn ('pisces' , result , f'The sign of { month_ } { day_ } is pisces.' )
94+
95+ @patch ('builtins.input' )
96+ def test_ok_aries (self , mock_inputs ):
97+ """
98+ Check if return 'aries' in the output
99+ """
100+
101+ min_date = date (2023 , 3 , 21 )
102+ max_date = date (2023 , 4 , 19 )
103+
104+ delta = max_date - min_date
105+
106+ for i in range (delta .days + 1 ):
107+ next_date = min_date + timedelta (days = i )
108+ month_ = next_date .strftime ('%B' ) # return the name of the month
109+ day_ = next_date .day
110+
111+ mock_inputs .side_effect = [month_ , day_ ]
112+
113+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
114+ sys .modules .pop (self .module_name , None )
115+ importlib .import_module (name = self .module_name , package = 'files' )
116+
117+ result = mock_print .getvalue ().lower ()
118+ self .assertIn ('aries' , result , f'The sign of { month_ } { day_ } is aries.' )
119+
120+ @patch ('builtins.input' )
121+ def test_ok_taurus (self , mock_inputs ):
122+ """
123+ Check if return 'taurus' in the output
124+ """
125+
126+ min_date = date (2023 , 4 , 20 )
127+ max_date = date (2023 , 5 , 20 )
128+
129+ delta = max_date - min_date
130+
131+ for i in range (delta .days + 1 ):
132+ next_date = min_date + timedelta (days = i )
133+ month_ = next_date .strftime ('%B' ) # return the name of the month
134+ day_ = next_date .day
135+
136+ mock_inputs .side_effect = [month_ , day_ ]
137+
138+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
139+ sys .modules .pop (self .module_name , None )
140+ importlib .import_module (name = self .module_name , package = 'files' )
141+
142+ result = mock_print .getvalue ().lower ()
143+ self .assertIn ('taurus' , result , f'The sign of { month_ } { day_ } is taurus.' )
144+
145+ @patch ('builtins.input' )
146+ def test_ok_gemini (self , mock_inputs ):
147+ """
148+ Check if return 'gemini' in the output
149+ """
150+
151+ min_date = date (2023 , 5 , 21 )
152+ max_date = date (2023 , 6 , 20 )
153+
154+ delta = max_date - min_date
155+
156+ for i in range (delta .days + 1 ):
157+ next_date = min_date + timedelta (days = i )
158+ month_ = next_date .strftime ('%B' ) # return the name of the month
159+ day_ = next_date .day
160+
161+ mock_inputs .side_effect = [month_ , day_ ]
162+
163+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
164+ sys .modules .pop (self .module_name , None )
165+ importlib .import_module (name = self .module_name , package = 'files' )
166+
167+ result = mock_print .getvalue ().lower ()
168+ self .assertIn ('gemini' , result , f'The sign of { month_ } { day_ } is gemini.' )
169+
170+ @patch ('builtins.input' )
171+ def test_ok_cancer (self , mock_inputs ):
172+ """
173+ Check if return 'cancer' in the output
174+ """
175+
176+ min_date = date (2023 , 6 , 21 )
177+ max_date = date (2023 , 7 , 22 )
178+
179+ delta = max_date - min_date
180+
181+ for i in range (delta .days + 1 ):
182+ next_date = min_date + timedelta (days = i )
183+ month_ = next_date .strftime ('%B' ) # return the name of the month
184+ day_ = next_date .day
185+
186+ mock_inputs .side_effect = [month_ , day_ ]
187+
188+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
189+ sys .modules .pop (self .module_name , None )
190+ importlib .import_module (name = self .module_name , package = 'files' )
191+
192+ result = mock_print .getvalue ().lower ()
193+ self .assertIn ('cancer' , result , f'The sign of { month_ } { day_ } is cancer.' )
194+
195+ @patch ('builtins.input' )
196+ def test_ok_leo (self , mock_inputs ):
197+ """
198+ Check if return 'leo' in the output
199+ """
200+
201+ min_date = date (2023 , 7 , 23 )
202+ max_date = date (2023 , 8 , 22 )
203+
204+ delta = max_date - min_date
205+
206+ for i in range (delta .days + 1 ):
207+ next_date = min_date + timedelta (days = i )
208+ month_ = next_date .strftime ('%B' ) # return the name of the month
209+ day_ = next_date .day
210+
211+ mock_inputs .side_effect = [month_ , day_ ]
212+
213+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
214+ sys .modules .pop (self .module_name , None )
215+ importlib .import_module (name = self .module_name , package = 'files' )
216+
217+ result = mock_print .getvalue ().lower ()
218+ self .assertIn ('leo' , result , f'The sign of { month_ } { day_ } is leo.' )
219+
220+ @patch ('builtins.input' )
221+ def test_ok_virgo (self , mock_inputs ):
222+ """
223+ Check if return 'virgo' in the output
224+ """
225+
226+ min_date = date (2023 , 8 , 23 )
227+ max_date = date (2023 , 9 , 22 )
228+
229+ delta = max_date - min_date
230+
231+ for i in range (delta .days + 1 ):
232+ next_date = min_date + timedelta (days = i )
233+ month_ = next_date .strftime ('%B' ) # return the name of the month
234+ day_ = next_date .day
235+
236+ mock_inputs .side_effect = [month_ , day_ ]
237+
238+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
239+ sys .modules .pop (self .module_name , None )
240+ importlib .import_module (name = self .module_name , package = 'files' )
241+
242+ result = mock_print .getvalue ().lower ()
243+ self .assertIn ('virgo' , result , f'The sign of { month_ } { day_ } is virgo.' )
244+
245+ @patch ('builtins.input' )
246+ def test_ok_libra (self , mock_inputs ):
247+ """
248+ Check if return 'libra' in the output
249+ """
250+
251+ min_date = date (2023 , 9 , 23 )
252+ max_date = date (2023 , 10 , 22 )
253+
254+ delta = max_date - min_date
255+
256+ for i in range (delta .days + 1 ):
257+ next_date = min_date + timedelta (days = i )
258+ month_ = next_date .strftime ('%B' ) # return the name of the month
259+ day_ = next_date .day
260+
261+ mock_inputs .side_effect = [month_ , day_ ]
262+
263+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
264+ sys .modules .pop (self .module_name , None )
265+ importlib .import_module (name = self .module_name , package = 'files' )
266+
267+ result = mock_print .getvalue ().lower ()
268+ self .assertIn ('libra' , result , f'The sign of { month_ } { day_ } is libra.' )
269+
270+ @patch ('builtins.input' )
271+ def test_ok_scorpio (self , mock_inputs ):
272+ """
273+ Check if return 'scorpio' in the output
274+ """
275+
276+ min_date = date (2023 , 10 , 23 )
277+ max_date = date (2023 , 11 , 21 )
278+
279+ delta = max_date - min_date
280+
281+ for i in range (delta .days + 1 ):
282+ next_date = min_date + timedelta (days = i )
283+ month_ = next_date .strftime ('%B' ) # return the name of the month
284+ day_ = next_date .day
285+
286+ mock_inputs .side_effect = [month_ , day_ ]
287+
288+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
289+ sys .modules .pop (self .module_name , None )
290+ importlib .import_module (name = self .module_name , package = 'files' )
291+
292+ result = mock_print .getvalue ().lower ()
293+ self .assertIn ('scorpio' , result , f'The sign of { month_ } { day_ } is scorpio.' )
294+
295+ @patch ('builtins.input' )
296+ def test_ok_sagittarius (self , mock_inputs ):
297+ """
298+ Check if return 'sagittarius' in the output
299+ """
300+
301+ min_date = date (2023 , 11 , 22 )
302+ max_date = date (2023 , 12 , 21 )
303+
304+ delta = max_date - min_date
305+
306+ for i in range (delta .days + 1 ):
307+ next_date = min_date + timedelta (days = i )
308+ month_ = next_date .strftime ('%B' ) # return the name of the month
309+ day_ = next_date .day
310+
311+ mock_inputs .side_effect = [month_ , day_ ]
312+
313+ with patch ('sys.stdout' , new_callable = io .StringIO ) as mock_print :
314+ sys .modules .pop (self .module_name , None )
315+ importlib .import_module (name = self .module_name , package = 'files' )
316+
317+ result = mock_print .getvalue ().lower ()
318+ self .assertIn ('sagittarius' , result , f'The sign of { month_ } { day_ } is sagittarius.' )
0 commit comments