summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_uuid.py
diff options
context:
space:
mode:
authorStefan Krah <stefan@bytereef.org>2010-04-11 16:36:10 (GMT)
committerStefan Krah <stefan@bytereef.org>2010-04-11 16:36:10 (GMT)
commitbdee329d8014ef53da7c27f3de1cd33c0fdbde14 (patch)
tree0763a4a107fa0f9ab8718aac568c86770d727c67 /Lib/test/test_uuid.py
parentb0765c464804edd7c87db8843704adb7d4a242d5 (diff)
downloadcpython-bdee329d8014ef53da7c27f3de1cd33c0fdbde14.zip
cpython-bdee329d8014ef53da7c27f3de1cd33c0fdbde14.tar.gz
cpython-bdee329d8014ef53da7c27f3de1cd33c0fdbde14.tar.bz2
Merged revisions 79954 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79954 | stefan.krah | 2010-04-11 17:15:54 +0200 (Sun, 11 Apr 2010) | 17 lines Fix for issues #3581, #1481 and #7650: 1. The assumptions in check_node() were too restrictive: - Hardware addresses with universal_local_bit=1 are valid (locally administered). - Many of the tested functions (including uuid.getnode()) may return valid RFC 4122 random node IDs. These are pretty much random 48-bit values with the multicast bit set to 1. 2. _unixdll_getnode() calls _uuid_generate_time(), which may be None on some platforms. The resulting TypeError is now caught. ........
Diffstat (limited to 'Lib/test/test_uuid.py')
-rw-r--r--Lib/test/test_uuid.py37
1 files changed, 10 insertions, 27 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index ab926ae..cc21bae 100644
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -281,15 +281,9 @@ class TestUUID(TestCase):
badtype(lambda: setattr(u, 'node', 0))
def check_node(self, node, source):
- individual_group_bit = (node >> 40L) & 1
- universal_local_bit = (node >> 40L) & 2
- message = "%012x doesn't look like a real MAC address" % node
- self.assertEqual(individual_group_bit, 0, message)
- self.assertEqual(universal_local_bit, 0, message)
- self.assertNotEqual(node, 0, message)
- self.assertNotEqual(node, 0xffffffffffffL, message)
- self.assert_(0 <= node, message)
- self.assert_(node < (1L << 48), message)
+ message = "%012x is not an RFC 4122 node ID" % node
+ self.assertTrue(0 < node, message)
+ self.assertTrue(node < (1L << 48), message)
TestUUID.source2node[source] = node
if TestUUID.last_node:
@@ -307,11 +301,6 @@ class TestUUID(TestCase):
def test_ifconfig_getnode(self):
import sys
- print >>sys.__stdout__, \
-""" WARNING: uuid._ifconfig_getnode is unreliable on many platforms.
- It is disabled until the code and/or test can be fixed properly."""
- return
-
import os
if os.name == 'posix':
node = uuid._ifconfig_getnode()
@@ -331,19 +320,18 @@ class TestUUID(TestCase):
def test_random_getnode(self):
node = uuid._random_getnode()
- self.assert_(0 <= node)
- self.assert_(node < (1L <<48))
+ # Least significant bit of first octet must be set.
+ self.assertTrue(node & 0x010000000000)
+ self.assertTrue(node < (1L << 48))
def test_unixdll_getnode(self):
import sys
- print >>sys.__stdout__, \
-""" WARNING: uuid._unixdll_getnode is unreliable on many platforms.
- It is disabled until the code and/or test can be fixed properly."""
- return
-
import os
if importable('ctypes') and os.name == 'posix':
- self.check_node(uuid._unixdll_getnode(), 'unixdll')
+ try: # Issues 1481, 3581: _uuid_generate_time() might be None.
+ self.check_node(uuid._unixdll_getnode(), 'unixdll')
+ except TypeError:
+ pass
def test_windll_getnode(self):
import os
@@ -352,11 +340,6 @@ class TestUUID(TestCase):
def test_getnode(self):
import sys
- print >>sys.__stdout__, \
-""" WARNING: uuid.getnode is unreliable on many platforms.
- It is disabled until the code and/or test can be fixed properly."""
- return
-
node1 = uuid.getnode()
self.check_node(node1, "getnode1")