"...git@developer.sourcefind.cn:OpenDAS/megatron-lm.git" did not exist on "688448db7547be90203440cfd105703d8a853f39"
Unverified Commit 2ea0d518 authored by Joanna's avatar Joanna Committed by GitHub
Browse files

add contains to registry (#223)



* add contains to registry
Signed-off-by: default avatarlixuanyi <lixuanyi@sensetime.com>

* add contains to registry

* 'fix'

* 'minor'

* move
Signed-off-by: default avatarlixuanyi <lixuanyi@sensetime.com>
Co-authored-by: default avatarlixuanyi <lixuanyi@sensetime.com>
parent e87a04e3
...@@ -18,6 +18,9 @@ class Registry(object): ...@@ -18,6 +18,9 @@ class Registry(object):
def __len__(self): def __len__(self):
return len(self._module_dict) return len(self._module_dict)
def __contains__(self, key):
return self.get(key) is not None
def __repr__(self): def __repr__(self):
format_str = self.__class__.__name__ + '(name={}, items={})'.format( format_str = self.__class__.__name__ + '(name={}, items={})'.format(
self._name, list(self._module_dict.keys())) self._name, list(self._module_dict.keys()))
......
...@@ -23,6 +23,7 @@ def test_registry(): ...@@ -23,6 +23,7 @@ def test_registry():
CATS.register_module(Munchkin) CATS.register_module(Munchkin)
assert len(CATS) == 2 assert len(CATS) == 2
assert CATS.get('Munchkin') is Munchkin assert CATS.get('Munchkin') is Munchkin
assert 'Munchkin' in CATS
with pytest.raises(KeyError): with pytest.raises(KeyError):
CATS.register_module(Munchkin) CATS.register_module(Munchkin)
...@@ -43,6 +44,7 @@ def test_registry(): ...@@ -43,6 +44,7 @@ def test_registry():
assert len(CATS) == 2 assert len(CATS) == 2
assert CATS.get('PersianCat') is None assert CATS.get('PersianCat') is None
assert 'PersianCat' not in CATS
# The order of dict keys are not preserved in python 3.5 # The order of dict keys are not preserved in python 3.5
assert repr(CATS) in [ assert repr(CATS) in [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment