Explorar el Código

archive: Add testcases for microsecond handling.

datetime.isoformat() has different output depending on whether
microseconds are zero or not. Add test cases to ensure we handle both
cases correctly in an archive.
Cam Hutchison hace 10 años
padre
commit
0295ef8563
Se han modificado 1 ficheros con 25 adiciones y 1 borrados
  1. 25 1
      attic/testsuite/archive.py

+ 25 - 1
attic/testsuite/archive.py

@@ -1,7 +1,10 @@
 import msgpack
 from attic.testsuite import AtticTestCase
-from attic.archive import CacheChunkBuffer, RobustUnpacker
+from attic.testsuite.mock import Mock
+from attic.archive import Archive, CacheChunkBuffer, RobustUnpacker
 from attic.key import PlaintextKey
+from attic.helpers import Manifest
+from datetime import datetime, timezone
 
 
 class MockCache:
@@ -14,6 +17,27 @@ class MockCache:
         return id, len(data), len(data)
 
 
+class ArchiveTimestampTestCase(AtticTestCase):
+
+    def _test_timestamp_parsing(self, isoformat, expected):
+        repository = Mock()
+        key = PlaintextKey()
+        manifest = Manifest(repository, key)
+        a = Archive(repository, key, manifest, 'test', create=True)
+        a.metadata = {b'time': isoformat}
+        self.assert_equal(a.ts, expected)
+
+    def test_with_microseconds(self):
+        self._test_timestamp_parsing(
+            '1970-01-01T00:00:01.000001',
+            datetime(1970, 1, 1, 0, 0, 1, 1, timezone.utc))
+
+    def test_without_microseconds(self):
+        self._test_timestamp_parsing(
+            '1970-01-01T00:00:01',
+            datetime(1970, 1, 1, 0, 0, 1, 0, timezone.utc))
+
+
 class ChunkBufferTestCase(AtticTestCase):
 
     def test(self):