Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_uuid.TestUUID Class Reference
Inheritance diagram for test.test_uuid.TestUUID:
Inheritance graph
[legend]
Collaboration diagram for test.test_uuid.TestUUID:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_UUID
def test_exceptions
def check_node
def test_ifconfig_getnode
def test_ipconfig_getnode
def test_netbios_getnode
def test_random_getnode
def test_unixdll_getnode
def test_windll_getnode
def test_getnode
def test_uuid1
def test_uuid3
def test_uuid4
def test_uuid5
def testIssue8621

Static Public Attributes

 last_node = None
dictionary source2node = {}

Detailed Description

Definition at line 13 of file test_uuid.py.


Member Function Documentation

def test.test_uuid.TestUUID.check_node (   self,
  node,
  source 
)

Definition at line 294 of file test_uuid.py.

00294 
00295     def check_node(self, node, source):
00296         message = "%012x is not an RFC 4122 node ID" % node
00297         self.assertTrue(0 < node, message)
00298         self.assertTrue(node < (1 << 48), message)
00299 
00300         TestUUID.source2node[source] = node
00301         if TestUUID.last_node:
00302             if TestUUID.last_node != node:
00303                 msg = "different sources disagree on node:\n"
00304                 for s, n in TestUUID.source2node.items():
00305                     msg += "    from source %r, node was %012x\n" % (s, n)
00306                 # There's actually no reason to expect the MAC addresses
00307                 # to agree across various methods -- e.g., a box may have
00308                 # multiple network interfaces, and different ways of getting
00309                 # a MAC address may favor different HW.
00310                 ##self.fail(msg)
00311         else:
00312             TestUUID.last_node = node

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file test_uuid.py.

