diff options
author | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2017-01-20 16:02:24 +0100 |
---|---|---|
committer | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2017-01-20 16:02:24 +0100 |
commit | 846950d49aca16fb3d848bf7e5851985377a3f73 (patch) | |
tree | a957a71de4bb9077e0913b617d5313178a3f337f /test | |
parent | 742fe7dda53fc4fbe5ccf8e1827ab6bbe5af95f0 (diff) | |
download | logilab-common-846950d49aca16fb3d848bf7e5851985377a3f73.tar.gz |
[registry] RegistrableInstance should be instantiated with __module__=__name__
To detect in whih module the instance was created we previously detect the
filename in python stack and then use modpath_from_file(). Since the later is
now deprecated, we should force passing the module at instantiation with
__module__=__name__.
Deprecate old usage
Diffstat (limited to 'test')
-rw-r--r-- | test/data/regobjects2.py | 2 | ||||
-rw-r--r-- | test/unittest_registry.py | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/test/data/regobjects2.py b/test/data/regobjects2.py index 5c28b51..091b9f7 100644 --- a/test/data/regobjects2.py +++ b/test/data/regobjects2.py @@ -5,4 +5,4 @@ class MyRegistrableInstance(RegistrableInstance): __select__ = yes() __registry__ = 'zereg' -instance = MyRegistrableInstance() +instance = MyRegistrableInstance(__module__=__name__) diff --git a/test/unittest_registry.py b/test/unittest_registry.py index 8c5c791..1c07e4c 100644 --- a/test/unittest_registry.py +++ b/test/unittest_registry.py @@ -200,13 +200,18 @@ class RegistryStoreTC(TestCase): class RegistrableInstanceTC(TestCase): def test_instance_modulename(self): + with warnings.catch_warnings(record=True) as warns: + obj = RegistrableInstance() + self.assertEqual(obj.__module__, 'unittest_registry') + self.assertIn('instantiate RegistrableInstance with __module__=__name__', + [str(w.message) for w in warns]) # no inheritance - obj = RegistrableInstance() + obj = RegistrableInstance(__module__=__name__) self.assertEqual(obj.__module__, 'unittest_registry') # with inheritance from another python file with prepended_syspath(self.datadir): from regobjects2 import instance, MyRegistrableInstance - instance2 = MyRegistrableInstance() + instance2 = MyRegistrableInstance(__module__=__name__) self.assertEqual(instance.__module__, 'regobjects2') self.assertEqual(instance2.__module__, 'unittest_registry') |