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

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

Issue 11508: Virtual Interfaces cause uuid._find_mac to raise a ValueError under Linux
Patch Set: Created 8 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 | « no previous file | Lib/uuid.py » ('j') | Lib/uuid.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from unittest import TestCase 1 from unittest import TestCase
2 from test import support 2 from test import support
3 import builtins 3 import builtins
4 import uuid 4 import uuid
5 5
6 def importable(name): 6 def importable(name):
7 try: 7 try:
8 __import__(name) 8 __import__(name)
9 return True 9 return True
10 except: 10 except:
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 def test_getnode(self): 352 def test_getnode(self):
353 import sys 353 import sys
354 node1 = uuid.getnode() 354 node1 = uuid.getnode()
355 self.check_node(node1, "getnode1") 355 self.check_node(node1, "getnode1")
356 356
357 # Test it again to ensure consistency. 357 # Test it again to ensure consistency.
358 node2 = uuid.getnode() 358 node2 = uuid.getnode()
359 self.check_node(node2, "getnode2") 359 self.check_node(node2, "getnode2")
360 360
361 self.assertEqual(node1, node2) 361 self.assertEqual(node1, node2)
362
363 def test__find_mac(self):
364 import os
365
366 original_popen = os.popen
367
368 class MockPopen(object):
storchaka 2013/10/27 14:09:20 I think this can be simpler. def mock_popen(cmd):
kfrazier 2013/10/31 03:36:29 I didn't know about support.swap_attr. That is a m
storchaka 2013/11/09 21:08:31 io.StringIO supports context manager protocol.
369 data = [
370 ('cscotun0 Link encap:UNSPEC HWaddr '
371 '00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00'),
372 'eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab',
373 ]
374 def __init__(self, cmd):
375 pass
376 def __enter__(self):
377 return self
378 def __exit__(self, exc_type, exc_value, traceback):
379 pass
380 def __iter__(self):
381 return iter(self.data)
382
383 os.popen = MockPopen
384
385 try:
386 mac = uuid._find_mac(
387 command='ifconfig',
388 args='',
389 hw_identifiers=['hwaddr'],
390 get_index=lambda x: x + 1,
391 )
392 self.assertEqual(mac, 0x1234567890ab)
393 finally:
394 os.popen = original_popen
362 395
363 def test_uuid1(self): 396 def test_uuid1(self):
364 # uuid1 requires ctypes. 397 # uuid1 requires ctypes.
365 try: 398 try:
366 import ctypes 399 import ctypes
367 except ImportError: 400 except ImportError:
368 return 401 return
369 402
370 equal = self.assertEqual 403 equal = self.assertEqual
371 404
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 517
485 518
486 519
487 520
488 521
489 def test_main(): 522 def test_main():
490 support.run_unittest(TestUUID) 523 support.run_unittest(TestUUID)
491 524
492 if __name__ == '__main__': 525 if __name__ == '__main__':
493 test_main() 526 test_main()
OLDNEW
« no previous file with comments | « no previous file | Lib/uuid.py » ('j') | Lib/uuid.py » ('J')

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