| 363 | |
| 364 | |
| 365 | class PythonTests(AbstractTests): |
| 366 | |
| 367 | def __init__(self, tcp_port: int, serial_port: str | None = None, **kwargs: dict[str, Any]) -> None: |
| 368 | super().__init__(**kwargs) |
| 369 | |
| 370 | self.tcp_port = tcp_port |
| 371 | self.serial_port = serial_port |
| 372 | |
| 373 | def init_tests(self) -> bool: |
| 374 | return True |
| 375 | |
| 376 | def test_case_client_exist(self, test_case: str) -> bool: |
| 377 | return self.pytest_test_path(test_case).exists() |
| 378 | |
| 379 | def test_case_server_exist(self, test_case: str) -> bool: |
| 380 | return self.pytest_test_path(test_case).exists() |
| 381 | |
| 382 | def client(self) -> None: |
| 383 | result_file = self.get_result_file() |
| 384 | |
| 385 | pytest_command = [ |
| 386 | "pytest", str(self.pytest_test_path(self.test_case)), |
| 387 | f"--junitxml={result_file}", |
| 388 | "--client", |
| 389 | *self.client_extra_parameters |
| 390 | ] |
| 391 | |
| 392 | if self.transport == "tcp": |
| 393 | pytest_command.extend(["--port", str(self.tcp_port)]) |
| 394 | elif self.transport == "serial" and self.serial_port: |
| 395 | pytest_command.extend(["--serial", self.serial_port]) |
| 396 | else: |
| 397 | raise ValueError |
| 398 | |
| 399 | self.client_process = Popen(pytest_command) |
| 400 | |
| 401 | def server(self) -> None: |
| 402 | pytest_command = [ |
| 403 | "pytest", str(self.pytest_test_path(self.test_case)), |
| 404 | "--server", |
| 405 | *self.server_extra_parameters |
| 406 | ] |
| 407 | |
| 408 | if self.transport == "tcp": |
| 409 | pytest_command.extend(["--port", str(self.tcp_port)]) |
| 410 | elif self.transport == "serial" and self.serial_port: |
| 411 | pytest_command.extend(["--serial", self.serial_port]) |
| 412 | else: |
| 413 | raise ValueError |
| 414 | |
| 415 | self.server_process = Popen(pytest_command) |
| 416 | sleep(0.5) |
| 417 | |
| 418 | def pytest_test_path(self, test_case: str) -> Path: |
| 419 | return self.test_dir.joinpath("python_impl_tests").joinpath(test_case) |
| 420 | |
| 421 | def generate_shim_code(self): |
| 422 | for case in self.test_cases: |