Skip to content

Commit

Permalink
fix: tests for registry
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskrt committed Jun 11, 2024
1 parent 340284d commit 241fbf8
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions src/gt4sd/algorithms/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ def test_list_available_local_via_S3SyncError(mock_wrong_s3_env):
def test_inherited_validation():
Config = next(iter(ApplicationsRegistry.applications.values())).configuration_class
with pytest.raises(
ValidationError, match="algorithm_version\n +none is not an allowed value"
ValidationError, match="should be a valid string"
):
Config(algorithm_version=None) # type: ignore

# NOTE: values convertible to string will not raise!
Config(algorithm_version=5) # type: ignore
with pytest.raises(
ValidationError, match="should be a valid string"
):
Config(algorithm_version=5) # type: ignore


def test_validation():
with pytest.raises(
ValidationError, match="batch_size\n +value is not a valid integer"
ValidationError, match="should be a valid integer"
):
ApplicationsRegistry.get_configuration_instance(
algorithm_type="conditional_generation",
Expand All @@ -80,25 +82,6 @@ def test_validation():
)


def test_pickable_wrapped_configurations():
# https://github.com/samuelcolvin/pydantic/issues/2111
Config = next(iter(ApplicationsRegistry.applications.values())).configuration_class
restored_obj = assert_pickable(Config(algorithm_version="test"))

# wrong type assignment, but we did not configure it to raise here:
restored_obj.algorithm_version = object
# ensure the restored dataclass is still a pydantic dataclass (mimic validation)
_, optional_errors = restored_obj.__pydantic_model__.__fields__.get(
"algorithm_version"
).validate(
restored_obj.algorithm_version,
restored_obj.__dict__,
loc="algorithm_version",
cls=restored_obj.__class__,
)
assert optional_errors is not None


def test_multiple_registration():
class OtherAlgorithm(GeneratorAlgorithm):
pass
Expand Down

0 comments on commit 241fbf8

Please sign in to comment.