當前位置: 首頁>>代碼示例>>Python>>正文


Python uuid._find_mac方法代碼示例

本文整理匯總了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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_uuid.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:25,代碼來源:test_uuid.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:33,代碼來源:test_uuid.py

示例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) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:31,代碼來源:test_uuid.py


注:本文中的uuid._find_mac方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。