def hw(): hw = HardwareManager(port='virtual:{}'.format(path)) hw.connect_direct(1) yield hw hw.disconnect() hw.close()
def hw(virtual_interface): port, _ = virtual_interface hw = HardwareManager(port="ws2:127.0.0.1:{}".format(port)) yield hw hw.close()
def hw(server): port, _ = server logger.info("Creating HardwareManager at port %d", port) hw = HardwareManager(port="ws:127.0.0.1:{}".format(port)) yield hw hw.close()
def hw(server): path, _ = server logger.info("Creating HardwareManager at with socket path %s", path) hw = HardwareManager(port="unix:{}".format(path)) yield hw hw.close()
def test_hardware_manager(mock_bable): """Test if the device adapter works correctly with the HardwareManager.""" # Test using a wrong controller id with pytest.raises(ExternalError): hw = HardwareManager(port='ble:0') # Test without giving the controller id hw = HardwareManager(port='ble') hw.close()
def realtime_scan_hw(): conf_file = os.path.join(os.path.dirname(__file__), 'fast_realtime_test.json') if '@' in conf_file or ',' in conf_file or ';' in conf_file: pytest.skip('Cannot pass device config because path has [@,;] in it') hw = HardwareManager('virtual:realtime_test@%s' % conf_file) yield hw hw.disconnect() hw.close()
def hw_man(gateway, local_broker): """Create a HardwareManager that can talk to our gateway over the local broker.""" reg = ComponentRegistry() reg.set_config('awsiot-endpoint', '') reg.set_config('awsiot-rootcert', '') reg.set_config('awsiot-iamkey', '') reg.set_config('awsiot-iamtoken', '') hw_dev = HardwareManager(port="awsiot:devices/d--0000-0000-0000-0002") yield hw_dev hw_dev.close()
class TestBLED112AdapterStream(unittest.TestCase): """ Test to make sure that the BLED112AdapterStream is working properly Test that it can connect, connect_direct, send rpcs and get reports """ def setUp(self): self.old_serial = serial.Serial serial.Serial = util.dummy_serial.Serial self.adapter = MockBLED112(3) self.dev1 = MockIOTileDevice(100, 'TestCN') self.dev1_ble = MockBLEDevice("00:11:22:33:44:55", self.dev1) self.adapter.add_device(self.dev1_ble) util.dummy_serial.RESPONSE_GENERATOR = self.adapter.generate_response self.dev1.reports = [ IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)]) ] self._reports_received = threading.Event() logging.basicConfig(level=logging.INFO, stream=sys.stdout) self.scanned_devices = [] self.hw = HardwareManager(port='bled112:test') def tearDown(self): self.hw.close() def test_connect_direct(self): self.hw.connect_direct("00:11:22:33:44:55") def test_connect_nonexistent(self): with pytest.raises(HardwareError): self.hw.connect_direct("00:11:22:33:44:56") def test_connect_badconnstring(self): with pytest.raises(HardwareError): self.hw.connect_direct("00:11:22:33:44:5L") def test_report_streaming(self): self.hw.connect_direct("00:11:22:33:44:55") assert self.hw.count_reports() == 0 self.hw.enable_streaming() time.sleep( 0.2) #Wait for report callback to happen from bled112 thread assert self.hw.count_reports() == 1
def proxy_variants_4(): conf_file = os.path.join(os.path.dirname(__file__), 'proxy_match_tile_config.json') if '@' in conf_file or ',' in conf_file or ';' in conf_file: pytest.skip('Cannot pass device config because path has [@,;] in it') reg = ComponentRegistry() # None, None reg.register_extension('iotile.proxy', 'proxy_match_tile', ProxyMatchTest1) reg.register_extension('iotile.proxy', 'proxy_match_tile', ProxyMatchTest2) hw = HardwareManager('virtual:tile_based@%s' % conf_file) yield hw reg.clear_extensions() hw.close()
def tile_based(): conf_file = os.path.join(os.path.dirname(__file__), 'tile_config.json') if '@' in conf_file or ',' in conf_file or ';' in conf_file: pytest.skip('Cannot pass device config because path has [@,;] in it') reg = ComponentRegistry() reg.register_extension('iotile.proxy', 'virtual_tile', 'test/test_hw/virtual_tile.py') reg.register_extension('iotile.proxy', 'simple_virtual_tile', 'test/test_hw/simple_virtual_tile.py') hw = HardwareManager('virtual:tile_based@%s' % conf_file) yield hw reg.clear_extensions() hw.disconnect() hw.close()
class TestBLED112Loopback(unittest.TestCase): def setUp(self): self.vdev = subprocess.Popen( ['virtual_device', 'bled112', 'report_test']) bleds = BLED112Adapter.find_bled112_devices() print(bleds) self.hw = HardwareManager(port='bled112:{}'.format(bleds[1])) def tearDown(self): self.hw.close() self.vdev.terminate() def test_loopback(self): time.sleep(2) print(self.hw.scan()) self.hw.connect(1) con = self.hw.controller() assert con.ModuleName() == 'Simple' self.hw.enable_streaming() assert self.hw.count_reports() == 11
def report_hw(): hw = HardwareManager('virtual:report_test') yield hw hw.disconnect() hw.close()
def simple_hw(): hw = HardwareManager('virtual:simple') yield hw hw.disconnect() hw.close()