1
0
Fork 0

Improve test coverage

This commit is contained in:
Maurizio Porrato 2023-08-10 09:16:10 +01:00
parent 3959781b20
commit 69d15c66d5
3 changed files with 15 additions and 1 deletions

View File

@ -542,5 +542,12 @@ class Repo:
def __iter__(self) -> Iterator[Operator]:
yield from self.all_operators()
def __eq__(self, other: object) -> bool:
if not isinstance(other, self.__class__):
raise NotImplementedError(
f"Can't compare {self.__class__.__name__} to {other.__class__.__name__}"
)
return self._repo_path == other._repo_path
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self._repo_path})"

View File

@ -58,6 +58,8 @@ def test_bundle_non_semver(tmp_path: Path) -> None:
bundle_99 = operator.bundle("0.0.99.0")
bundle_100 = operator.bundle("0.0.100.0")
assert bundle_99 > bundle_100
assert operator.channels == {"beta"}
assert operator.default_channel == "beta"
def test_bundle_invalid(tmp_path: Path) -> None:
@ -108,6 +110,8 @@ def test_bundle_invalid(tmp_path: Path) -> None:
with pytest.raises(InvalidBundleException, match="Invalid .* contents"):
_ = repo.operator("invalid_metadata_contents").bundle("0.0.1").annotations
assert repo.operator("empty_metadata").bundle("0.0.1").annotations == {}
assert repo.operator("empty_metadata").channels == set()
assert repo.operator("empty_metadata").default_channel is None
assert repo.has("missing_csv")
with pytest.raises(InvalidBundleException, match="CSV file for .* not found"):
_ = repo.operator("missing_csv").bundle("0.0.1").csv_operator_name

View File

@ -1,6 +1,7 @@
from pathlib import Path
from operator_repo import Repo
from operator_repo import Operator, Repo
from tests import bundle_files, create_files
@ -14,6 +15,8 @@ def test_operator_one_bundle(tmp_path: Path) -> None:
create_files(tmp_path, bundle_files("hello", "0.0.1"))
repo = Repo(tmp_path)
operator = repo.operator("hello")
assert operator.repo == repo
assert Operator(operator.root).repo == repo
bundle = operator.bundle("0.0.1")
assert len(list(operator)) == 1
assert set(operator) == {bundle}