diff options
author | Laurent Peuch <cortex@worlddomination.be> | 2020-05-06 14:55:37 +0200 |
---|---|---|
committer | Laurent Peuch <cortex@worlddomination.be> | 2020-05-06 14:55:37 +0200 |
commit | 1ca9be028235dfc29c4ec16e0912d86e5ad00367 (patch) | |
tree | dfe947c36ce80b94369ea5eb53e8a711e1b96c18 /test/test_registry.py | |
parent | 324419e23b73f2269fff4d44e1457d7d3bfbf66d (diff) | |
download | logilab-common-1ca9be028235dfc29c4ec16e0912d86e5ad00367.tar.gz |
black && flake8
Diffstat (limited to 'test/test_registry.py')
-rw-r--r-- | test/test_registry.py | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/test/test_registry.py b/test/test_registry.py index 377ec48..5ba2afe 100644 --- a/test/test_registry.py +++ b/test/test_registry.py @@ -44,10 +44,12 @@ class _1_(Predicate): def __call__(self, *args, **kwargs): return 1 + class _0_(Predicate): def __call__(self, *args, **kwargs): return 0 + def _2_(*args, **kwargs): return 2 @@ -114,7 +116,7 @@ class SelectorsTC(TestCase): self.assertIs(csel.search_selector(_1_), sel) self.assertIs(csel.search_selector((AndPredicate, OrPredicate)), csel) self.assertIs(csel.search_selector((OrPredicate, AndPredicate)), csel) - self.assertIs(csel.search_selector((_1_, _0_)), sel) + self.assertIs(csel.search_selector((_1_, _0_)), sel) self.assertIs(csel.search_selector((_0_, _1_)), sel) def test_inplace_and(self): @@ -157,74 +159,80 @@ class SelectorsTC(TestCase): class _temp_(Predicate): def __call__(self, *args, **kwargs): return 0 - del _temp_ # test weakref + + del _temp_ # test weakref s1 = _1_() & _1_() s2 = _1_() & _0_() s3 = _0_() & _1_() gc.collect() self.count = 0 + def decorate(f, self=self): def wrapper(*args, **kwargs): self.count += 1 return f(*args, **kwargs) + return wrapper + wrap_predicates(decorate) self.assertEqual(s1(None), 2) self.assertEqual(s2(None), 0) self.assertEqual(s3(None), 0) self.assertEqual(self.count, 8) + @contextmanager def prepended_syspath(path): sys.path.insert(0, path) yield sys.path = sys.path[1:] -class RegistryStoreTC(TestCase): +class RegistryStoreTC(TestCase): def test_autoload(self): store = RegistryStore() - store.setdefault('zereg') + store.setdefault("zereg") with prepended_syspath(self.datadir): with warnings.catch_warnings(record=True) as warns: - store.register_objects([self.datapath('regobjects.py'), - self.datapath('regobjects2.py')]) - self.assertEqual(['zereg'], list(store.keys())) - self.assertEqual(set(('appobject1', 'appobject2', 'appobject3')), - set(store['zereg'])) + store.register_objects( + [self.datapath("regobjects.py"), self.datapath("regobjects2.py")] + ) self.assertIn( "[logilab.common.registry] use register_modnames() instead", [str(w.message) for w in warns], ) + self.assertEqual(["zereg"], list(store.keys())) + self.assertEqual(set(("appobject1", "appobject2", "appobject3")), set(store["zereg"])) def test_autoload_modnames(self): store = RegistryStore() - store.setdefault('zereg') + store.setdefault("zereg") with prepended_syspath(self.datadir): - store.register_modnames(['regobjects', 'regobjects2']) - self.assertEqual(['zereg'], list(store.keys())) - self.assertEqual(set(('appobject1', 'appobject2', 'appobject3')), - set(store['zereg'])) + store.register_modnames(["regobjects", "regobjects2"]) + self.assertEqual(["zereg"], list(store.keys())) + self.assertEqual(set(("appobject1", "appobject2", "appobject3")), set(store["zereg"])) class RegistrableInstanceTC(TestCase): - def test_instance_modulename(self): with warnings.catch_warnings(record=True) as warns: obj = RegistrableInstance() - self.assertEqual(obj.__module__, 'test_registry') - self.assertIn('instantiate RegistrableInstance with __module__=__name__', - [str(w.message) for w in warns]) + self.assertEqual(obj.__module__, "test_registry") + self.assertIn( + "instantiate RegistrableInstance with __module__=__name__", + [str(w.message) for w in warns], + ) # no inheritance obj = RegistrableInstance(__module__=__name__) - self.assertEqual(obj.__module__, 'test_registry') + self.assertEqual(obj.__module__, "test_registry") # with inheritance from another python file with prepended_syspath(self.datadir): from regobjects2 import instance, MyRegistrableInstance + instance2 = MyRegistrableInstance(__module__=__name__) - self.assertEqual(instance.__module__, 'regobjects2') - self.assertEqual(instance2.__module__, 'test_registry') + self.assertEqual(instance.__module__, "regobjects2") + self.assertEqual(instance2.__module__, "test_registry") -if __name__ == '__main__': +if __name__ == "__main__": unittest_main() |