def test_hours_since_with_past_minutes_less(self): tod_past = TimeOfDay(8, 45) tod_now = TimeOfDay(21, 30) self.assertEqual(tod_now.hours_since(tod_past), 12.75)
def test_hours_since_calcs_across_midnight(self): tod_past = TimeOfDay(21, 45) tod_now = TimeOfDay(8, 30) self.assertEqual(tod_now.hours_since(tod_past), 10.75)
def test_hours_until_calcs_across_midnight(self): tod_now = TimeOfDay(21, 45) tod_future = TimeOfDay(8, 30) self.assertEqual(tod_now.hours_until(tod_future), 10.75)
def test_hours_since_with_past_minutes_greater(self): tod_past = TimeOfDay(8, 15) tod_now = TimeOfDay(21, 30) self.assertEqual(tod_now.hours_since(tod_past), 13.25)
def test_hours_until_with_future_minutes_greater(self): tod_now = TimeOfDay(8, 15) tod_future = TimeOfDay(21, 30) self.assertEqual(tod_now.hours_until(tod_future), 13.25)
def test_hours_until_with_future_minutes_less(self): tod_now = TimeOfDay(8, 45) tod_future = TimeOfDay(21, 30) self.assertEqual(tod_now.hours_until(tod_future), 12.75)
def test__str__returns_expected_string(self): tod = TimeOfDay(VALID_24_CLK_TIME_HR, VALID_24_CLK_TIME_MIN) self.assertEqual(str(tod), VALID_24_CLK_TIME_STR)
def test_contructor_saves_values(self): tod = TimeOfDay(VALID_HOUR, VALID_MIN) self.assertEqual(tod.hour, VALID_HOUR) self.assertEqual(tod.minute, VALID_MIN)
def test_from_24_hour_time_works_for_valid_times(self): tod = TimeOfDay.from_24_hour_time(VALID_24_CLK_TIME_STR) self.assertIsInstance(tod, TimeOfDay) self.assertEqual(tod.hour, VALID_24_CLK_TIME_HR) self.assertEqual(tod.minute, VALID_24_CLK_TIME_MIN)
def test_from_24_hour_time_excepts_on_invalid_times(self): with self.assertRaises(InvalidTime) as e: TimeOfDay.from_24_hour_time(INVALID_24_CLK_TIME)
def test_from_12_hour_time_excepts_on_invalid_times(self): for time_str, hr24, min in _some_invalid_12hr_clk_times(): with self.assertRaises(InvalidTime, msg=time_str) as e: TimeOfDay.from_12_hour_time(time_str)
def test_parse_12hr_time_str_to_hour_min_works_for_valid_times(self): for time_str, hr24, min in _all_valid_12hr_clk_times(): h, m = TimeOfDay.parse_12hr_time_str_to_hour_min(time_str) self.assertEqual(hr24, h) self.assertEqual(min, m)
def test_parse_24hr_time_str_to_hour_min_excepts_on_invalid_times(self): for time_str, hr24, min in _some_invalid_24hr_clk_times(): with self.assertRaises(InvalidTime, msg=time_str) as e: TimeOfDay.parse_24hr_time_str_to_hour_min(time_str)
def test_constructor_calls_to_confirm_valid_time(self, valid_time_func_mock): tod = TimeOfDay(VALID_HOUR, VALID_MIN) valid_time_func_mock.assert_called_with(VALID_HOUR, VALID_MIN)
def test_constructor_excepts_on_invalid_time(self): with self.assertRaises(InvalidTime): TimeOfDay(INVALID_HOUR, INVALID_MIN)