From dc0e93fb3fb50b5eb5edd3c4a838d8fab9cbc3d1 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Mon, 25 Mar 2024 21:11:05 +0100 Subject: [PATCH] test: correct implementation of the `get_matrix_id` mock --- tests/variantstudy/conftest.py | 6 +++++- tests/variantstudy/test_command_factory.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/variantstudy/conftest.py b/tests/variantstudy/conftest.py index 1bcbb13cb1..b08851b07b 100644 --- a/tests/variantstudy/conftest.py +++ b/tests/variantstudy/conftest.py @@ -81,7 +81,11 @@ def get_matrix_id(matrix: t.Union[t.List[t.List[float]], str]) -> str: Get the matrix ID from a matrix or a matrix link. """ if isinstance(matrix, str): - return matrix.lstrip("matrix://") + # str.removeprefix() is not available in Python 3.8 + prefix = "matrix://" + if matrix.startswith(prefix): + return matrix[len(prefix) :] + return matrix elif isinstance(matrix, list): return create(matrix) else: diff --git a/tests/variantstudy/test_command_factory.py b/tests/variantstudy/test_command_factory.py index 64ec3b799f..a0324a2722 100644 --- a/tests/variantstudy/test_command_factory.py +++ b/tests/variantstudy/test_command_factory.py @@ -403,7 +403,11 @@ def setup_class(self): @pytest.mark.unit_test def test_command_factory(self, command_dto: CommandDTO): def get_matrix_id(matrix: str) -> str: - return matrix.lstrip("matrix://") + # str.removeprefix() is not available in Python 3.8 + prefix = "matrix://" + if matrix.startswith(prefix): + return matrix[len(prefix) :] + return matrix command_factory = CommandFactory( generator_matrix_constants=Mock(spec=GeneratorMatrixConstants),