def test_that_logging_is_started_on_start(self): # Fixture with patch('edlib.utils.multiranger.LogConfig', return_value=self.log_config_mock): sut = Multiranger(self.ed_mock) # Test sut.start() # Assert self.log_config_mock.start.assert_called_once_with()
def test_that_log_configuration_is_added_on_connect(self): # Fixture with patch('edlib.utils.multiranger.LogConfig', return_value=self.log_config_mock): sut = Multiranger(self.ed_mock) # Test sut.start() # Assert self.log_mock.add_config.assert_called_once_with( self.log_config_mock)
def test_that_data_callback_is_set(self): # Fixture with patch('edlib.utils.multiranger.LogConfig', return_value=self.log_config_mock): sut = Multiranger(self.ed_mock) # Test sut.start() # Assert self.log_config_mock.start.assert_called_once_with() self.assertEqual(1, len( self.log_config_mock.data_received_cb.callbacks))
def test_that_log_configuration_is_correct(self): # Fixture with patch('edlib.utils.multiranger.LogConfig', return_value=self.log_config_mock): sut = Multiranger(self.ed_mock) # Test sut.start() # Assert self.log_config_mock.add_variable.assert_has_calls([ call(self.FRONT), call(self.BACK), call(self.LEFT), call(self.RIGHT), call(self.UP), ])
def test_that_using_context_manager_calls_start_and_stop(self): # Fixture with patch('edlib.utils.multiranger.LogConfig', return_value=self.log_config_mock): with Multiranger(self.ed_mock): pass # Assert self.log_config_mock.start.assert_called_once_with() self.log_config_mock.delete.assert_called_once_with()
def _validate_distance_from_getter(self, expected, getter_name, zranger=False): # Fixture with patch('edlib.utils.multiranger.LogConfig', return_value=self.log_config_mock): sut = Multiranger(self.ed_mock, zranger=zranger) timestmp = 1234 logconf = None self.log_config_mock.data_received_cb.call(timestmp, self.log_data, logconf) # Test actual = getattr(sut, getter_name) # Assert self.assertEqual(expected, actual)
MIN_DISTANCE = 0.2 # m if range is None: return False else: return range < MIN_DISTANCE if __name__ == '__main__': # Initialize the low-level drivers (don't list the debug drivers) edlib.crtp.init_drivers(enable_debug_driver=False) ed = Espdrone(rw_cache='./cache') with SyncEspdrone(URI, ed=ed) as sed: with MotionCommander(sed) as motion_commander: with Multiranger(sed) as multiranger: keep_flying = True while keep_flying: VELOCITY = 0.5 velocity_x = 0.0 velocity_y = 0.0 if is_close(multiranger.front): velocity_x -= VELOCITY if is_close(multiranger.back): velocity_x += VELOCITY if is_close(multiranger.left): velocity_y -= VELOCITY if is_close(multiranger.right):