00203 
00204     def test_exceptions(self):
00205         badvalue = lambda f: self.assertRaises(ValueError, f)
00206         badtype = lambda f: self.assertRaises(TypeError, f)
00207 
00208         # Badly formed hex strings.
00209         badvalue(lambda: uuid.UUID(''))
00210         badvalue(lambda: uuid.UUID('abc'))
00211         badvalue(lambda: uuid.UUID('1234567812345678123456781234567'))
00212         badvalue(lambda: uuid.UUID('123456781234567812345678123456789'))
00213         badvalue(lambda: uuid.UUID('123456781234567812345678z2345678'))
00214 
00215         # Badly formed bytes.
00216         badvalue(lambda: uuid.UUID(bytes='abc'))
00217         badvalue(lambda: uuid.UUID(bytes='\0'*15))
00218         badvalue(lambda: uuid.UUID(bytes='\0'*17))
00219 
00220         # Badly formed bytes_le.
00221         badvalue(lambda: uuid.UUID(bytes_le='abc'))
00222         badvalue(lambda: uuid.UUID(bytes_le='\0'*15))
00223         badvalue(lambda: uuid.UUID(bytes_le='\0'*17))
00224 
00225         # Badly formed fields.
00226         badvalue(lambda: uuid.UUID(fields=(1,)))
00227         badvalue(lambda: uuid.UUID(fields=(1, 2, 3, 4, 5)))
00228         badvalue(lambda: uuid.UUID(fields=(1, 2, 3, 4, 5, 6, 7)))
00229 
00230         # Field values out of range.
00231         badvalue(lambda: uuid.UUID(fields=(-1, 0, 0, 0, 0, 0)))
00232         badvalue(lambda: uuid.UUID(fields=(0x100000000, 0, 0, 0, 0, 0)))
00233         badvalue(lambda: uuid.UUID(fields=(0, -1, 0, 0, 0, 0)))
00234         badvalue(lambda: uuid.UUID(fields=(0, 0x10000, 0, 0, 0, 0)))
00235         badvalue(lambda: uuid.UUID(fields=(0, 0, -1, 0, 0, 0)))
00236         badvalue(lambda: uuid.UUID(fields=(0, 0, 0x10000, 0, 0, 0)))
00237         badvalue(lambda: uuid.UUID(fields=(0, 0, 0, -1, 0, 0)))
00238         badvalue(lambda: uuid.UUID(fields=(0, 0, 0, 0x100, 0, 0)))
00239         badvalue(lambda: uuid.UUID(fields=(0, 0, 0, 0, -1, 0)))
00240         badvalue(lambda: uuid.UUID(fields=(0, 0, 0, 0, 0x100, 0)))
00241         badvalue(lambda: uuid.UUID(fields=(0, 0, 0, 0, 0, -1)))
00242         badvalue(lambda: uuid.UUID(fields=(0, 0, 0, 0, 0, 0x1000000000000)))
00243 
00244         # Version number out of range.
00245         badvalue(lambda: uuid.UUID('00'*16, version=0))
00246         badvalue(lambda: uuid.UUID('00'*16, version=6))
00247 
00248         # Integer value out of range.
00249         badvalue(lambda: uuid.UUID(int=-1))
00250         badvalue(lambda: uuid.UUID(int=1<<128))
00251 
00252         # Must supply exactly one of hex, bytes, fields, int.
00253         h, b, f, i = '00'*16, b'\0'*16, (0, 0, 0, 0, 0, 0), 0
00254         uuid.UUID(h)
00255         uuid.UUID(hex=h)
00256         uuid.UUID(bytes=b)
00257         uuid.UUID(bytes_le=b)
00258         uuid.UUID(fields=f)
00259         uuid.UUID(int=i)
00260 
00261         # Wrong number of arguments (positional).
00262         badtype(lambda: uuid.UUID())
00263         badtype(lambda: uuid.UUID(h, b))
00264         badtype(lambda: uuid.UUID(h, b, b))
00265         badtype(lambda: uuid.UUID(h, b, b, f))
00266         badtype(lambda: uuid.UUID(h, b, b, f, i))
00267 
00268         # Duplicate arguments.
00269         for hh in [[], [('hex', h)]]:
00270             for bb in [[], [('bytes', b)]]:
00271                 for bble in [[], [('bytes_le', b)]]:
00272                     for ii in [[], [('int', i)]]:
00273                         for ff in [[], [('fields', f)]]:
00274                             args = dict(hh + bb + bble + ii + ff)
00275                             if len(args) != 0:
00276                                 badtype(lambda: uuid.UUID(h, **args))
00277                             if len(args) != 1:
00278                                 badtype(lambda: uuid.UUID(**args))
00279 
00280         # Immutability.
00281         u = uuid.UUID(h)
00282         badtype(lambda: setattr(u, 'hex', h))
00283         badtype(lambda: setattr(u, 'bytes', b))
00284         badtype(lambda: setattr(u, 'bytes_le', b))
00285         badtype(lambda: setattr(u, 'fields', f))
00286         badtype(lambda: setattr(u, 'int', i))
00287         badtype(lambda: setattr(u, 'time_low', 0))
00288         badtype(lambda: setattr(u, 'time_mid', 0))
00289         badtype(lambda: setattr(u, 'time_hi_version', 0))
00290         badtype(lambda: setattr(u, 'time_hi_version', 0))
00291         badtype(lambda: setattr(u, 'clock_seq_hi_variant', 0))
00292         badtype(lambda: setattr(u, 'clock_seq_low', 0))
00293         badtype(lambda: setattr(u, 'node', 0))

Here is the call graph for this function:

Definition at line 352 of file test_uuid.py.

00352 
00353     def test_getnode(self):
00354         import sys
00355         node1 = uuid.getnode()
00356         self.check_node(node1, "getnode1")
00357 
00358         # Test it again to ensure consistency.
00359         node2 = uuid.getnode()
00360         self.check_node(node2, "getnode2")
00361 
00362         self.assertEqual(node1, node2)

Here is the call graph for this function:

Definition at line 313 of file test_uuid.py.

00313 
00314     def test_ifconfig_getnode(self):
00315         import sys
00316         import os
00317         if os.name == 'posix':
00318             node = uuid._ifconfig_getnode()
00319             if node is not None:
00320                 self.check_node(node, 'ifconfig')

Here is the call graph for this function:

Definition at line 321 of file test_uuid.py.

