|
3 | 3 | from unittest.mock import patch |
4 | 4 | from uuid import uuid1 |
5 | 5 |
|
6 | | -from uuid6 import UUID, uuid6, uuid7, uuid8 |
| 6 | +from uuid6 import UUID, uuid6, uuid7, uuid8, uuid1_to_uuid6 |
7 | 7 |
|
8 | 8 | REGEX_UUID6 = r"^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" |
9 | 9 | REGEX_UUID7 = r"^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" |
@@ -39,6 +39,19 @@ def test_uuid8_generation(self): |
39 | 39 | self.assertLess(uuid8_1, uuid8_2) |
40 | 40 | uuid8_1 = uuid8_2 |
41 | 41 |
|
| 42 | + def test_uuid1_to_uuid6_generation(self): |
| 43 | + uuid6_1 = None |
| 44 | + for _ in range(1000): |
| 45 | + uuid_1 = uuid1() |
| 46 | + uuid6_2 = uuid1_to_uuid6(uuid_1) |
| 47 | + self.assertEqual(uuid6_2.version, 6) |
| 48 | + self.assertEqual(uuid6_2.node, uuid_1.node) |
| 49 | + self.assertEqual(uuid6_2.clock_seq, uuid_1.clock_seq) |
| 50 | + self.assertEqual(uuid6_2.time, uuid_1.time) |
| 51 | + if uuid6_1 is not None: |
| 52 | + self.assertLess(uuid6_1, uuid6_2) |
| 53 | + uuid6_1 = uuid6_2 |
| 54 | + |
42 | 55 | def test_invalid_int(self): |
43 | 56 | with self.assertRaises(ValueError): |
44 | 57 | _ = UUID(int=-1) |
@@ -155,6 +168,10 @@ def test_multiple_arguments(self): |
155 | 168 | with self.assertRaises(TypeError): |
156 | 169 | _ = UUID(int=0, hex="061d0edc-bea0-75cc-9892-f6295fd7d295") |
157 | 170 |
|
| 171 | + def test_convert_invalid_version(self): |
| 172 | + with self.assertRaises(ValueError): |
| 173 | + _ = uuid1_to_uuid6(uuid7()) |
| 174 | + |
158 | 175 |
|
159 | 176 | if __name__ == "__main__": |
160 | 177 | unittest.main() |
0 commit comments