Skip to content

Commit

Permalink
simplify small parts of code with new python api
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Oct 1, 2024
1 parent 133635d commit 7e67b01
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
6 changes: 1 addition & 5 deletions antarest/matrixstore/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ def get_matrix_id(self, matrix: t.Union[t.List[t.List[float]], str]) -> str:
"""
# noinspection SpellCheckingInspection
if isinstance(matrix, str):
# str.removeprefix() is not available in Python 3.8
prefix = "matrix://"
if matrix.startswith(prefix):
return matrix[len(prefix) :]
return matrix
return matrix.removeprefix("matrix://")
elif isinstance(matrix, list):
return self.create(matrix)
else:
Expand Down
7 changes: 1 addition & 6 deletions tests/study/storage/test_abstract_storage_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ def __init__(self, tmp_path: Path):

def __eq__(self, other: Path):
if isinstance(other, Path) and other.name == "tmp_copy":
# `is_relative_to` is not available for Python < 3.9
try:
other.relative_to(self.tmp_path)
return True
except ValueError:
return False
return other.is_relative_to(self.tmp_path)

def __ne__(self, other):
return not self.__eq__(other)
Expand Down
6 changes: 1 addition & 5 deletions tests/variantstudy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ 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):
# str.removeprefix() is not available in Python 3.8
prefix = "matrix://"
if matrix.startswith(prefix):
return matrix[len(prefix) :]
return matrix
return matrix.removeprefix("matrix://")
elif isinstance(matrix, list):
return create(matrix)
else:
Expand Down
6 changes: 1 addition & 5 deletions tests/variantstudy/test_command_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,7 @@
@pytest.fixture
def command_factory() -> CommandFactory:
def get_matrix_id(matrix: str) -> str:
# str.removeprefix() is not available in Python 3.8
prefix = "matrix://"
if matrix.startswith(prefix):
return matrix[len(prefix) :]
return matrix
return matrix.removeprefix("matrix://")

return CommandFactory(
generator_matrix_constants=Mock(spec=GeneratorMatrixConstants),
Expand Down

0 comments on commit 7e67b01

Please sign in to comment.