00321 
00322     def test_ipconfig_getnode(self):
00323         import os
00324         if os.name == 'nt':
00325             node = uuid._ipconfig_getnode()
00326             if node is not None:
00327                 self.check_node(node, 'ipconfig')

Here is the call graph for this function:

Definition at line 328 of file test_uuid.py.

00328 
00329     def test_netbios_getnode(self):
00330         if importable('win32wnet') and importable('netbios'):
00331             self.check_node(uuid._netbios_getnode(), 'netbios')

Here is the call graph for this function:

Definition at line 332 of file test_uuid.py.

00332 
00333     def test_random_getnode(self):
00334         node = uuid._random_getnode()
00335         # Least significant bit of first octet must be set.
00336         self.assertTrue(node & 0x010000000000)
00337         self.assertTrue(node < (1 << 48))

Here is the call graph for this function:

Definition at line 338 of file test_uuid.py.

00338 
00339     def test_unixdll_getnode(self):
00340         import sys
00341         import os
00342         if importable('ctypes') and os.name == 'posix':
00343             try: # Issues 1481, 3581: _uuid_generate_time() might be None.
00344                 self.check_node(uuid._unixdll_getnode(), 'unixdll')
00345             except TypeError:
00346                 pass

Here is the call graph for this function:

Definition at line 17 of file test_uuid.py.

