]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: fix test_datetime_to_str_2 on non-UTC hosts
authorSage Weil <sage@newdream.net>
Wed, 27 Jan 2021 21:44:21 +0000 (15:44 -0600)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 29 Jan 2021 12:42:38 +0000 (13:42 +0100)
The old test parsed to a datetime without a tz, which was interpreted as
the local time zone when rendering back to a string.  Specify that it's a
UTC datetime so that behavior is consistent regardless of the test host
timezone.

Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit 78aca4db249c409d0cd5a24bfae81e55cf930bc3)

src/python-common/ceph/tests/test_datetime.py

index a5c6ec001517b152ae9aaf5b3d387cb3ce1406b5..d03a829301f542330013bff430ab5395aa59f77c 100644 (file)
@@ -11,8 +11,11 @@ def test_datetime_to_str_1():
 
 
 def test_datetime_to_str_2():
-    dt = datetime.datetime.strptime('2019-04-24T17:06:53.039991',
-                                    '%Y-%m-%dT%H:%M:%S.%f')
+    # note: tz isn't specified in the string, so explicitly store this as UTC
+    dt = datetime.datetime.strptime(
+        '2019-04-24T17:06:53.039991',
+        '%Y-%m-%dT%H:%M:%S.%f'
+    ).replace(tzinfo=datetime.timezone.utc)
     assert datetime_to_str(dt) == '2019-04-24T17:06:53.039991Z'