Anonymous avatar Anonymous committed ac01b63

check_node(): stop spraying mystery output to stderr.

When a node number disagrees, keep track of all sources & the
node numbers they reported, and stick all that in the error message.

Changed all callers to supply a non-empty "source" argument; made
the "source" argument non-optional.

On my box, test_uuid still fails, but with the less confusing output:

AssertionError: different sources disagree on node:
from source 'getnode1', node was 00038a000015
from source 'getnode2', node was 00038a000015
from source 'ipconfig', node was 001111b2b7bf

Only the last one appears to be correct; e.g.,

C:\Code\python\PCbuild>getmac

Physical Address Transport Name
=================== ==========================================================
00-11-11-B2-B7-BF \Device\Tcpip_{190FB163-5AFD-4483-86A1-2FE16AC61FF1}
62-A1-AC-6C-FD-BE \Device\Tcpip_{8F77DF5A-EA3D-4F1D-975E-D472CEE6438A}
E2-1F-01-C6-5D-88 \Device\Tcpip_{CD18F76B-2EF3-409F-9B8A-6481EE70A1E4}

I can't find anything on my box with MAC 00-03-8a-00-00-15, and am
not clear on where that comes from.

Comments (0)

Files changed (1)

Lib/test/test_uuid.py

 
 class TestUUID(TestCase):
     last_node = None
+    source2node = {}
 
     def test_UUID(self):
         equal = self.assertEqual
         badtype(lambda: setattr(u, 'fields', f))
         badtype(lambda: setattr(u, 'int', i))
 
-    def check_node(self, node, source=''):
+    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.assertNotEqual(node, 0, message)
         self.assertNotEqual(node, 0xffffffffffffL, message)
         self.assert_(0 <= node, message)
-        self.assert_(node < 1<<48L, message)
+        self.assert_(node < (1L << 48), message)
 
-        import sys
-        if source:
-            sys.stderr.write('(%s: %012x)' % (source, node))
+        TestUUID.source2node[source] = node
         if TestUUID.last_node:
-            self.assertEqual(TestUUID.last_node, node, 'inconsistent node IDs')
+            if TestUUID.last_node != node:
+                msg = "different sources disagree on node:\n"
+                for s, n in TestUUID.source2node.iteritems():
+                    msg += "    from source %r, node was %012x\n" % (s, n)
+                self.fail(msg)
         else:
             TestUUID.last_node = node
 
             self.check_node(uuid._windll_getnode(), 'windll')
 
     def test_getnode(self):
-        self.check_node(uuid.getnode())
+        self.check_node(uuid.getnode(), "getnode1")
 
         # Test it again to ensure consistency.
-        self.check_node(uuid.getnode())
+        self.check_node(uuid.getnode(), "getnode2")
 
     def test_uuid1(self):
         equal = self.assertEqual
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.