Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(162058)

Side by Side Diff: Lib/test/test_uuid.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_unicode_file.py ('k') | Lib/test/test_weakset.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 import builtins 3 import builtins
4 import io 4 import io
5 import os 5 import os
6 import shutil 6 import shutil
7 import uuid 7 import uuid
8 8
9 def importable(name): 9 def importable(name):
10 try: 10 try:
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 badtype(lambda: setattr(u, 'time_low', 0)) 289 badtype(lambda: setattr(u, 'time_low', 0))
290 badtype(lambda: setattr(u, 'time_mid', 0)) 290 badtype(lambda: setattr(u, 'time_mid', 0))
291 badtype(lambda: setattr(u, 'time_hi_version', 0)) 291 badtype(lambda: setattr(u, 'time_hi_version', 0))
292 badtype(lambda: setattr(u, 'time_hi_version', 0)) 292 badtype(lambda: setattr(u, 'time_hi_version', 0))
293 badtype(lambda: setattr(u, 'clock_seq_hi_variant', 0)) 293 badtype(lambda: setattr(u, 'clock_seq_hi_variant', 0))
294 badtype(lambda: setattr(u, 'clock_seq_low', 0)) 294 badtype(lambda: setattr(u, 'clock_seq_low', 0))
295 badtype(lambda: setattr(u, 'node', 0)) 295 badtype(lambda: setattr(u, 'node', 0))
296 296
297 def check_node(self, node, source): 297 def check_node(self, node, source):
298 message = "%012x is not an RFC 4122 node ID" % node 298 message = "%012x is not an RFC 4122 node ID" % node
299 self.assertTrue(0 < node, message) 299 self.assertGreater(node, 0, message)
300 self.assertTrue(node < (1 << 48), message) 300 self.assertLess(node, 1 << 48, message)
301 301
302 TestUUID.source2node[source] = node 302 TestUUID.source2node[source] = node
303 if TestUUID.last_node: 303 if TestUUID.last_node:
304 if TestUUID.last_node != node: 304 if TestUUID.last_node != node:
305 msg = "different sources disagree on node:\n" 305 msg = "different sources disagree on node:\n"
306 for s, n in TestUUID.source2node.items(): 306 for s, n in TestUUID.source2node.items():
307 msg += " from source %r, node was %012x\n" % (s, n) 307 msg += " from source %r, node was %012x\n" % (s, n)
308 # There's actually no reason to expect the MAC addresses 308 # There's actually no reason to expect the MAC addresses
309 # to agree across various methods -- e.g., a box may have 309 # to agree across various methods -- e.g., a box may have
310 # multiple network interfaces, and different ways of getting 310 # multiple network interfaces, and different ways of getting
(...skipping 16 matching lines...) Expand all
327 327
328 @unittest.skipUnless(importable('win32wnet'), 'requires win32wnet') 328 @unittest.skipUnless(importable('win32wnet'), 'requires win32wnet')
329 @unittest.skipUnless(importable('netbios'), 'requires netbios') 329 @unittest.skipUnless(importable('netbios'), 'requires netbios')
330 def test_netbios_getnode(self): 330 def test_netbios_getnode(self):
331 self.check_node(uuid._netbios_getnode(), 'netbios') 331 self.check_node(uuid._netbios_getnode(), 'netbios')
332 332
333 def test_random_getnode(self): 333 def test_random_getnode(self):
334 node = uuid._random_getnode() 334 node = uuid._random_getnode()
335 # Least significant bit of first octet must be set. 335 # Least significant bit of first octet must be set.
336 self.assertTrue(node & 0x010000000000) 336 self.assertTrue(node & 0x010000000000)
337 self.assertTrue(node < (1 << 48)) 337 self.assertLess(node, 1 << 48)
338 338
339 @unittest.skipUnless(os.name == 'posix', 'requires Posix') 339 @unittest.skipUnless(os.name == 'posix', 'requires Posix')
340 @unittest.skipUnless(importable('ctypes'), 'requires ctypes') 340 @unittest.skipUnless(importable('ctypes'), 'requires ctypes')
341 def test_unixdll_getnode(self): 341 def test_unixdll_getnode(self):
342 try: # Issues 1481, 3581: _uuid_generate_time() might be None. 342 try: # Issues 1481, 3581: _uuid_generate_time() might be None.
343 self.check_node(uuid._unixdll_getnode(), 'unixdll') 343 self.check_node(uuid._unixdll_getnode(), 'unixdll')
344 except TypeError: 344 except TypeError:
345 pass 345 pass
346 346
347 @unittest.skipUnless(os.name == 'nt', 'requires Windows') 347 @unittest.skipUnless(os.name == 'nt', 'requires Windows')
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 self.addCleanup(os.close, fds[0]) 489 self.addCleanup(os.close, fds[0])
490 parent_value = uuid.uuid4().hex 490 parent_value = uuid.uuid4().hex
491 os.waitpid(pid, 0) 491 os.waitpid(pid, 0)
492 child_value = os.read(fds[0], 100).decode('latin-1') 492 child_value = os.read(fds[0], 100).decode('latin-1')
493 493
494 self.assertNotEqual(parent_value, child_value) 494 self.assertNotEqual(parent_value, child_value)
495 495
496 496
497 if __name__ == '__main__': 497 if __name__ == '__main__':
498 unittest.main() 498 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_unicode_file.py ('k') | Lib/test/test_weakset.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+