00017 
00018     def test_UUID(self):
00019         equal = self.assertEqual
00020         ascending = []
00021         for (string, curly, hex, bytes, bytes_le, fields, integer, urn,
00022              time, clock_seq, variant, version) in [
00023             ('00000000-0000-0000-0000-000000000000',
00024              '{00000000-0000-0000-0000-000000000000}',
00025              '00000000000000000000000000000000',
00026              b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
00027              b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
00028              (0, 0, 0, 0, 0, 0),
00029              0,
00030              'urn:uuid:00000000-0000-0000-0000-000000000000',
00031              0, 0, uuid.RESERVED_NCS, None),
00032             ('00010203-0405-0607-0809-0a0b0c0d0e0f',
00033              '{00010203-0405-0607-0809-0a0b0c0d0e0f}',
00034              '000102030405060708090a0b0c0d0e0f',
00035              b'\0\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\x0d\x0e\x0f',
00036              b'\x03\x02\x01\0\x05\x04\x07\x06\x08\t\n\x0b\x0c\x0d\x0e\x0f',
00037              (0x00010203, 0x0405, 0x0607, 8, 9, 0x0a0b0c0d0e0f),
00038              0x000102030405060708090a0b0c0d0e0f,
00039              'urn:uuid:00010203-0405-0607-0809-0a0b0c0d0e0f',
00040              0x607040500010203, 0x809, uuid.RESERVED_NCS, None),
00041             ('02d9e6d5-9467-382e-8f9b-9300a64ac3cd',
00042              '{02d9e6d5-9467-382e-8f9b-9300a64ac3cd}',
00043              '02d9e6d59467382e8f9b9300a64ac3cd',
00044              b'\x02\xd9\xe6\xd5\x94\x67\x38\x2e\x8f\x9b\x93\x00\xa6\x4a\xc3\xcd',
00045              b'\xd5\xe6\xd9\x02\x67\x94\x2e\x38\x8f\x9b\x93\x00\xa6\x4a\xc3\xcd',
00046              (0x02d9e6d5, 0x9467, 0x382e, 0x8f, 0x9b, 0x9300a64ac3cd),
00047              0x02d9e6d59467382e8f9b9300a64ac3cd,
00048              'urn:uuid:02d9e6d5-9467-382e-8f9b-9300a64ac3cd',
00049              0x82e946702d9e6d5, 0xf9b, uuid.RFC_4122, 3),
00050             ('12345678-1234-5678-1234-567812345678',
00051              '{12345678-1234-5678-1234-567812345678}',
00052              '12345678123456781234567812345678',
00053              b'\x12\x34\x56\x78'*4,
00054              b'\x78\x56\x34\x12\x34\x12\x78\x56\x12\x34\x56\x78\x12\x34\x56\x78',
00055              (0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678),
00056              0x12345678123456781234567812345678,
00057              'urn:uuid:12345678-1234-5678-1234-567812345678',
00058              0x678123412345678, 0x1234, uuid.RESERVED_NCS, None),
00059             ('6ba7b810-9dad-11d1-80b4-00c04fd430c8',
00060              '{6ba7b810-9dad-11d1-80b4-00c04fd430c8}',
00061              '6ba7b8109dad11d180b400c04fd430c8',
00062              b'\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00063              b'\x10\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00064              (0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8),
00065              0x6ba7b8109dad11d180b400c04fd430c8,
00066              'urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8',
00067              0x1d19dad6ba7b810, 0xb4, uuid.RFC_4122, 1),
00068             ('6ba7b811-9dad-11d1-80b4-00c04fd430c8',
00069              '{6ba7b811-9dad-11d1-80b4-00c04fd430c8}',
00070              '6ba7b8119dad11d180b400c04fd430c8',
00071              b'\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00072              b'\x11\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00073              (0x6ba7b811, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8),
00074              0x6ba7b8119dad11d180b400c04fd430c8,
00075              'urn:uuid:6ba7b811-9dad-11d1-80b4-00c04fd430c8',
00076              0x1d19dad6ba7b811, 0xb4, uuid.RFC_4122, 1),
00077             ('6ba7b812-9dad-11d1-80b4-00c04fd430c8',
00078              '{6ba7b812-9dad-11d1-80b4-00c04fd430c8}',
00079              '6ba7b8129dad11d180b400c04fd430c8',
00080              b'\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00081              b'\x12\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00082              (0x6ba7b812, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8),
00083              0x6ba7b8129dad11d180b400c04fd430c8,
00084              'urn:uuid:6ba7b812-9dad-11d1-80b4-00c04fd430c8',
00085              0x1d19dad6ba7b812, 0xb4, uuid.RFC_4122, 1),
00086             ('6ba7b814-9dad-11d1-80b4-00c04fd430c8',
00087              '{6ba7b814-9dad-11d1-80b4-00c04fd430c8}',
00088              '6ba7b8149dad11d180b400c04fd430c8',
00089              b'\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00090              b'\x14\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8',
00091              (0x6ba7b814, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8),
00092              0x6ba7b8149dad11d180b400c04fd430c8,
00093              'urn:uuid:6ba7b814-9dad-11d1-80b4-00c04fd430c8',
00094              0x1d19dad6ba7b814, 0xb4, uuid.RFC_4122, 1),
00095             ('7d444840-9dc0-11d1-b245-5ffdce74fad2',
00096              '{7d444840-9dc0-11d1-b245-5ffdce74fad2}',
00097              '7d4448409dc011d1b2455ffdce74fad2',
00098              b'\x7d\x44\x48\x40\x9d\xc0\x11\xd1\xb2\x45\x5f\xfd\xce\x74\xfa\xd2',
00099              b'\x40\x48\x44\x7d\xc0\x9d\xd1\x11\xb2\x45\x5f\xfd\xce\x74\xfa\xd2',
00100              (0x7d444840, 0x9dc0, 0x11d1, 0xb2, 0x45, 0x5ffdce74fad2),
00101              0x7d4448409dc011d1b2455ffdce74fad2,
00102              'urn:uuid:7d444840-9dc0-11d1-b245-5ffdce74fad2',
00103              0x1d19dc07d444840, 0x3245, uuid.RFC_4122, 1),
00104             ('e902893a-9d22-3c7e-a7b8-d6e313b71d9f',
00105              '{e902893a-9d22-3c7e-a7b8-d6e313b71d9f}',
00106              'e902893a9d223c7ea7b8d6e313b71d9f',
00107              b'\xe9\x02\x89\x3a\x9d\x22\x3c\x7e\xa7\xb8\xd6\xe3\x13\xb7\x1d\x9f',
00108              b'\x3a\x89\x02\xe9\x22\x9d\x7e\x3c\xa7\xb8\xd6\xe3\x13\xb7\x1d\x9f',
00109              (0xe902893a, 0x9d22, 0x3c7e, 0xa7, 0xb8, 0xd6e313b71d9f),
00110              0xe902893a9d223c7ea7b8d6e313b71d9f,
00111              'urn:uuid:e902893a-9d22-3c7e-a7b8-d6e313b71d9f',
00112              0xc7e9d22e902893a, 0x27b8, uuid.RFC_4122, 3),
00113             ('eb424026-6f54-4ef8-a4d0-bb658a1fc6cf',
00114              '{eb424026-6f54-4ef8-a4d0-bb658a1fc6cf}',
00115              'eb4240266f544ef8a4d0bb658a1fc6cf',
00116              b'\xeb\x42\x40\x26\x6f\x54\x4e\xf8\xa4\xd0\xbb\x65\x8a\x1f\xc6\xcf',
00117              b'\x26\x40\x42\xeb\x54\x6f\xf8\x4e\xa4\xd0\xbb\x65\x8a\x1f\xc6\xcf',
00118              (0xeb424026, 0x6f54, 0x4ef8, 0xa4, 0xd0, 0xbb658a1fc6cf),
00119              0xeb4240266f544ef8a4d0bb658a1fc6cf,
00120              'urn:uuid:eb424026-6f54-4ef8-a4d0-bb658a1fc6cf',
00121              0xef86f54eb424026, 0x24d0, uuid.RFC_4122, 4),
00122             ('f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
00123              '{f81d4fae-7dec-11d0-a765-00a0c91e6bf6}',
00124              'f81d4fae7dec11d0a76500a0c91e6bf6',
00125              b'\xf8\x1d\x4f\xae\x7d\xec\x11\xd0\xa7\x65\x00\xa0\xc9\x1e\x6b\xf6',
00126              b'\xae\x4f\x1d\xf8\xec\x7d\xd0\x11\xa7\x65\x00\xa0\xc9\x1e\x6b\xf6',
00127              (0xf81d4fae, 0x7dec, 0x11d0, 0xa7, 0x65, 0x00a0c91e6bf6),
00128              0xf81d4fae7dec11d0a76500a0c91e6bf6,
00129              'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
00130              0x1d07decf81d4fae, 0x2765, uuid.RFC_4122, 1),
00131             ('fffefdfc-fffe-fffe-fffe-fffefdfcfbfa',
00132              '{fffefdfc-fffe-fffe-fffe-fffefdfcfbfa}',
00133              'fffefdfcfffefffefffefffefdfcfbfa',
00134              b'\xff\xfe\xfd\xfc\xff\xfe\xff\xfe\xff\xfe\xff\xfe\xfd\xfc\xfb\xfa',
00135              b'\xfc\xfd\xfe\xff\xfe\xff\xfe\xff\xff\xfe\xff\xfe\xfd\xfc\xfb\xfa',
00136              (0xfffefdfc, 0xfffe, 0xfffe, 0xff, 0xfe, 0xfffefdfcfbfa),
00137              0xfffefdfcfffefffefffefffefdfcfbfa,
00138              'urn:uuid:fffefdfc-fffe-fffe-fffe-fffefdfcfbfa',
00139              0xffefffefffefdfc, 0x3ffe, uuid.RESERVED_FUTURE, None),
00140             ('ffffffff-ffff-ffff-ffff-ffffffffffff',
00141              '{ffffffff-ffff-ffff-ffff-ffffffffffff}',
00142              'ffffffffffffffffffffffffffffffff',
00143              b'\xff'*16,
00144              b'\xff'*16,
00145              (0xffffffff, 0xffff, 0xffff, 0xff, 0xff, 0xffffffffffff),
00146              0xffffffffffffffffffffffffffffffff,
00147              'urn:uuid:ffffffff-ffff-ffff-ffff-ffffffffffff',
00148              0xfffffffffffffff, 0x3fff, uuid.RESERVED_FUTURE, None),
00149             ]:
00150             equivalents = []
00151             # Construct each UUID in several different ways.
00152             for u in [uuid.UUID(string), uuid.UUID(curly), uuid.UUID(hex),
00153                       uuid.UUID(bytes=bytes), uuid.UUID(bytes_le=bytes_le),
00154                       uuid.UUID(fields=fields), uuid.UUID(int=integer),
00155                       uuid.UUID(urn)]:
00156                 # Test all conversions and properties of the UUID object.
00157                 equal(str(u), string)
00158                 equal(int(u), integer)
00159                 equal(u.bytes, bytes)
00160                 equal(u.bytes_le, bytes_le)
00161                 equal(u.fields, fields)
00162                 equal(u.time_low, fields[0])
00163                 equal(u.time_mid, fields[1])
00164                 equal(u.time_hi_version, fields[2])
00165                 equal(u.clock_seq_hi_variant, fields[3])
00166                 equal(u.clock_seq_low, fields[4])
00167                 equal(u.node, fields[5])
00168                 equal(u.hex, hex)
00169                 equal(u.int, integer)
00170                 equal(u.urn, urn)
00171                 equal(u.time, time)
00172                 equal(u.clock_seq, clock_seq)
00173                 equal(u.variant, variant)
00174                 equal(u.version, version)
00175                 equivalents.append(u)
00176 
00177             # Different construction methods should give the same UUID.
00178             for u in equivalents:
00179                 for v in equivalents:
00180                     equal(u, v)
00181 
00182             # Bug 7380: "bytes" and "bytes_le" should give the same type.
00183             equal(type(u.bytes), builtins.bytes)
00184             equal(type(u.bytes_le), builtins.bytes)
00185 
00186             ascending.append(u)
00187 
00188         # Test comparison of UUIDs.
00189         for i in range(len(ascending)):
00190             for j in range(len(ascending)):
00191                 equal(i < j, ascending[i] < ascending[j])
00192                 equal(i <= j, ascending[i] <= ascending[j])
00193                 equal(i == j, ascending[i] == ascending[j])
00194                 equal(i > j, ascending[i] > ascending[j])
00195                 equal(i >= j, ascending[i] >= ascending[j])
00196                 equal(i != j, ascending[i] != ascending[j])
00197 
00198         # Test sorting of UUIDs (above list is in ascending order).
00199         resorted = ascending[:]
00200         resorted.reverse()
00201         resorted.sort()
00202         equal(ascending, resorted)

