Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_uuid.py

    r2 r391  
    1 from unittest import TestCase
     1import unittest
    22from test import test_support
     3import os
    34import uuid
    45
     
    1011        return False
    1112
    12 class TestUUID(TestCase):
     13class TestUUID(unittest.TestCase):
    1314    last_node = None
    1415    source2node = {}
     
    282283
    283284    def check_node(self, node, source):
    284         individual_group_bit = (node >> 40L) & 1
    285         universal_local_bit = (node >> 40L) & 2
    286         message = "%012x doesn't look like a real MAC address" % node
    287         self.assertEqual(individual_group_bit, 0, message)
    288         self.assertEqual(universal_local_bit, 0, message)
    289         self.assertNotEqual(node, 0, message)
    290         self.assertNotEqual(node, 0xffffffffffffL, message)
    291         self.assert_(0 <= node, message)
    292         self.assert_(node < (1L << 48), message)
     285        message = "%012x is not an RFC 4122 node ID" % node
     286        self.assertTrue(0 < node, message)
     287        self.assertTrue(node < (1L << 48), message)
    293288
    294289        TestUUID.source2node[source] = node
     
    306301            TestUUID.last_node = node
    307302
     303    @unittest.skipUnless(os.name == 'posix', 'requires Posix')
    308304    def test_ifconfig_getnode(self):
    309         import sys
    310         print >>sys.__stdout__, \
    311 """    WARNING: uuid._ifconfig_getnode is unreliable on many platforms.
    312         It is disabled until the code and/or test can be fixed properly."""
    313         return
    314 
    315         import os
    316         if os.name == 'posix':
    317             node = uuid._ifconfig_getnode()
    318             if node is not None:
    319                 self.check_node(node, 'ifconfig')
    320 
     305        node = uuid._ifconfig_getnode()
     306        if node is not None:
     307            self.check_node(node, 'ifconfig')
     308
     309    @unittest.skipUnless(os.name == 'nt', 'requires Windows')
    321310    def test_ipconfig_getnode(self):
    322         import os
    323         if os.name == 'nt':
    324             node = uuid._ipconfig_getnode()
    325             if node is not None:
    326                 self.check_node(node, 'ipconfig')
    327 
     311        node = uuid._ipconfig_getnode()
     312        if node is not None:
     313            self.check_node(node, 'ipconfig')
     314
     315    @unittest.skipUnless(importable('win32wnet'), 'requires win32wnet')
     316    @unittest.skipUnless(importable('netbios'), 'requires netbios')
    328317    def test_netbios_getnode(self):
    329         if importable('win32wnet') and importable('netbios'):
    330             self.check_node(uuid._netbios_getnode(), 'netbios')
     318        self.check_node(uuid._netbios_getnode(), 'netbios')
    331319
    332320    def test_random_getnode(self):
    333321        node = uuid._random_getnode()
    334         self.assert_(0 <= node)
    335         self.assert_(node < (1L <<48))
    336 
     322        # Least significant bit of first octet must be set.
     323        self.assertTrue(node & 0x010000000000)
     324        self.assertTrue(node < (1L << 48))
     325
     326    @unittest.skipUnless(os.name == 'posix', 'requires Posix')
     327    @unittest.skipUnless(importable('ctypes'), 'requires ctypes')
    337328    def test_unixdll_getnode(self):
    338         import sys
    339         print >>sys.__stdout__, \
    340 """    WARNING: uuid._unixdll_getnode is unreliable on many platforms.
    341         It is disabled until the code and/or test can be fixed properly."""
    342         return
    343 
    344         import os
    345         if importable('ctypes') and os.name == 'posix':
     329        try: # Issues 1481, 3581: _uuid_generate_time() might be None.
    346330            self.check_node(uuid._unixdll_getnode(), 'unixdll')
    347 
     331        except TypeError:
     332            pass
     333
     334    @unittest.skipUnless(os.name == 'nt', 'requires Windows')
     335    @unittest.skipUnless(importable('ctypes'), 'requires ctypes')
    348336    def test_windll_getnode(self):
    349         import os
    350         if importable('ctypes') and os.name == 'nt':
    351             self.check_node(uuid._windll_getnode(), 'windll')
     337        self.check_node(uuid._windll_getnode(), 'windll')
    352338
    353339    def test_getnode(self):
    354         import sys
    355         print >>sys.__stdout__, \
    356 """    WARNING: uuid.getnode is unreliable on many platforms.
    357         It is disabled until the code and/or test can be fixed properly."""
    358         return
    359 
    360340        node1 = uuid.getnode()
    361341        self.check_node(node1, "getnode1")
     
    367347        self.assertEqual(node1, node2)
    368348
     349    @unittest.skipUnless(importable('ctypes'), 'requires ctypes')
    369350    def test_uuid1(self):
    370         # uuid1 requires ctypes.
    371         try:
    372             import ctypes
    373         except ImportError:
    374             return
    375 
    376351        equal = self.assertEqual
    377352
     
    426401            equal(str(u), v)
    427402
     403    @unittest.skipUnless(importable('ctypes'), 'requires ctypes')
    428404    def test_uuid4(self):
    429         # uuid4 requires ctypes.
    430         try:
    431             import ctypes
    432         except ImportError:
    433             return
    434 
    435405        equal = self.assertEqual
    436406
     
    464434            equal(str(u), v)
    465435
     436    @unittest.skipUnless(os.name == 'posix', 'requires Posix')
     437    def testIssue8621(self):
     438        # On at least some versions of OSX uuid.uuid4 generates
     439        # the same sequence of UUIDs in the parent and any
     440        # children started using fork.
     441        fds = os.pipe()
     442        pid = os.fork()
     443        if pid == 0:
     444            os.close(fds[0])
     445            value = uuid.uuid4()
     446            os.write(fds[1], value.hex)
     447            os._exit(0)
     448
     449        else:
     450            os.close(fds[1])
     451            self.addCleanup(os.close, fds[0])
     452            parent_value = uuid.uuid4().hex
     453            os.waitpid(pid, 0)
     454            child_value = os.read(fds[0], 100)
     455
     456            self.assertNotEqual(parent_value, child_value)
     457
     458
     459
     460
    466461
    467462def test_main():
Note: See TracChangeset for help on using the changeset viewer.