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

Delta Between Two Patch Sets: Lib/test/test_uuid.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 9 months ago
Right Patch Set: Created 5 years, 6 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_unicode_file.py ('k') | Lib/test/test_weakset.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import unittest 1 import unittest
2 from test import support
2 import builtins 3 import builtins
4 import io
3 import os 5 import os
6 import shutil
4 import uuid 7 import uuid
5 8
6 def importable(name): 9 def importable(name):
7 try: 10 try:
8 __import__(name) 11 __import__(name)
9 return True 12 return True
10 except: 13 except:
11 return False 14 return False
12 15
13 class TestUUID(unittest.TestCase): 16 class TestUUID(unittest.TestCase):
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 def test_getnode(self): 352 def test_getnode(self):
350 node1 = uuid.getnode() 353 node1 = uuid.getnode()
351 self.check_node(node1, "getnode1") 354 self.check_node(node1, "getnode1")
352 355
353 # Test it again to ensure consistency. 356 # Test it again to ensure consistency.
354 node2 = uuid.getnode() 357 node2 = uuid.getnode()
355 self.check_node(node2, "getnode2") 358 self.check_node(node2, "getnode2")
356 359
357 self.assertEqual(node1, node2) 360 self.assertEqual(node1, node2)
358 361
362 @unittest.skipUnless(os.name == 'posix', 'requires Posix')
363 def test_find_mac(self):
364 data = '''\
365
366 fake hwaddr
367 cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 -00
368 eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
369 '''
370 def mock_popen(cmd):
371 return io.StringIO(data)
372
373 if shutil.which('ifconfig') is None:
374 path = os.pathsep.join(('/sbin', '/usr/sbin'))
375 if shutil.which('ifconfig', path=path) is None:
376 self.skipTest('requires ifconfig')
377
378 with support.swap_attr(os, 'popen', mock_popen):
379 mac = uuid._find_mac(
380 command='ifconfig',
381 args='',
382 hw_identifiers=['hwaddr'],
383 get_index=lambda x: x + 1,
384 )
385 self.assertEqual(mac, 0x1234567890ab)
386
359 @unittest.skipUnless(importable('ctypes'), 'requires ctypes') 387 @unittest.skipUnless(importable('ctypes'), 'requires ctypes')
360 def test_uuid1(self): 388 def test_uuid1(self):
361 equal = self.assertEqual 389 equal = self.assertEqual
362 390
363 # Make sure uuid1() generates UUIDs that are actually version 1. 391 # Make sure uuid1() generates UUIDs that are actually version 1.
364 for u in [uuid.uuid1() for i in range(10)]: 392 for u in [uuid.uuid1() for i in range(10)]:
365 equal(u.variant, uuid.RFC_4122) 393 equal(u.variant, uuid.RFC_4122)
366 equal(u.version, 1) 394 equal(u.version, 1)
367 395
368 # Make sure the generated UUIDs are actually unique. 396 # Make sure the generated UUIDs are actually unique.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 self.addCleanup(os.close, fds[0]) 489 self.addCleanup(os.close, fds[0])
462 parent_value = uuid.uuid4().hex 490 parent_value = uuid.uuid4().hex
463 os.waitpid(pid, 0) 491 os.waitpid(pid, 0)
464 child_value = os.read(fds[0], 100).decode('latin-1') 492 child_value = os.read(fds[0], 100).decode('latin-1')
465 493
466 self.assertNotEqual(parent_value, child_value) 494 self.assertNotEqual(parent_value, child_value)
467 495
468 496
469 if __name__ == '__main__': 497 if __name__ == '__main__':
470 unittest.main() 498 unittest.main()
LEFTRIGHT

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