|
9 | 9 | import shutil |
10 | 10 | import subprocess |
11 | 11 | import sys |
| 12 | +from unittest import mock |
12 | 13 |
|
13 | 14 | py_uuid = support.import_fresh_module('uuid', blocked=['_uuid']) |
14 | 15 | c_uuid = support.import_fresh_module('uuid', fresh=['_uuid']) |
@@ -567,6 +568,23 @@ def test_uuid1_bogus_return_value(self): |
567 | 568 | u = self.uuid.uuid1() |
568 | 569 | self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown) |
569 | 570 |
|
| 571 | + def test_uuid1_time(self): |
| 572 | + with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \ |
| 573 | + mock.patch.object(self.uuid, '_generate_time_safe', None), \ |
| 574 | + mock.patch.object(self.uuid, '_last_timestamp', None), \ |
| 575 | + mock.patch.object(self.uuid, 'getnode', return_value=93328246233727), \ |
| 576 | + mock.patch('time.time_ns', return_value=1545052026752910643), \ |
| 577 | + mock.patch('random.getrandbits', return_value=5317): # guaranteed to be random |
| 578 | + u = self.uuid.uuid1() |
| 579 | + self.assertEqual(u, self.uuid.UUID('a7a55b92-01fc-11e9-94c5-54e1acf6da7f')) |
| 580 | + |
| 581 | + with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \ |
| 582 | + mock.patch.object(self.uuid, '_generate_time_safe', None), \ |
| 583 | + mock.patch.object(self.uuid, '_last_timestamp', None), \ |
| 584 | + mock.patch('time.time_ns', return_value=1545052026752910643): |
| 585 | + u = self.uuid.uuid1(node=93328246233727, clock_seq=5317) |
| 586 | + self.assertEqual(u, self.uuid.UUID('a7a55b92-01fc-11e9-94c5-54e1acf6da7f')) |
| 587 | + |
570 | 588 | def test_uuid3(self): |
571 | 589 | equal = self.assertEqual |
572 | 590 |
|
|
0 commit comments