|
37 | 37 | class TestPlatformHandler: |
38 | 38 | """Tests for the PlatformHandler class.""" |
39 | 39 |
|
| 40 | + @pytest.fixture |
| 41 | + def console(self, mocker: MockerFixture) -> Console: |
| 42 | + """Console instance for testing.""" |
| 43 | + |
| 44 | + def exception_to_string(exception: Exception) -> str: |
| 45 | + return str(exception) |
| 46 | + |
| 47 | + # Create mock. |
| 48 | + mocked_console = mocker.Mock(spec=Console) |
| 49 | + |
| 50 | + # Patch internally used functions. |
| 51 | + _ = mocker.patch.object(mocked_console, "pretty_exception", side_effect=exception_to_string) |
| 52 | + |
| 53 | + # Return mocked console. |
| 54 | + return mocked_console |
| 55 | + |
| 56 | + @pytest.fixture |
| 57 | + def binding(self, mocker: MockerFixture) -> BaseBinding: |
| 58 | + """FakeBinding instance for testing.""" |
| 59 | + |
| 60 | + def reflect_vector4(input_vector: Vector4) -> Vector4: |
| 61 | + return input_vector |
| 62 | + |
| 63 | + # Create mock. |
| 64 | + mocked_binding = mocker.Mock(spec=BaseBinding) |
| 65 | + |
| 66 | + # Patch internally used functions. |
| 67 | + _ = mocker.patch.object(mocked_binding, "platform_space_to_unified_space", side_effect=reflect_vector4) |
| 68 | + _ = mocker.patch.object(mocked_binding, "unified_space_to_platform_space", side_effect=reflect_vector4) |
| 69 | + |
| 70 | + # Return mocked binding. |
| 71 | + return mocked_binding |
| 72 | + |
40 | 73 | @pytest.fixture |
41 | 74 | def platform_handler(self, binding: BaseBinding, console: Console) -> PlatformHandler: |
42 | 75 | """Fixture for creating a PlatformHandler instance.""" |
@@ -546,7 +579,7 @@ async def test_emergency_stop( |
546 | 579 | """Platform should call stop_all and print to critical console.""" |
547 | 580 | # Mock binding. |
548 | 581 | patched_stop_all = mocker.patch.object( |
549 | | - PlatformHandler, |
| 582 | + platform_handler, |
550 | 583 | "stop_all", |
551 | 584 | ) |
552 | 585 | spied_critical_print = mocker.spy(console, "critical_print") |
|
0 commit comments