def test_time(self): self.assertIsInstance(typ.time_get(None), datetime.time) self.assertIsInstance(typ.time_get(""), datetime.time) re = "^[0-5][0-9]:[0-5][0-9]:[0-5][0-9]$" self.assertRegexpMatches(typ.time_get(None).strftime(typ.FORMAT_TIME), re) self.assertRegexpMatches(typ.time_get("").strftime(typ.FORMAT_TIME), re) time = datetime.time(12, 34, 56) time_string = '12:34:56' self.assertEqual(time, typ.time_get(time_string)) self.assertEqual(time, typ.time_get(time)) with self.assertRaises(TypeError): _ = typ.time_get([]) with self.assertRaises(TypeError): _ = typ.time_get({}) with self.assertRaises(TypeError): _ = typ.time_get(False) # Test fail on datetime.datetime with self.assertRaises(TypeError): _ = typ.time_get(datetime.datetime.now()) # Test fail on datetime.date with self.assertRaises(TypeError): _ = typ.time_get(datetime.datetime.now().date()) # Test fail on invalid string format with self.assertRaises(ValueError): _ = typ.time_get("11-11-11")
def test_time(self): time = datetime.time(12, 34, 56) time_string = '12:34:56' self.assertEqual(time, typ.time_get(time_string)) self.assertEqual(typ.time_set(time), time_string)
def test_time(self): self.assertIsInstance(typ.time_get(None), datetime.time) self.assertIsInstance(typ.time_get(""), datetime.time) re = "^[0-5][0-9]:[0-5][0-9]:[0-5][0-9]$" self.assertRegexpMatches( typ.time_get(None).strftime(typ.FORMAT_TIME), re) self.assertRegexpMatches( typ.time_get("").strftime(typ.FORMAT_TIME), re) time = datetime.time(12, 34, 56) time_string = '12:34:56' self.assertEqual(time, typ.time_get(time_string)) self.assertEqual(time, typ.time_get(time)) with self.assertRaises(TypeError): _ = typ.time_get([]) with self.assertRaises(TypeError): _ = typ.time_get({}) with self.assertRaises(TypeError): _ = typ.time_get(False) # Test fail on datetime.datetime with self.assertRaises(TypeError): _ = typ.time_get(datetime.datetime.now()) # Test fail on datetime.date with self.assertRaises(TypeError): _ = typ.time_get(datetime.datetime.now().date()) # Test fail on invalid string format with self.assertRaises(ValueError): _ = typ.time_get("11-11-11")