Here is the call graph for this function:

Definition at line 363 of file test_uuid.py.

00363 
00364     def test_uuid1(self):
00365         # uuid1 requires ctypes.
00366         try:
00367             import ctypes
00368         except ImportError:
00369             return
00370 
00371         equal = self.assertEqual
00372 
00373         # Make sure uuid1() generates UUIDs that are actually version 1.
00374         for u in [uuid.uuid1() for i in range(10)]:
00375             equal(u.variant, uuid.RFC_4122)
00376             equal(u.version, 1)
00377 
00378         # Make sure the generated UUIDs are actually unique.
00379         uuids = {}
00380         for u in [uuid.uuid1() for i in range(1000)]:
00381             uuids[u] = 1
00382         equal(len(uuids.keys()), 1000)
00383 
00384         # Make sure the supplied node ID appears in the UUID.
00385         u = uuid.uuid1(0)
00386         equal(u.node, 0)
00387         u = uuid.uuid1(0x123456789abc)
00388         equal(u.node, 0x123456789abc)
00389         u = uuid.uuid1(0xffffffffffff)
00390         equal(u.node, 0xffffffffffff)
00391 
00392         # Make sure the supplied clock sequence appears in the UUID.
00393         u = uuid.uuid1(0x123456789abc, 0)
00394         equal(u.node, 0x123456789abc)
00395         equal(((u.clock_seq_hi_variant & 0x3f) << 8) | u.clock_seq_low, 0)
00396         u = uuid.uuid1(0x123456789abc, 0x1234)
00397         equal(u.node, 0x123456789abc)
00398         equal(((u.clock_seq_hi_variant & 0x3f) << 8) |
00399                          u.clock_seq_low, 0x1234)
00400         u = uuid.uuid1(0x123456789abc, 0x3fff)
00401         equal(u.node, 0x123456789abc)
00402         equal(((u.clock_seq_hi_variant & 0x3f) << 8) |
00403                          u.clock_seq_low, 0x3fff)

