Best Python code snippet using freezegun
roomSearch.py
Source:roomSearch.py
...17 return room_label18def return_weekNo(dateNo):19 # changing timezone to Singapore's20 local_tz = pytz.timezone('Asia/Singapore')21 currentDate = dateNo.replace(tzinfo=pytz.UTC).astimezone(local_tz)22 startOfweek1 = datetime.datetime(2020, 7, 26).replace(tzinfo=pytz.utc).astimezone(local_tz)23 endOfweek1 = datetime.datetime(2020, 8, 18).replace(tzinfo=pytz.utc).astimezone(local_tz)24 startOfweek2 = datetime.datetime(2020, 8, 19).replace(tzinfo=pytz.utc).astimezone(local_tz)25 endOfweek2 = datetime.datetime(2020, 8, 25).replace(tzinfo=pytz.utc).astimezone(local_tz)26 startOfweek3 = datetime.datetime(2020, 8, 26).replace(tzinfo=pytz.utc).astimezone(local_tz)27 endOfweek3 = datetime.datetime(2020, 9, 1).replace(tzinfo=pytz.utc).astimezone(local_tz)28 startOfweek4 = datetime.datetime(2020, 9, 2).replace(tzinfo=pytz.utc).astimezone(local_tz)29 endOfweek4 = datetime.datetime(2020, 9, 8).replace(tzinfo=pytz.utc).astimezone(local_tz)30 startOfweek5 = datetime.datetime(2020, 9, 9).replace(tzinfo=pytz.utc).astimezone(local_tz)31 endOfweek5 = datetime.datetime(2020, 9, 15).replace(tzinfo=pytz.utc).astimezone(local_tz)32 startOfweek6 = datetime.datetime(2020, 9, 16).replace(tzinfo=pytz.utc).astimezone(local_tz)33 endOfweek6 = datetime.datetime(2020, 9, 22).replace(tzinfo=pytz.utc).astimezone(local_tz)34 startOfweek7 = datetime.datetime(2020, 9, 30).replace(tzinfo=pytz.utc).astimezone(local_tz)35 endOfweek7 = datetime.datetime(2020, 10, 6).replace(tzinfo=pytz.utc).astimezone(local_tz)36 startOfweek8 = datetime.datetime(2020, 10, 7).replace(tzinfo=pytz.utc).astimezone(local_tz)37 endOfweek8 = datetime.datetime(2020, 10, 13).replace(tzinfo=pytz.utc).astimezone(local_tz)38 startOfweek9 = datetime.datetime(2020, 10, 14).replace(tzinfo=pytz.utc).astimezone(local_tz)39 endOfweek9 = datetime.datetime(2020, 10, 20).replace(tzinfo=pytz.utc).astimezone(local_tz)40 startOfweek10 = datetime.datetime(2020, 10, 21).replace(tzinfo=pytz.utc).astimezone(local_tz)41 endOfweek10 = datetime.datetime(2020, 10, 27).replace(tzinfo=pytz.utc).astimezone(local_tz)42 startOfweek11 = datetime.datetime(2020, 10, 28).replace(tzinfo=pytz.utc).astimezone(local_tz)43 endOfweek11 = datetime.datetime(2020, 11, 3).replace(tzinfo=pytz.utc).astimezone(local_tz)44 startOfweek12 = datetime.datetime(2020, 11, 4).replace(tzinfo=pytz.utc).astimezone(local_tz)45 endOfweek12 = datetime.datetime(2020, 11, 10).replace(tzinfo=pytz.utc).astimezone(local_tz)46 startOfweek13 = datetime.datetime(2020, 11, 11).replace(tzinfo=pytz.utc).astimezone(local_tz)47 endOfweek13 = datetime.datetime(2020, 11, 17).replace(tzinfo=pytz.utc).astimezone(local_tz)48 if startOfweek1 <= currentDate <= endOfweek1:49 return "1"50 elif startOfweek2 <= currentDate <= endOfweek2:51 return "2"52 elif startOfweek3 <= currentDate <= endOfweek3:53 return "3"54 elif startOfweek4 <= currentDate <= endOfweek4:55 return "4"56 elif startOfweek5 <= currentDate <= endOfweek5:57 return "5"58 elif startOfweek6 <= currentDate <= endOfweek6:59 return "6"60 elif startOfweek7 <= currentDate <= endOfweek7:61 return "7"...
mocks.py
Source:mocks.py
...36 'year': YEAR, 'month': MONTH,37 'hour': 3, 'minute': 59, 'second': 59, 'microsecond': 99999938}39FRIDAY_PREMARKET_START = NEW_YORK_TZ.localize(datetime(40 day=14, **PREMARKET_START)).astimezone(pytz.utc)41FRIDAY_PREMARKET_END = NEW_YORK_TZ.localize(42 datetime(day=14, **PREMARKET_END)).astimezone(pytz.utc)43FRIDAY_MARKET_START = NEW_YORK_TZ.localize(44 datetime(day=14, **MARKET_START)).astimezone(pytz.utc)45FRIDAY_MARKET_END = NEW_YORK_TZ.localize(46 datetime(day=14, **MARKET_END)).astimezone(pytz.utc)47FRIDAY_AFTERHOURS_START = NEW_YORK_TZ.localize(datetime(48 day=14, **AFTERHOURS_START)).astimezone(pytz.utc)49FRIDAY_AFTERHOURS_END = NEW_YORK_TZ.localize(50 datetime(day=14, **AFTERHOURS_END)).astimezone(pytz.utc)51FRIDAY_CLOSED_START = NEW_YORK_TZ.localize(52 datetime(day=14, **CLOSED_START)).astimezone(pytz.utc)53FRIDAY_CLOSED_END = NEW_YORK_TZ.localize(54 datetime(day=14, **CLOSED_END)).astimezone(pytz.utc)55SATURDAY_PREMARKET_START = NEW_YORK_TZ.localize(datetime(56 day=15, **PREMARKET_START)).astimezone(pytz.utc)57SATURDAY_PREMARKET_END = NEW_YORK_TZ.localize(58 datetime(day=15, **PREMARKET_END)).astimezone(pytz.utc)59SATURDAY_MARKET_START = NEW_YORK_TZ.localize(60 datetime(day=15, **MARKET_START)).astimezone(pytz.utc)61SATURDAY_MARKET_END = NEW_YORK_TZ.localize(62 datetime(day=15, **MARKET_END)).astimezone(pytz.utc)63SUNDAY_AFTERHOURS_START = NEW_YORK_TZ.localize(datetime(64 day=16, **AFTERHOURS_START)).astimezone(pytz.utc)65SUNDAY_AFTERHOURS_END = NEW_YORK_TZ.localize(66 datetime(day=16, **AFTERHOURS_END)).astimezone(pytz.utc)67SUNDAY_CLOSED_START = NEW_YORK_TZ.localize(68 datetime(day=16, **CLOSED_START)).astimezone(pytz.utc)69SUNDAY_CLOSED_END = NEW_YORK_TZ.localize(70 datetime(day=16, **CLOSED_END)).astimezone(pytz.utc)71# DST72PREMARKET_START_DST = PREMARKET_START.copy()73PREMARKET_START_DST.update({'month': MONTH_DST})74PREMARKET_END_DST = PREMARKET_END.copy()75PREMARKET_END_DST.update({'month': MONTH_DST})76MARKET_START_DST = MARKET_START.copy()77MARKET_START_DST.update({'month': MONTH_DST})78MARKET_END_DST = MARKET_END.copy()79MARKET_END_DST.update({'month': MONTH_DST})80AFTERHOURS_START_DST = AFTERHOURS_START.copy()81AFTERHOURS_START_DST.update({'month': MONTH_DST})82AFTERHOURS_END_DST = AFTERHOURS_END.copy()83AFTERHOURS_END_DST.update({'month': MONTH_DST})84CLOSED_START_DST = CLOSED_START.copy()85CLOSED_START_DST.update({'month': MONTH_DST})86CLOSED_END_DST = CLOSED_END.copy()87CLOSED_END_DST.update({'month': MONTH_DST})88FRIDAY_PREMARKET_START_DST = NEW_YORK_TZ.localize(datetime(89 day=13, **PREMARKET_START_DST)).astimezone(pytz.utc)90FRIDAY_PREMARKET_END_DST = NEW_YORK_TZ.localize(datetime(91 day=13, **PREMARKET_END_DST)).astimezone(pytz.utc)92FRIDAY_MARKET_START_DST = NEW_YORK_TZ.localize(datetime(93 day=13, **MARKET_START_DST)).astimezone(pytz.utc)94FRIDAY_MARKET_END_DST = NEW_YORK_TZ.localize(95 datetime(day=13, **MARKET_END_DST)).astimezone(pytz.utc)96FRIDAY_AFTERHOURS_START_DST = NEW_YORK_TZ.localize(datetime(97 day=13, **AFTERHOURS_START_DST)).astimezone(pytz.utc)98FRIDAY_AFTERHOURS_END_DST = NEW_YORK_TZ.localize(datetime(99 day=13, **AFTERHOURS_END_DST)).astimezone(pytz.utc)100FRIDAY_CLOSED_START_DST = NEW_YORK_TZ.localize(datetime(101 day=13, **CLOSED_START_DST)).astimezone(pytz.utc)102FRIDAY_CLOSED_END_DST = NEW_YORK_TZ.localize(103 datetime(day=13, **CLOSED_END_DST)).astimezone(pytz.utc)104def create_datetime(*args, **kw):...
test_parse.py
Source:test_parse.py
...4class ScheduleParserTests(TestCase):5 def test_parse1(self):6 line = 'ABEL LUIS SANTANA ARAUJO\n1988-09-22\nUAPS CARLOS RIBEIRO\n2021-07-06\n11:00:00\n1\n'7 sp = ScheduleParser(line)8 self.assertEqual(sp.datetime().astimezone(), datetime(9 2021, 7, 6, hour=11, tzinfo=ZN_FORT).astimezone())10 print(sp.datetime())11 self.assertTrue(sp.is_valid)12 def test_parse2(self):13 line = 'ADALBERTO FERREIRA DA SILVA\n 1980-03-04 SHOPPING RIOMAR FORTALEZA PAPICU PISO L3\n 2021-06-24\n 13:00:00\n 1'14 sp = ScheduleParser(line, True)15 self.assertEqual(sp.datetime().astimezone(), datetime(16 2021, 6, 24, hour=13, tzinfo=ZN_FORT).astimezone())17 self.assertTrue(sp.is_valid)18 def test_parse3(self):19 line = 'ABEL LUIS SANTANA ARAUJO\n1988-09-22\nUAPS CARLOS RIBEIRO\n2021-07-06 11:00:00 1'20 sp = ScheduleParser(line)21 self.assertEqual(sp.datetime().astimezone(), datetime(22 2021, 7, 6, hour=11, tzinfo=ZN_FORT).astimezone())23 self.assertTrue(sp.is_valid)24 def test_parse4(self):25 line = 'AARAO BAYDE RIBEIRO\n 1982-03-21\n SHOPPING RIOM\n AR FORTALEZA PAPICU PISO L3\n 2021-06-26\n 09:00:00\n 1\n'26 sp = ScheduleParser(line)27 self.assertEqual(sp.datetime().astimezone(), datetime(28 2021, 6, 26, hour=9, tzinfo=ZN_FORT).astimezone())29 self.assertTrue(sp.is_valid)30 def test_parse5(self):31 line = 'ADAILTON XAVIER DOS SANTOS\n 1977-01-29 SHOPPING RIOMAR FORTALEZA PAPICU PISO L3\n 2021-07-08\n 11:00:00 1\n'32 sp = ScheduleParser(line)33 self.assertEqual(sp.datetime().astimezone(), datetime(34 2021, 7, 8, hour=11, tzinfo=ZN_FORT).astimezone())35 self.assertTrue(sp.is_valid)36 def test_parse6(self):37 line = 'ADILSON RODRIGUES LOURENCO\n 1986-01-25\n NORTH SHOPPING JOQUEI - PIS0 3\n 2021-07-02 16:00:00\n 1\n'38 sp = ScheduleParser(line)39 self.assertEqual(sp.datetime().astimezone(), datetime(40 2021, 7, 2, hour=16, tzinfo=ZN_FORT).astimezone())41 self.assertTrue(sp.is_valid)42 def test_parse7(self):43 line = 'ABRAAO CORDEIRO M\n ELO\n 1984-06-01\n UAPS HUM\n BERTO BEZERA\n 2021-06-26\n 16:30:00\n 1\n'44 sp = ScheduleParser(line)45 self.assertEqual(sp.datetime().astimezone(), datetime(46 2021, 6, 26, hour=16, minute=30, tzinfo=ZN_FORT).astimezone())47 self.assertTrue(sp.is_valid)48 def test_parse8(self):49 line = 'ADERSON KLERTON ALMEIDA DE SOUSA\n 21/01/1981\n CENTRO DE EVENTOS DO CEARÃ - SALÃO TAÃBA\n 30.05.2021\n 13:00\n 1\n'50 sp = ScheduleParser(line)51 self.assertEqual(sp.datetime().astimezone(), datetime(52 2021, 5, 30, hour=13, tzinfo=ZN_FORT).astimezone())53 self.assertTrue(sp.is_valid)54 def test_parse_D3(self):55 line = 'ANTONIA HOSANA DE SOUSA GUERRA\n 08/12/1940\n SHOPPING IGUATEMI - PISO TERREO EXPANSAO\n 06/10/2021\n 16:00:00\n 3\n'56 sp = ScheduleParser(line, True)57 self.assertEqual(sp.datetime().astimezone(), datetime(58 2021, 10, 6, hour=16, tzinfo=ZN_FORT).astimezone())59 self.assertTrue(sp.is_valid)60 def test_datetime(self):61 line = 'ABEL LUIS SANTANA ARAUJO\n1988-09-22\nUAPS CARLOS RIBEIRO\n2021-07-06\n11:00:00\n1\n'62 sp = ScheduleParser(line)63 self.assertEqual(sp.datetime().astimezone(), datetime(64 2021, 7, 6, hour=11, tzinfo=ZN_FORT).astimezone())65 datetime66 def test_invalid_parse(self):67 line = 'ABEL LUIS S23423ANTANA ARAUJO\nUAPS CARL234OS RIBEIRO\n2021-07-06 11:00:00 21\n'68 sp = ScheduleParser(line)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!