当前位置: 首页>>代码示例>>Python>>正文


Python SelectReactor.disconnectAll方法代码示例

本文整理汇总了Python中twisted.internet.selectreactor.SelectReactor.disconnectAll方法的典型用法代码示例。如果您正苦于以下问题:Python SelectReactor.disconnectAll方法的具体用法?Python SelectReactor.disconnectAll怎么用?Python SelectReactor.disconnectAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.selectreactor.SelectReactor的用法示例。


在下文中一共展示了SelectReactor.disconnectAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: supplicant

# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import disconnectAll [as 别名]
def supplicant():
    """Run a reactor and provide access to the supplicant driver"""
    reactor = SelectReactor()
    t = threading.Thread(target=reactor.run, kwargs={'installSignalHandlers': 0})
    t.start()
    time.sleep(0.1)  # let reactor start
    driver = WpaSupplicantDriver(reactor)
    supplicant = driver.connect()
    try:
        yield supplicant
    except Exception as e:
        print('FAIL - {}'.format(e))
    else:
        print('OK')
    reactor.disconnectAll()
    reactor.sigTerm()
    t.join()
开发者ID:devmapal,项目名称:python-wpa-supplicant,代码行数:19,代码来源:cli.py

示例2: TestWpaSupplicant

# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import disconnectAll [as 别名]
class TestWpaSupplicant(unittest.TestCase):
    def setUp(self):
        mocks.init()
        self._taskrunner = ThreadedTaskRunner()
        self._taskrunner.start()
        self._reactor = SelectReactor()
        self._driver = WpaSupplicantDriver(self._reactor)
        self._reactor_thread = threading.Thread(target=self._reactor.run,
                                                kwargs={'installSignalHandlers': 0})
        self._reactor_thread.start()
        time.sleep(0.1)
        self._supplicant = self._driver.connect()

    def tearDown(self):
        self._reactor.disconnectAll()
        self._reactor.sigTerm()
        self._reactor_thread.join()
        self._taskrunner.stop()

    #
    # Helpers
    #
    def _get_interface(self, interface_name):
        return self._supplicant.get_interface(interface_name)

    def _get_any_bss(self):
        iface = self._get_interface('wlan0')
        return BSS('/fi/w1/wpa_supplicant1/Interfaces/1/BSSs/1',
                   iface._conn,
                   iface._reactor)

    #
    # Test Driver
    #
    def test_connect(self):
        supplicant = self._driver.connect()
        self.assertIsInstance(supplicant, WpaSupplicant)

    #
    # Test Base
    #
    def test_register_for_signal(self):
        cb = mock.Mock()
        self._supplicant.register_signal('mysig', cb)
        self._supplicant._introspection.fire_signal('mysig', True)
        cb.assert_called_once_with(True)

    def test_register_for_signal_once(self):
        def fire_signal(result):
            time.sleep(1)
            self._supplicant._introspection.fire_signal('mysig', result)

        deferred_queue = self._supplicant.register_signal_once('mysig')
        self._taskrunner.queue(Task(fire_signal, True))
        result = deferred_queue.get()
        self.assertEqual(result, True)

    #
    # Test Supplicant
    #
    def test_get_interface(self):
        interface = self._supplicant.get_interface('wlan0')
        self._supplicant._without_introspection.callRemote.assert_called_with(
            'GetInterface', 'wlan0')
        self.assertTrue(isinstance(interface, Interface))
        self.assertEqual(interface.get_path(), '/fi/w1/wpa_supplicant1/Interfaces/3')

    def test_get_unknown_interface(self):
        self.assertRaises(InterfaceUnknown, self._supplicant.get_interface, 'wlan99')

    def test_create_interface(self):
        interface = self._supplicant.create_interface('wlan0')
        self._supplicant._without_introspection.callRemote.assert_called_with(
            'CreateInterface',
            {'Ifname': 'wlan0'})
        self.assertTrue(isinstance(interface, Interface))
        self.assertEqual(interface.get_path(), '/fi/w1/wpa_supplicant1/Interfaces/3')

    def test_create_interface_already_exists(self):
        self.test_create_interface()
        self.assertRaises(InterfaceExists, self._supplicant.create_interface, 'wlan0')

    def test_remove_interface(self):
        self._supplicant.create_interface('wlan0')
        returnval = self._supplicant.remove_interface(
            '/fi/w1/wpa_supplicant1/Interfaces/3')
        self._supplicant._without_introspection.callRemote.assert_called_with(
            'RemoveInterface',
            '/fi/w1/wpa_supplicant1/Interfaces/3')
        self.assertEqual(returnval, None)

    def test_remove_unknown_interface(self):
        supplicant = self._driver.connect()
        self.assertRaises(InterfaceUnknown, supplicant.remove_interface, 'wlan99')

    def test_get_debug_level(self):
        supplicant = self._driver.connect()
        self.assertEqual(supplicant.get_debug_level(), six.u('info'))

    def test_get_debug_timestamp(self):
#.........这里部分代码省略.........
开发者ID:iRaffnix,项目名称:python-wpa-supplicant,代码行数:103,代码来源:test_core.py


注:本文中的twisted.internet.selectreactor.SelectReactor.disconnectAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。