Skip to content

Commit

Permalink
don't allow arbitrary keyword config
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Oct 3, 2023
1 parent ae7c6b4 commit ac3705d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions autoregistry/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def update(self, new: dict) -> None:
for key, value in new.items():
if hasattr(self, key):
setattr(self, key, value)
else:
raise TypeError(f"Unexpected configuration value {key}={value}")

def getitem(self, registry: dict, key: str):
"""Key/Value lookup with keysplitting and optional case-insensitivity."""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_classes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
from autoregistry import InvalidNameError, Registry


def test_typo():
# Make sure we catch invalid parameters
with pytest.raises(TypeError):

class Sensor(Registry, asdklfjlk=123):
pass


def test_case_sensitive():
Pokemon, Charmander, Pikachu, SurfingPikachu = construct_pokemon_classes(
case_sensitive=True,
Expand Down
12 changes: 11 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ def test_registry_config_update():
config.update(
{
"suffix": "test",
"not_valid_config_key": None, # This should be ignored.
}
)

assert config.suffix == "test"


def test_registry_config_update_invalid_key():
config = RegistryConfig()
with pytest.raises(TypeError):
config.update(
{
"suffix": "test",
"not_valid_config_key": None, # This should be ignored.
}
)


def test_registry_config_cannot_derive_name():
__registry__ = _Registry(RegistryConfig())
foo = "foo"
Expand Down

0 comments on commit ac3705d

Please sign in to comment.