◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
123 changes: 114 additions & 9 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import builtins
import contextlib
import copy
import io
import os
import pickle
Expand All @@ -18,7 +19,7 @@ def importable(name):
try:
__import__(name)
return True
except:
return False


Expand All @@ -31,6 +32,15 @@ def get_command_stdout(command, args):
class BaseTestUUID:
uuid = None

def test_UUID(self):
equal = self.assertEqual
ascending = []
Expand Down Expand Up @@ -522,7 +532,14 @@ def test_uuid1(self):
@support.requires_mac_ver(10, 5)
@unittest.skipUnless(os.name == 'posix', 'POSIX-only test')
def test_uuid1_safe(self):
if not self.uuid._has_uuid_generate_time_safe:
self.skipTest('requires uuid_generate_time_safe(3)')

u = self.uuid.uuid1()
Expand All @@ -538,7 +555,6 @@ def mock_generate_time_safe(self, safe_value):
"""
if os.name != 'posix':
self.skipTest('POSIX-only test')
self.uuid._load_system_functions()
f = self.uuid._generate_time_safe
if f is None:
self.skipTest('need uuid._generate_time_safe')
Expand Down Expand Up @@ -573,17 +589,15 @@ def test_uuid1_bogus_return_value(self):
self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown)

def test_uuid1_time(self):
with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \
mock.patch.object(self.uuid, '_generate_time_safe', None), \
mock.patch.object(self.uuid, '_last_timestamp', None), \
mock.patch.object(self.uuid, 'getnode', return_value=93328246233727), \
mock.patch('time.time_ns', return_value=1545052026752910643), \
mock.patch('random.getrandbits', return_value=5317): # guaranteed to be random
u = self.uuid.uuid1()
self.assertEqual(u, self.uuid.UUID('a7a55b92-01fc-11e9-94c5-54e1acf6da7f'))

with mock.patch.object(self.uuid, '_has_uuid_generate_time_safe', False), \
mock.patch.object(self.uuid, '_generate_time_safe', None), \
mock.patch.object(self.uuid, '_last_timestamp', None), \
mock.patch('time.time_ns', return_value=1545052026752910643):
u = self.uuid.uuid1(node=93328246233727, clock_seq=5317)
Expand All @@ -592,7 +606,22 @@ def test_uuid1_time(self):
def test_uuid3(self):
equal = self.assertEqual

# Test some known version-3 UUIDs.
for u, v in [(self.uuid.uuid3(self.uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(self.uuid.uuid3(self.uuid.NAMESPACE_URL, 'http://python.org/'),
Expand Down Expand Up @@ -624,7 +653,22 @@ def test_uuid4(self):
def test_uuid5(self):
equal = self.assertEqual

# Test some known version-5 UUIDs.
for u, v in [(self.uuid.uuid5(self.uuid.NAMESPACE_DNS, 'python.org'),
'886313e1-3b8a-5372-9b90-0c9aee199e5d'),
(self.uuid.uuid5(self.uuid.NAMESPACE_URL, 'http://python.org/'),
Expand Down Expand Up @@ -667,6 +711,67 @@ def test_uuid_weakref(self):
weak = weakref.ref(strong)
self.assertIs(strong, weak())

class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
uuid = py_uuid

Expand Down
Loading
Loading
Toggle all file notes Toggle all file annotations