def test_date(self): self.assertIsInstance(typ.date_get(None), datetime.date) self.assertIsInstance(typ.date_get(""), datetime.date) re = "^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])$" self.assertRegexpMatches(typ.date_get(None).strftime(typ.FORMAT_DATE), re) self.assertRegexpMatches(typ.date_get("").strftime(typ.FORMAT_DATE), re) date = datetime.date(2011, 12, 1) date_string = '2011-12-01' self.assertEqual(date, typ.date_get(date_string)) self.assertEqual(date, typ.date_get(date)) with self.assertRaises(TypeError): _ = typ.date_get([]) with self.assertRaises(TypeError): _ = typ.date_get({}) with self.assertRaises(TypeError): _ = typ.date_get(False) # Test fail on datetime.datetime with self.assertRaises(ValueError): _ = typ.date_get(datetime.datetime.now()) # Test fail on datetime.time with self.assertRaises(TypeError): _ = typ.date_get(datetime.datetime.now().time()) # Test fail on invalid string format with self.assertRaises(ValueError): _ = typ.date_get("11.11.1111")
def test_date(self): date = datetime.date(2011, 12, 1) date_string = '2011-12-01' self.assertEqual(date, typ.date_get(date_string)) self.assertEqual(typ.date_set(date), date_string)
def test_date(self): self.assertIsInstance(typ.date_get(None), datetime.date) self.assertIsInstance(typ.date_get(""), datetime.date) re = "^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])$" self.assertRegexpMatches( typ.date_get(None).strftime(typ.FORMAT_DATE), re) self.assertRegexpMatches( typ.date_get("").strftime(typ.FORMAT_DATE), re) date = datetime.date(2011, 12, 1) date_string = '2011-12-01' self.assertEqual(date, typ.date_get(date_string)) self.assertEqual(date, typ.date_get(date)) with self.assertRaises(TypeError): _ = typ.date_get([]) with self.assertRaises(TypeError): _ = typ.date_get({}) with self.assertRaises(TypeError): _ = typ.date_get(False) # Test fail on datetime.datetime with self.assertRaises(ValueError): _ = typ.date_get(datetime.datetime.now()) # Test fail on datetime.time with self.assertRaises(TypeError): _ = typ.date_get(datetime.datetime.now().time()) # Test fail on invalid string format with self.assertRaises(ValueError): _ = typ.date_get("11.11.1111")