def test_send_search_requests(self, _search_interface_mock, netifaces_mock): """Test finding all valid interfaces to send search requests to. No requests are sent.""" # pylint: disable=protected-access xknx = XKNX() netifaces_mock.interfaces.return_value = self.fake_interfaces netifaces_mock.ifaddresses = lambda interface: self.fake_ifaddresses[ interface] netifaces_mock.AF_INET = 2 async def async_none(): return None _search_interface_mock.return_value = asyncio.ensure_future( async_none()) gateway_scanner = GatewayScanner(xknx, timeout_in_seconds=0) test_scan = self.loop.run_until_complete(gateway_scanner.scan()) self.assertEqual(_search_interface_mock.call_count, 2) expected_calls = [ ((gateway_scanner, "lo0", "127.0.0.1"), ), ((gateway_scanner, "en1", "10.1.1.2"), ), ] self.assertEqual(_search_interface_mock.call_args_list, expected_calls) self.assertEqual(test_scan, [])
def test_scan_timeout(self, netifaces_mock): """Test gateway scanner timeout.""" # pylint: disable=protected-access xknx = XKNX() # No interface shall be found netifaces_mock.interfaces.return_value = [] gateway_scanner = GatewayScanner(xknx) gateway_scanner._response_received_or_timeout.wait = MagicMock( side_effect=asyncio.TimeoutError()) timed_out_scan = self.loop.run_until_complete(gateway_scanner.scan()) # Unsuccessfull scan() returns None self.assertEqual(timed_out_scan, [])
async def test_scan_timeout( self, getsockname_mock, udp_transport_send_mock, udp_transport_connect_mock, time_travel, ): """Test gateway scanner timeout.""" xknx = XKNX() gateway_scanner = GatewayScanner(xknx) timed_out_scan_task = asyncio.create_task(gateway_scanner.scan()) await time_travel(gateway_scanner.timeout_in_seconds) # Unsuccessfull scan() returns empty list assert await timed_out_scan_task == []
def test_scan_timeout(self, netifaces_mock): """Test gateway scanner timeout.""" # pylint: disable=protected-access xknx = XKNX(loop=self.loop) # No interface shall be found netifaces_mock.interfaces.return_value = [] gateway_scanner = GatewayScanner(xknx, timeout_in_seconds=0) timed_out_scan = self.loop.run_until_complete(gateway_scanner.scan()) # Timeout handle was cancelled (cancelled method requires Python 3.7) event_has_cancelled = getattr(gateway_scanner._timeout_handle, "cancelled", None) if callable(event_has_cancelled): self.assertTrue(gateway_scanner._timeout_handle.cancelled()) self.assertTrue(gateway_scanner._response_received_or_timeout.is_set()) # Unsuccessfull scan() returns None self.assertEqual(timed_out_scan, [])
def test_scan_timeout(self, netifaces_mock): """Test gateway scanner timeout.""" # pylint: disable=protected-access xknx = XKNX(loop=self.loop) # No interface shall be found netifaces_mock.interfaces.return_value = [] gateway_scanner = GatewayScanner(xknx, timeout_in_seconds=0) timed_out_scan = self.loop.run_until_complete(gateway_scanner.scan()) # Timeout handle was cancelled (cancelled method requires Python 3.7) event_has_cancelled = getattr(gateway_scanner._timeout_handle, "cancelled", None) if callable(event_has_cancelled): self.assertTrue(gateway_scanner._timeout_handle.cancelled()) self.assertTrue(gateway_scanner._response_received_or_timeout.is_set()) # Unsuccessfull scan() returns None self.assertEqual(timed_out_scan, [])
def test_send_search_requests(self, _search_interface_mock, netifaces_mock): """Test finding all valid interfaces to send search requests to. No requests are sent.""" # pylint: disable=protected-access xknx = XKNX(loop=self.loop) netifaces_mock.interfaces.return_value = self.fake_interfaces netifaces_mock.ifaddresses = lambda interface: self.fake_ifaddresses[interface] netifaces_mock.AF_INET = 2 async def async_none(): return None _search_interface_mock.return_value = asyncio.ensure_future(async_none()) gateway_scanner = GatewayScanner(xknx, timeout_in_seconds=0) test_scan = self.loop.run_until_complete(gateway_scanner.scan()) self.assertEqual(_search_interface_mock.call_count, 2) expected_calls = [((gateway_scanner, 'lo0', '127.0.0.1'),), ((gateway_scanner, 'en1', '10.1.1.2'),)] self.assertEqual(_search_interface_mock.call_args_list, expected_calls) self.assertEqual(test_scan, [])