aboutsummaryrefslogtreecommitdiff
path: root/tests/test_types.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-10-02 09:07:49 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-10-02 09:07:49 +0200
commitb75c00bf5a7f650ff53a407b47a96407ac277d8e (patch)
tree9a6d77b2bad5f61d883469d0cebeb1dcb4eb30c0 /tests/test_types.py
parente0f8012431f6e5359f4f03b3d3a36403adff85bf (diff)
Add date and datetime types, enforce timestamps to be unix timestamps
Diffstat (limited to 'tests/test_types.py')
-rw-r--r--tests/test_types.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_types.py b/tests/test_types.py
index cc2ff3b..2d6b744 100644
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -119,6 +119,63 @@ class testTypes(unittest.TestCase):
v = checker.load(now)
self.assertEqual(v, now)
+ v = checker.load("1600000000")
+ self.assertEqual(v, datetime.datetime(2020, 9, 13, 14, 26, 40))
+
+ today = datetime.date.today()
+ for d in (
+ today,
+ "today",
+ "2020-13-01", "2020-01-01",
+ "2020-01-01 10:00"
+ ):
+ with self.assertRaises(types.LesanaValueError):
+ checker.load(d)
+
+ v = checker.load(None)
+ self.assertEqual(v, None)
+
+ def test_datetime(self):
+ checker = types.LesanaDatetime()
+
+ v = checker.empty()
+ self.assertEqual(v, None)
+
+ now = datetime.datetime.now()
+ v = checker.load(now)
+ self.assertEqual(v, now)
+
+ today = datetime.date.today()
+ v = checker.load(today)
+ self.assertIsInstance(v, datetime.datetime)
+ for part in ('year', 'month', 'day'):
+ self.assertEqual(getattr(v, part), getattr(today, part))
+
+ v = checker.load("2020-01-01")
+ self.assertEqual(v, datetime.datetime(2020, 1, 1))
+
+ v = checker.load("2020-01-01 10:00")
+ self.assertEqual(v, datetime.datetime(2020, 1, 1, 10, 0))
+
+ for d in ("today", "2020-13-01"):
+ with self.assertRaises(types.LesanaValueError):
+ checker.load(d)
+
+ v = checker.load(None)
+ self.assertEqual(v, None)
+
+ def test_date(self):
+ checker = types.LesanaDate()
+
+ v = checker.empty()
+ self.assertEqual(v, None)
+
+ now = datetime.datetime.now()
+ v = checker.load(now)
+ self.assertIsInstance(v, datetime.date)
+ for part in ('year', 'month', 'day'):
+ self.assertEqual(getattr(v, part), getattr(now, part))
+
today = datetime.date.today()
v = checker.load(today)
self.assertEqual(v, today)