def test_am_pm_time3(self): input_str = "12:00 am" dt = parse_datetime(input_str) dt_expected = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) dt_expected = add_day_if_past(dt_expected) self.assertEqual(dt, dt_expected)
def test_time_strings(self): # (user input, simulated 'now' time, expected output) times = [ ("07:00", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 7, 0)), ("7:00", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 7, 0)), ("0:00", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 0, 0)), ("17:30", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 1, 17, 30)), ("6:30 am", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 6, 30)), ("6:30 pm", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 1, 18, 30)), ("06:30 am", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 6, 30)), ("06:30 pm", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 1, 18, 30)), ("00:00 am", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 0, 0)), ("12:00 am", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 0, 0)), ("24.06. 12:00", datetime(2020, 6, 24, 9, 0), datetime(2020, 6, 24, 12, 0)), ("24.06. 6:00", datetime(2020, 6, 23, 9, 0), datetime(2020, 6, 24, 6, 0)), ("24.6. 6:00", datetime(2020, 6, 23, 9, 0), datetime(2020, 6, 24, 6, 0)), ("24.6. 06:00", datetime(2020, 6, 23, 9, 0), datetime(2020, 6, 24, 6, 0)), ("24.6. 12:00", datetime(2020, 6, 24, 9, 0), datetime(2020, 6, 24, 12, 0)), ("6.6. 06:06", datetime(2020, 6, 5, 9, 0), datetime(2020, 6, 6, 6, 6)), ("6.6. 6:06", datetime(2020, 6, 5, 9, 0), datetime(2020, 6, 6, 6, 6)), # "04/27 12:00 am", # "04/27 2:00 am", # "04/27 3:00 pm", # "04/27 10:00 pm", # "4/27 10:00 pm", # "4/27 09:00 pm", # "4/27 9:00 pm", # "4/4 9:00 pm", # "4/4 09:00 pm", # "4/4 12:00 pm", ("morning", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 7, 0)), ("evening", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 1, 18, 0)), ("tomorrow", datetime(2020, 1, 1, 9, 0), datetime(2020, 1, 2, 7, 0)), ] for user_input, simulated_now_time, expected_output in times: print(f"testing time: {user_input}") todocli.utils.datetime_util.datetime.now.return_value = simulated_now_time return_val = parse_datetime(user_input) self.assertEqual(return_val, expected_output)
def new(args): task_list, name = parse_task_path(args.task_name) reminder_date_time_str = args.reminder reminder_datetime = None if reminder_date_time_str is not None: reminder_datetime = parse_datetime(reminder_date_time_str) todo_api.create_task(name, task_list, reminder_datetime)
def test_invalid_time(self): invalid_times = [ "24:00", "25:00", "25123:00", "0:12345", "12:30 sam", "12:30 pom", "abfdsa", ] for time in invalid_times: print(f"testing time: {time}") try: self.assertRaises(Exception, parse_datetime(time)) except ErrorParsingTime: pass except TimeExpressionNotRecognized: pass else: raise