-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
bpo-11063, bpo-20519: avoid ctypes and improve import time for uuid #3796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
32b1b40
05dcee2
f4d7cf3
8f4dfb2
a78dc43
34df739
92b8670
88bb338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import unittest.mock | ||
| from test import support | ||
| import builtins | ||
| import contextlib | ||
| import io | ||
| import os | ||
| import shutil | ||
|
|
@@ -17,7 +18,9 @@ def importable(name): | |
| except: | ||
| return False | ||
|
|
||
|
|
||
| class BaseTestUUID: | ||
| uuid = None | ||
|
|
||
| def test_UUID(self): | ||
| equal = self.assertEqual | ||
|
|
@@ -360,37 +363,44 @@ def test_uuid1_safe(self): | |
| # unknown (unless I suppose the platform is buggy). | ||
| self.assertNotEqual(u.is_safe, self.uuid.SafeUUID.unknown) | ||
|
|
||
| @contextlib.contextmanager | ||
| def mock_generate_time_safe(self, safe_value): | ||
| """ | ||
| Mock uuid._generate_time_safe() to return a given *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') | ||
| with unittest.mock.patch.object(self.uuid, '_generate_time_safe', | ||
| lambda: (f()[0], safe_value)): | ||
| yield | ||
|
|
||
| @unittest.skipUnless(os.name == 'posix', 'POSIX-only test') | ||
| 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. | ||
| f = self.uuid._generate_time_safe | ||
| with unittest.mock.patch.object(self.uuid, '_generate_time_safe', | ||
| lambda: (f()[0], None)): | ||
| with self.mock_generate_time_safe(None): | ||
| u = self.uuid.uuid1() | ||
| self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown) | ||
|
|
||
| @unittest.skipUnless(os.name == 'posix', 'POSIX-only test') | ||
| def test_uuid1_is_safe(self): | ||
| f = self.uuid._generate_time_safe | ||
| with unittest.mock.patch.object(self.uuid, '_generate_time_safe', | ||
| lambda: (f()[0], 0)): | ||
| with self.mock_generate_time_safe(0): | ||
| u = self.uuid.uuid1() | ||
| self.assertEqual(u.is_safe, self.uuid.SafeUUID.safe) | ||
|
|
||
| @unittest.skipUnless(os.name == 'posix', 'POSIX-only test') | ||
| def test_uuid1_is_unsafe(self): | ||
| f = self.uuid._generate_time_safe | ||
| with unittest.mock.patch.object(self.uuid, '_generate_time_safe', | ||
| lambda: (f()[0], -1)): | ||
| with self.mock_generate_time_safe(-1): | ||
| u = self.uuid.uuid1() | ||
| self.assertEqual(u.is_safe, self.uuid.SafeUUID.unsafe) | ||
|
|
||
| @unittest.skipUnless(os.name == 'posix', 'POSIX-only test') | ||
| def test_uuid1_bogus_return_value(self): | ||
| f = self.uuid._generate_time_safe | ||
| with unittest.mock.patch.object(self.uuid, '_generate_time_safe', | ||
| lambda: (f()[0], 3)): | ||
| with self.mock_generate_time_safe(3): | ||
| u = self.uuid.uuid1() | ||
| self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown) | ||
|
|
||
|
|
@@ -476,6 +486,7 @@ class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase): | |
|
|
||
|
|
||
| class BaseTestInternals: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add "uuid = None" here. |
||
| uuid = None | ||
|
|
||
| @unittest.skipUnless(os.name == 'posix', 'requires Posix') | ||
| def test_find_mac(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1669,16 +1669,16 @@ class db_found(Exception): pass | |
| missing.append('_tkinter') | ||
|
|
||
| # Build the _uuid module if possible | ||
| build_uuid = False | ||
| if find_file("uuid.h", inc_dirs, ["/usr/include/uuid"]): | ||
| uuid_incs = find_file("uuid.h", inc_dirs, ["/usr/include/uuid"]) | ||
| if uuid_incs: | ||
| if self.compiler.find_library_file(lib_dirs, 'uuid'): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may also store the result of find_library_file() into uuid_libdirs to pass it to Extension library_dirs. I'm not sure about this one.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me try...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it shouldn't be necessary. Other uses of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, fine. |
||
| uuid_libs = ['uuid'] | ||
| else: | ||
| uuid_libs = [] | ||
| build_uuid = True | ||
| if build_uuid: | ||
| if uuid_incs: | ||
| self.extensions.append(Extension('_uuid', ['_uuidmodule.c'], | ||
| libraries=uuid_libs)) | ||
| libraries=uuid_libs, | ||
| include_dirs=uuid_incs)) | ||
| else: | ||
| missing.append('_uuid') | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add "uuid = None" here.