summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Belopolsky <abalkin@users.noreply.github.com>2018-06-08 22:58:38 (GMT)
committerGitHub <noreply@github.com>2018-06-08 22:58:38 (GMT)
commit4c3e39f61c6a759aa1370497ea3597f3564f9da0 (patch)
tree1be951cb240307841062bcaba9c065092b7e516a
parent12f482e0ae33021c04264294f33fa6baa9617cec (diff)
downloadcpython-4c3e39f61c6a759aa1370497ea3597f3564f9da0.zip
cpython-4c3e39f61c6a759aa1370497ea3597f3564f9da0.tar.gz
cpython-4c3e39f61c6a759aa1370497ea3597f3564f9da0.tar.bz2
Datetime test coverage (#7544)
* Added a test case for strftime("%z"). The added test checks a case with UTC offest expressed in an integer number of seconds. * Added a test comparing naive and aware datetimes. Check that a greater than comparison of a naive datetime instance with an aware one raises a TypeError. * Test datetime in fold or in gap comparison both ways.
-rw-r--r--Lib/test/datetimetester.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 436cbea..a7e5e0b 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -2345,9 +2345,10 @@ class TestDateTime(TestDate):
t = self.theclass(2004, 12, 31, 6, 22, 33, 47)
self.assertEqual(t.strftime("%m %d %y %f %S %M %H %j"),
"12 31 04 000047 33 22 06 366")
- tz = timezone(-timedelta(hours=2, seconds=33, microseconds=123))
- t = t.replace(tzinfo=tz)
- self.assertEqual(t.strftime("%z"), "-020033.000123")
+ for (s, us), z in [((33, 123), "33.000123"), ((33, 0), "33"),]:
+ tz = timezone(-timedelta(hours=2, seconds=s, microseconds=us))
+ t = t.replace(tzinfo=tz)
+ self.assertEqual(t.strftime("%z"), "-0200" + z)
def test_extract(self):
dt = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
@@ -3647,6 +3648,9 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
t2 = self.theclass.min
self.assertNotEqual(t1, t2)
self.assertEqual(t2, t2)
+ # and > comparison should fail
+ with self.assertRaises(TypeError):
+ t1 > t2
# It's also naive if it has tzinfo but tzinfo.utcoffset() is None.
class Naive(tzinfo):
@@ -5073,11 +5077,13 @@ class TestLocalTimeDisambiguation(unittest.TestCase):
t_fold = datetime(2002, 10, 27, 1, 45, tzinfo=Eastern2)
t_fold_utc = t_fold.astimezone(timezone.utc)
self.assertNotEqual(t_fold, t_fold_utc)
+ self.assertNotEqual(t_fold_utc, t_fold)
def test_mixed_compare_gap(self):
t_gap = datetime(2002, 4, 7, 2, 45, tzinfo=Eastern2)
t_gap_utc = t_gap.astimezone(timezone.utc)
self.assertNotEqual(t_gap, t_gap_utc)
+ self.assertNotEqual(t_gap_utc, t_gap)
def test_hash_aware(self):
t = datetime(2000, 1, 1, tzinfo=Eastern2)