8
8
import io
9
9
import os
10
10
import pickle
11
+ import re
11
12
import sys
12
13
import weakref
13
14
from unittest import mock
@@ -530,7 +531,11 @@ def test_uuid1(self):
530
531
@support .requires_mac_ver (10 , 5 )
531
532
@unittest .skipUnless (os .name == 'posix' , 'POSIX-only test' )
532
533
def test_uuid1_safe (self ):
533
- if not self .uuid ._has_uuid_generate_time_safe :
534
+ msg = re .escape ("'_has_uuid_generate_time_safe' is deprecated and "
535
+ "slated for removal in Python 3.15" )
536
+ with self .assertWarnsRegex (DeprecationWarning , msg ):
537
+ has_uuid_generate_time_safe = self .uuid ._has_uuid_generate_time_safe
538
+ if not has_uuid_generate_time_safe :
534
539
self .skipTest ('requires uuid_generate_time_safe(3)' )
535
540
536
541
u = self .uuid .uuid1 ()
@@ -546,7 +551,6 @@ def mock_generate_time_safe(self, safe_value):
546
551
"""
547
552
if os .name != 'posix' :
548
553
self .skipTest ('POSIX-only test' )
549
- self .uuid ._load_system_functions ()
550
554
f = self .uuid ._generate_time_safe
551
555
if f is None :
552
556
self .skipTest ('need uuid._generate_time_safe' )
@@ -581,7 +585,17 @@ def test_uuid1_bogus_return_value(self):
581
585
self .assertEqual (u .is_safe , self .uuid .SafeUUID .unknown )
582
586
583
587
def test_uuid1_time (self ):
584
- with mock .patch .object (self .uuid , '_has_uuid_generate_time_safe' , False ), \
588
+ @contextlib .contextmanager
589
+ def patch_has_uuid_generate_time_safe (value ):
590
+ msg = re .escape ("'_has_uuid_generate_time_safe' is deprecated and "
591
+ "slated for removal in Python 3.15" )
592
+ with self .assertWarnsRegex (DeprecationWarning , msg ):
593
+ with mock .patch .object (
594
+ self .uuid , '_has_uuid_generate_time_safe' , value ,
595
+ ) as patched :
596
+ yield patched
597
+
598
+ with patch_has_uuid_generate_time_safe (False ), \
585
599
mock .patch .object (self .uuid , '_generate_time_safe' , None ), \
586
600
mock .patch .object (self .uuid , '_last_timestamp' , None ), \
587
601
mock .patch .object (self .uuid , 'getnode' , return_value = 93328246233727 ), \
@@ -590,7 +604,7 @@ def test_uuid1_time(self):
590
604
u = self .uuid .uuid1 ()
591
605
self .assertEqual (u , self .uuid .UUID ('a7a55b92-01fc-11e9-94c5-54e1acf6da7f' ))
592
606
593
- with mock . patch . object ( self . uuid , '_has_uuid_generate_time_safe' , False ), \
607
+ with patch_has_uuid_generate_time_safe ( False ), \
594
608
mock .patch .object (self .uuid , '_generate_time_safe' , None ), \
595
609
mock .patch .object (self .uuid , '_last_timestamp' , None ), \
596
610
mock .patch ('time.time_ns' , return_value = 1545052026752910643 ):
0 commit comments