Skip to content

Commit

Permalink
Return item from registry adders. Add basic tests for registries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Nov 13, 2024
1 parent 1e64246 commit bc668f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions glue_ar/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def add(self, extensions: Union[str, Tuple[str]], builder: Type):
def __call__(self, extensions: Union[str, Tuple[str]]):
def adder(builder: Type):
self.add(extensions, builder)
return builder
return adder


Expand All @@ -33,6 +34,7 @@ def add(self, name: str, compressor: Callable[[str], None]):
def __call__(self, name: str):
def adder(compressor: Callable[[str], None]):
self.add(name, compressor)
return compressor
return adder


Expand Down
Empty file added glue_ar/tests/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions glue_ar/tests/test_registries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from ..registries import BuilderRegistry, CompressorRegistry


def test_builder_registry():

builder_registry = BuilderRegistry()

@builder_registry("ext")
class ExtBuilder:
pass

@builder_registry(("ext1", "ext2"))
class ExtsBuilder:
pass

assert builder_registry.members == {"ext": ExtBuilder,
"ext1": ExtsBuilder,
"ext2": ExtsBuilder}


def test_compressor_registry():

compressor_registry = CompressorRegistry()

@compressor_registry("dummy")
def dummy_compressor(_filepath: str):
pass

Check warning on line 27 in glue_ar/tests/test_registries.py

View check run for this annotation

Codecov / codecov/patch

glue_ar/tests/test_registries.py#L27

Added line #L27 was not covered by tests

assert compressor_registry.members == {"dummy": dummy_compressor}

0 comments on commit bc668f8

Please sign in to comment.