diff options
author | Barry Warsaw <barry@python.org> | 2017-02-18 20:45:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-18 20:45:49 (GMT) |
commit | 8c130d7f8114158f5b94749032ec0c17dba96f83 (patch) | |
tree | 363730734516493dca96560ecb71648455d388de /Lib/test/test_uuid.py | |
parent | ace5c0fdd9b962e6e886c29dbcea72c53f051dc4 (diff) | |
download | cpython-8c130d7f8114158f5b94749032ec0c17dba96f83.zip cpython-8c130d7f8114158f5b94749032ec0c17dba96f83.tar.gz cpython-8c130d7f8114158f5b94749032ec0c17dba96f83.tar.bz2 |
bpo-22807: Expose platform UUID generation safety information. (#138)
bpo-22807: Expose platform UUID generation safety information.
Diffstat (limited to 'Lib/test/test_uuid.py')
-rw-r--r-- | Lib/test/test_uuid.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 47248f9..c912c02 100644 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -340,6 +340,46 @@ class TestUUID(unittest.TestCase): equal(((u.clock_seq_hi_variant & 0x3f) << 8) | u.clock_seq_low, 0x3fff) + @unittest.skipUnless(uuid._uuid_generate_time.restype is not None, + 'requires uuid_generate_time_safe(3)') + @unittest.skipUnless(importable('ctypes'), 'requires ctypes') + def test_uuid1_safe(self): + u = uuid.uuid1() + # uuid_generate_time_safe() may return 0 or -1 but what it returns is + # dependent on the underlying platform support. At least it cannot be + # unknown (unless I suppose the platform is buggy). + self.assertNotEqual(u.is_safe, uuid.SafeUUID.unknown) + + @unittest.skipUnless(importable('ctypes'), 'requires ctypes') + def test_uuid1_unknown(self): + # Even if the platform has uuid_generate_time_safe(), let's mock it to + # be uuid_generate_time() and ensure the safety is unknown. + with unittest.mock.patch.object(uuid._uuid_generate_time, + 'restype', None): + u = uuid.uuid1() + self.assertEqual(u.is_safe, uuid.SafeUUID.unknown) + + @unittest.skipUnless(importable('ctypes'), 'requires ctypes') + def test_uuid1_is_safe(self): + with unittest.mock.patch.object(uuid._uuid_generate_time, + 'restype', lambda x: 0): + u = uuid.uuid1() + self.assertEqual(u.is_safe, uuid.SafeUUID.safe) + + @unittest.skipUnless(importable('ctypes'), 'requires ctypes') + def test_uuid1_is_unsafe(self): + with unittest.mock.patch.object(uuid._uuid_generate_time, + 'restype', lambda x: -1): + u = uuid.uuid1() + self.assertEqual(u.is_safe, uuid.SafeUUID.unsafe) + + @unittest.skipUnless(importable('ctypes'), 'requires ctypes') + def test_uuid1_bogus_return_value(self): + with unittest.mock.patch.object(uuid._uuid_generate_time, + 'restype', lambda x: 3): + u = uuid.uuid1() + self.assertEqual(u.is_safe, uuid.SafeUUID.unknown) + def test_uuid3(self): equal = self.assertEqual |