Skip to content

Commit afbb5d1

Browse files
authored
require uuid_generate_time_safe for all tests of it (#390)
The way mocking is written in these tests, we need to have the underlying function around.
1 parent f522792 commit afbb5d1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Lib/test/test_uuid.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,18 @@ def test_uuid1(self):
340340
equal(((u.clock_seq_hi_variant & 0x3f) << 8) |
341341
u.clock_seq_low, 0x3fff)
342342

343-
@unittest.skipUnless(uuid._uuid_generate_time is not None,
344-
'requires uuid_generate_time_safe(3)')
345-
@unittest.skipUnless(importable('ctypes'), 'requires ctypes')
343+
requires_ugt = unittest.skipUnless(uuid._uuid_generate_time is not None,
344+
'requires uuid_generate_time_safe(3)')
345+
346+
@requires_ugt
346347
def test_uuid1_safe(self):
347348
u = uuid.uuid1()
348349
# uuid_generate_time_safe() may return 0 or -1 but what it returns is
349350
# dependent on the underlying platform support. At least it cannot be
350351
# unknown (unless I suppose the platform is buggy).
351352
self.assertNotEqual(u.is_safe, uuid.SafeUUID.unknown)
352353

353-
@unittest.skipUnless(importable('ctypes'), 'requires ctypes')
354+
@requires_ugt
354355
def test_uuid1_unknown(self):
355356
# Even if the platform has uuid_generate_time_safe(), let's mock it to
356357
# be uuid_generate_time() and ensure the safety is unknown.
@@ -359,21 +360,21 @@ def test_uuid1_unknown(self):
359360
u = uuid.uuid1()
360361
self.assertEqual(u.is_safe, uuid.SafeUUID.unknown)
361362

362-
@unittest.skipUnless(importable('ctypes'), 'requires ctypes')
363+
@requires_ugt
363364
def test_uuid1_is_safe(self):
364365
with unittest.mock.patch.object(uuid._uuid_generate_time,
365366
'restype', lambda x: 0):
366367
u = uuid.uuid1()
367368
self.assertEqual(u.is_safe, uuid.SafeUUID.safe)
368369

369-
@unittest.skipUnless(importable('ctypes'), 'requires ctypes')
370+
@requires_ugt
370371
def test_uuid1_is_unsafe(self):
371372
with unittest.mock.patch.object(uuid._uuid_generate_time,
372373
'restype', lambda x: -1):
373374
u = uuid.uuid1()
374375
self.assertEqual(u.is_safe, uuid.SafeUUID.unsafe)
375376

376-
@unittest.skipUnless(importable('ctypes'), 'requires ctypes')
377+
@requires_ugt
377378
def test_uuid1_bogus_return_value(self):
378379
with unittest.mock.patch.object(uuid._uuid_generate_time,
379380
'restype', lambda x: 3):

0 commit comments

Comments
 (0)