subunit/run.py: make iso8601 UTC usage python 2/3 compatible
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 6 Mar 2019 23:34:15 +0000 (12:34 +1300)
committerNoel Power <npower@samba.org>
Thu, 7 Mar 2019 12:01:25 +0000 (12:01 +0000)
In `iso8601/iso8601.py`:

    if sys.version_info >= (3, 2, 0):
        UTC = datetime.timezone.utc
        ...
    else:
        class Utc(datetime.tzinfo):
            ...

        UTC = Utc()

The class `Utc` is only available for python < 3.2.0.
Use `UTC` instance instead, which is python 2/3 compatible.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
python/samba/subunit/run.py

index 8f32d46ef49f76393797b5badf7a7428ab883b17..89ca8a8050be77738ebdb922071ca9ae3b59dfa9 100755 (executable)
@@ -24,7 +24,7 @@
   $ python -m samba.subunit.run mylib.tests.test_suite
 """
 
-from iso8601.iso8601 import Utc
+from iso8601.iso8601 import UTC
 
 import datetime
 import os
@@ -184,7 +184,7 @@ class TestProtocolClient(unittest.TestResult):
 
         ":param datetime: A datetime.datetime object.
         """
-        time = a_datetime.astimezone(Utc())
+        time = a_datetime.astimezone(UTC)
         self._stream.write("time: %04d-%02d-%02d %02d:%02d:%02d.%06dZ\n" % (
             time.year, time.month, time.day, time.hour, time.minute,
             time.second, time.microsecond))
@@ -458,7 +458,7 @@ class AutoTimingTestResultDecorator(HookedTestResultDecorator):
         time = self._time
         if time is not None:
             return
-        time = datetime.datetime.utcnow().replace(tzinfo=Utc())
+        time = datetime.datetime.utcnow().replace(tzinfo=UTC)
         self.decorated.time(time)
 
     @property