testtools: Merge in new upstream.
[nivanova/samba-autobuild/.git] / lib / testtools / testtools / testresult / real.py
index d1a10236452f42b25e8e71cdc5c9fc15f5dea766..b521251f462aa923d7dd066a638190603dfd1433 100644 (file)
@@ -14,7 +14,26 @@ import datetime
 import sys
 import unittest
 
-from testtools.compat import _format_exc_info, str_is_unicode, _u
+from testtools.compat import all, _format_exc_info, str_is_unicode, _u
+
+# From http://docs.python.org/library/datetime.html
+_ZERO = datetime.timedelta(0)
+
+# A UTC class.
+
+class UTC(datetime.tzinfo):
+    """UTC"""
+
+    def utcoffset(self, dt):
+        return _ZERO
+
+    def tzname(self, dt):
+        return "UTC"
+
+    def dst(self, dt):
+        return _ZERO
+
+utc = UTC()
 
 
 class TestResult(unittest.TestResult):
@@ -149,7 +168,7 @@ class TestResult(unittest.TestResult):
         time() method.
         """
         if self.__now is None:
-            return datetime.datetime.now()
+            return datetime.datetime.now(utc)
         else:
             return self.__now
 
@@ -238,6 +257,9 @@ class MultiTestResult(TestResult):
     def stopTestRun(self):
         return self._dispatch('stopTestRun')
 
+    def time(self, a_datetime):
+        return self._dispatch('time', a_datetime)
+
     def done(self):
         return self._dispatch('done')