本文整理汇总了Python中uuid._find_mac方法的典型用法代码示例。如果您正苦于以下问题:Python uuid._find_mac方法的具体用法?Python uuid._find_mac怎么用?Python uuid._find_mac使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uuid
的用法示例。
在下文中一共展示了uuid._find_mac方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_mac
# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import _find_mac [as 别名]
def test_find_mac(self):
data = '''
fake hwaddr
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
popen = unittest.mock.MagicMock()
popen.stdout = io.BytesIO(data.encode())
with unittest.mock.patch.object(shutil, 'which',
return_value='/sbin/ifconfig'):
with unittest.mock.patch.object(subprocess, 'Popen',
return_value=popen):
mac = uuid._find_mac(
command='ifconfig',
args='',
hw_identifiers=[b'hwaddr'],
get_index=lambda x: x + 1,
)
self.assertEqual(mac, 0x1234567890ab)
示例2: test_find_mac
# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import _find_mac [as 别名]
def test_find_mac(self):
data = '''\
fake hwaddr
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
def mock_popen(cmd):
return io.StringIO(data)
if shutil.which('ifconfig') is None:
path = os.pathsep.join(('/sbin', '/usr/sbin'))
if shutil.which('ifconfig', path=path) is None:
self.skipTest('requires ifconfig')
with support.swap_attr(os, 'popen', mock_popen):
mac = uuid._find_mac(
command='ifconfig',
args='',
hw_identifiers=['hwaddr'],
get_index=lambda x: x + 1,
)
self.assertEqual(mac, 0x1234567890ab)
示例3: test_find_mac
# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import _find_mac [as 别名]
def test_find_mac(self):
data = '''\
fake hwaddr
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
def mock_popen(cmd):
if sys.platform == 'cli':
return io.StringIO(data)
return io.BytesIO(data)
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, 'ifconfig')
if (os.path.exists(executable) and
os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
self.skipTest('requires ifconfig')
with test_support.swap_attr(os, 'popen', mock_popen):
mac = uuid._find_mac(
command='ifconfig',
args='',
hw_identifiers=['hwaddr'],
get_index=lambda x: x + 1,
)
self.assertEqual(mac, 0x1234567890ab)
示例4: test_find_mac
# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import _find_mac [as 别名]
def test_find_mac(self):
data = '''\
fake hwaddr
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
def mock_popen(cmd):
return io.BytesIO(data)
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, 'ifconfig')
if (os.path.exists(executable) and
os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
self.skipTest('requires ifconfig')
with test_support.swap_attr(os, 'popen', mock_popen):
mac = uuid._find_mac(
command='ifconfig',
args='',
hw_identifiers=['hwaddr'],
get_index=lambda x: x + 1,
)
self.assertEqual(mac, 0x1234567890ab)