Here is the call graph for this function:

Definition at line 404 of file test_uuid.py.

00404 
00405     def test_uuid3(self):
00406         equal = self.assertEqual
00407 
00408         # Test some known version-3 UUIDs.
00409         for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
00410                       '6fa459ea-ee8a-3ca4-894e-db77e160355e'),
00411                      (uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
00412                       '9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
00413                      (uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
00414                       'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
00415                      (uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
00416                       '658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
00417                     ]:
00418             equal(u.variant, uuid.RFC_4122)
00419             equal(u.version, 3)
00420             equal(u, uuid.UUID(v))
00421             equal(str(u), v)

Here is the call graph for this function:

Definition at line 422 of file test_uuid.py.

00422 
00423     def test_uuid4(self):
00424         # uuid4 requires ctypes.
00425         try:
00426             import ctypes
00427         except ImportError:
00428             return
00429 
00430         equal = self.assertEqual
00431 
00432         # Make sure uuid4() generates UUIDs that are actually version 4.
00433         for u in [uuid.uuid4() for i in range(10)]:
00434             equal(u.variant, uuid.RFC_4122)
00435             equal(u.version, 4)
00436 
00437         # Make sure the generated UUIDs are actually unique.
00438         uuids = {}
00439         for u in [uuid.uuid4() for i in range(1000)]:
00440             uuids[u] = 1
00441         equal(len(uuids.keys()), 1000)

Here is the call graph for this function:

Definition at line 442 of file test_uuid.py.

00442 
00443     def test_uuid5(self):
00444         equal = self.assertEqual
00445 
00446         # Test some known version-5 UUIDs.
00447         for u, v in [(uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org'),
00448                       '886313e1-3b8a-5372-9b90-0c9aee199e5d'),
00449                      (uuid.uuid5(uuid.NAMESPACE_URL, 'http://python.org/'),
00450                       '4c565f0d-3f5a-5890-b41b-20cf47701c5e'),
00451                      (uuid.uuid5(uuid.NAMESPACE_OID, '1.3.6.1'),
00452                       '1447fa61-5277-5fef-a9b3-fbc6e44f4af3'),
00453                      (uuid.uuid5(uuid.NAMESPACE_X500, 'c=ca'),
00454                       'cc957dd1-a972-5349-98cd-874190002798'),
00455                     ]:
00456             equal(u.variant, uuid.RFC_4122)
00457             equal(u.version, 5)
00458             equal(u, uuid.UUID(v))
00459             equal(str(u), v)

Here is the call graph for this function:

Definition at line 347 of file test_uuid.py.

00347 
00348     def test_windll_getnode(self):
00349         import os
00350         if importable('ctypes') and os.name == 'nt':
00351             self.check_node(uuid._windll_getnode(), 'windll')

Here is the call graph for this function:

Definition at line 460 of file test_uuid.py.

00460 
00461     def testIssue8621(self):
00462         import os
00463         import sys
00464         if os.name != 'posix':
00465             return
00466 
00467         # On at least some versions of OSX uuid.uuid4 generates
00468         # the same sequence of UUIDs in the parent and any
00469         # children started using fork.
00470         fds = os.pipe()
00471         pid = os.fork()
00472         if pid == 0:
00473             os.close(fds[0])
00474             value = uuid.uuid4()
00475             os.write(fds[1], value.hex.encode('latin1'))
00476             os._exit(0)
00477 
00478         else:
00479             os.close(fds[1])
00480             parent_value = uuid.uuid4().hex
00481             os.waitpid(pid, 0)
00482             child_value = os.read(fds[0], 100).decode('latin1')
00483 
00484             self.assertNotEqual(parent_value, child_value)
00485 
00486 
00487 
00488 

Here is the call graph for this function:


Member Data Documentation

Definition at line 14 of file test_uuid.py.

Definition at line 15 of file test_uuid.py.


The documentation for this class was generated from the following file: