def test_then_returns_motor_state(self, mock_port_adapter): dxl_id = 4 adapter = DynamixelAdapter(mock_port_adapter) actual = adapter.read_state(dxl_id) assert type(actual) == MotorState
def create_mayday() -> MaydayRobot: dxl_adapter = DynamixelAdapter(None) dxl_adapter.init_communication() leg_factory = LegFactory() mayday_factory = MaydayRobotFactory(leg_factory) may = mayday_factory.create_basic(dxl_adapter) return may
def test_given_read_present_vel_int_1__then_returns_0_024( self, mock_port_adapter): dxl_id = 4 mock_port_adapter.read = MagicMock(return_value=1) adapter = DynamixelAdapter(mock_port_adapter) actual = adapter.read_state(dxl_id).velocity assert 0.024 - actual < 0.01
def test_given_read_present_vel_int_1__then_returns_1( self, mock_port_adapter): dxl_id = 4 mock_port_adapter.read = MagicMock(return_value=1) adapter = DynamixelAdapter(mock_port_adapter) actual = adapter.read_state(dxl_id).velocity assert actual == 1.0 * 0.229 * tau / 60.0 # converted to rad/s
def test_given_read_present_pos_int_2048_then_returns_radians_0( self, mock_port_adapter): dxl_id = 4 mock_port_adapter.read = MagicMock(return_value=2048) adapter = DynamixelAdapter(mock_port_adapter) actual = adapter.read_state(dxl_id).position assert actual == 0.0
def test_given_drive_mode_backward__when_write_drive_mode__then_calls_dxl_write_with_1( self): id_num = 11 drive_mode = 'backward' adapter = DynamixelAdapter(None) adapter.write_config = MagicMock() adapter.write_drive_mode(id_num, drive_mode) drive_mode_expected = 1 adapter.write_config.assert_called_with(id_num, 'Drive Mode', drive_mode_expected)
def test_given_angle__when_rad_to_int_range__then_returns_expected( self, angle, expected): actual = DynamixelAdapter.rad_to_int_range(angle) assert actual == expected
def initialized_dxl_adapter(): dxl_adapter = DynamixelAdapter(DynamixelPortAdapter()) dxl_adapter.port_adapter.init_communication() return dxl_adapter
def adapter(): mock_port_adapter = create_autospec(DynamixelPortAdapter) return DynamixelAdapter(mock_port_adapter)
def test_given_too_big_int_value__when_int_range_to_rad__then_raises_value_error( self, int_value): with pytest.raises(ValueError) as cm: actual = DynamixelAdapter.int_range_to_rad(int_value)
def test_given_int__when_int_range_to_rad__then_returns_expected( self, int_value, expected): actual = DynamixelAdapter.int_range_to_rad(int_value) assert actual == expected