|
1 | 1 | import unittest |
| 2 | +from datetime import datetime |
2 | 3 | from time import time_ns |
3 | 4 | from unittest.mock import patch |
4 | 5 | from uuid import uuid1 |
5 | 6 |
|
6 | 7 | from uuid6 import DraftUUID, uuid6, uuid7 |
7 | 8 |
|
8 | | -YEAR_IN_NS = 3600 * 24 * 36525 * 10 ** 7 |
| 9 | +YEAR_IN_NS = 3600 * 24 * 36525 * 10**7 |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class DraftUUIDTests(unittest.TestCase): |
@@ -100,10 +101,24 @@ def test_uuid7_far_in_future(self): |
100 | 101 | def test_time(self): |
101 | 102 | uuid_1 = uuid1() |
102 | 103 | uuid_6 = uuid6() |
103 | | - self.assertAlmostEqual(uuid_6.time / 10 ** 7, uuid_1.time / 10 ** 7, 3) |
| 104 | + self.assertAlmostEqual(uuid_6.time / 10**7, uuid_1.time / 10**7, 3) |
104 | 105 | cur_time = time_ns() |
105 | 106 | uuid_7 = uuid7() |
106 | | - self.assertAlmostEqual(uuid_7.time / 10 ** 9, cur_time / 10 ** 9, 3) |
| 107 | + self.assertAlmostEqual(uuid_7.time / 10**9, cur_time / 10**9, 3) |
| 108 | + |
| 109 | + def test_time_zero(self): |
| 110 | + uuid_6 = DraftUUID(hex="00000000-0000-6000-8000-000000000000") |
| 111 | + self.assertEqual(uuid_6.time, 0) |
| 112 | + uuid_7 = DraftUUID(hex="00000000-0000-7000-8000-000000000000") |
| 113 | + self.assertEqual(uuid_7.time, 0) |
| 114 | + |
| 115 | + def test_time_max(self): |
| 116 | + uuid_6 = DraftUUID(hex="ffffffff-ffff-6fff-bfff-ffffffffffff") |
| 117 | + self.assertEqual(uuid_6.time, 1152921504606846975) |
| 118 | + uuid_7 = DraftUUID(hex="ffffffff-ffff-7fff-bfff-ffffffffffff") |
| 119 | + self.assertEqual(uuid_7.time, 68719476736000000000) |
| 120 | + dt = datetime.utcfromtimestamp(uuid_7.time / 10**9) |
| 121 | + self.assertEqual(dt, datetime(4147, 8, 20, 7, 32, 16)) |
107 | 122 |
|
108 | 123 | def test_uuid7_from_hex(self): |
109 | 124 | uuid_7 = DraftUUID(hex="061d0edc-bea0-75cc-9892-f6295fd7d295") |
|
0 commit comments