Skip to content

Commit

Permalink
add test for SingleSingletonStore
Browse files Browse the repository at this point in the history
  • Loading branch information
rababerladuseladim committed Jul 12, 2024
1 parent 54c68c9 commit 028619a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mex/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def load(self, cls: type[_SingletonT]) -> _SingletonT:
return self._singleton
if not issubclass(type(self._singleton), cls):
raise TypeError(
f"requested class ({cls}) is not not a parent class of loaded class "
f"requested class ({cls}) is not a parent class of loaded class "
f"({type(self._singleton)}). "
f"Did you initialize {cls} upon startup?"
)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from mex.common.context import SingleSingletonStore


class Parent:
pass


class Child(Parent):
pass


def test_single_singleton_store() -> None:
store = SingleSingletonStore["Parent"]()
parent = store.load(Parent)

with pytest.raises(TypeError, match="is not a parent class of loaded class"):
store.load(Child)

assert parent is store.load(Parent)

store.push(Child())

child = store.load(Child)

assert child is store.load(Parent)

store.reset()

assert store._singleton is None

0 comments on commit 028619a

Please sign in to comment.