|
1 | 1 | import unittest |
2 | 2 | from test import support |
3 | 3 | from test.support import import_helper |
| 4 | +from test.support.script_helper import assert_python_ok |
4 | 5 | import builtins |
5 | 6 | import contextlib |
6 | 7 | import copy |
@@ -773,10 +774,37 @@ def test_cli_uuid5_ouputted_with_valid_namespace_and_name(self): |
773 | 774 | class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): |
774 | 775 | uuid = py_uuid |
775 | 776 |
|
| 777 | + |
776 | 778 | @unittest.skipUnless(c_uuid, 'requires the C _uuid module') |
777 | 779 | class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase): |
778 | 780 | uuid = c_uuid |
779 | 781 |
|
| 782 | + def check_has_stable_libuuid_extractable_node(self): |
| 783 | + if not self.uuid._has_stable_extractable_node: |
| 784 | + self.skipTest("libuuid cannot deduce MAC address") |
| 785 | + |
| 786 | + @unittest.skipUnless(os.name == 'posix', 'POSIX only') |
| 787 | + def test_unix_getnode_from_libuuid(self): |
| 788 | + self.check_has_stable_libuuid_extractable_node() |
| 789 | + script = 'import uuid; print(uuid._unix_getnode())' |
| 790 | + _, n_a, _ = assert_python_ok('-c', script) |
| 791 | + _, n_b, _ = assert_python_ok('-c', script) |
| 792 | + n_a, n_b = n_a.decode().strip(), n_b.decode().strip() |
| 793 | + self.assertTrue(n_a.isdigit()) |
| 794 | + self.assertTrue(n_b.isdigit()) |
| 795 | + self.assertEqual(n_a, n_b) |
| 796 | + |
| 797 | + @unittest.skipUnless(os.name == 'nt', 'Windows only') |
| 798 | + def test_windows_getnode_from_libuuid(self): |
| 799 | + self.check_has_stable_libuuid_extractable_node() |
| 800 | + script = 'import uuid; print(uuid._windll_getnode())' |
| 801 | + _, n_a, _ = assert_python_ok('-c', script) |
| 802 | + _, n_b, _ = assert_python_ok('-c', script) |
| 803 | + n_a, n_b = n_a.decode().strip(), n_b.decode().strip() |
| 804 | + self.assertTrue(n_a.isdigit()) |
| 805 | + self.assertTrue(n_b.isdigit()) |
| 806 | + self.assertEqual(n_a, n_b) |
| 807 | + |
780 | 808 |
|
781 | 809 | class BaseTestInternals: |
782 | 810 | _uuid = py_uuid |
|
0 commit comments