summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLaurent Peuch <cortex@worlddomination.be>2020-05-06 14:20:08 +0200
committerLaurent Peuch <cortex@worlddomination.be>2020-05-06 14:20:08 +0200
commit324419e23b73f2269fff4d44e1457d7d3bfbf66d (patch)
treee0ddff710df5b40726b751bc8dc377454b18995f /test
parent49dc54a7c761ca4acbef6d2104f8a45a1d5a9cb1 (diff)
downloadlogilab-common-324419e23b73f2269fff4d44e1457d7d3bfbf66d.tar.gz
[deprecation/fix] correctly automatically get the module in which deprecation utils are called
There was a missmatched combination of: * the frame wasn't always correctly grabbed * grabbing the frame in the situation of a decorator didn't make any sens, so switch to func.__module__ * the tests were bad and expected "[logilab.common]" while it should have been "[test_deprecation]" because it was there that the depreciation was declared
Diffstat (limited to 'test')
-rw-r--r--test/test_deprecation.py96
-rw-r--r--test/test_modutils.py22
-rw-r--r--test/test_registry.py6
3 files changed, 84 insertions, 40 deletions
diff --git a/test/test_deprecation.py b/test/test_deprecation.py
index 096978e..cac8664 100644
--- a/test/test_deprecation.py
+++ b/test/test_deprecation.py
@@ -48,8 +48,7 @@ class RawInputTC(TestCase):
class AnyClass(object, metaclass=deprecation.class_deprecated):
pass
AnyClass()
- self.assertEqual(self.messages,
- ['[logilab.common] AnyClass is deprecated'])
+ self.assertEqual(self.messages, ["[test_deprecation] AnyClass is deprecated"])
def test_class_renamed(self):
class AnyClass(object):
@@ -58,8 +57,9 @@ class RawInputTC(TestCase):
OldClass = deprecation.class_renamed("OldClass", AnyClass)
OldClass()
- self.assertEqual(self.messages,
- ['[logilab.common] OldClass is deprecated, use AnyClass instead'])
+ self.assertEqual(
+ self.messages, ["[test_deprecation] OldClass is deprecated, use AnyClass instead"]
+ )
def test_class_moved(self):
class AnyClass(object):
@@ -67,36 +67,53 @@ class RawInputTC(TestCase):
OldClass = deprecation.class_moved(new_class=AnyClass, old_name="OldName")
OldClass()
- self.assertEqual(self.messages,
- ['[logilab.common] class OldName is now available as unittest_deprecation.AnyClass'])
+ self.assertEqual(
+ self.messages,
+ ["[test_deprecation] class OldName is now available as test_deprecation.AnyClass"],
+ )
self.messages = []
AnyClass = deprecation.class_moved(new_class=AnyClass)
AnyClass()
- self.assertEqual(self.messages,
- ['[logilab.common] class AnyClass is now available as unittest_deprecation.AnyClass'])
+ self.assertEqual(
+ self.messages,
+ ["[test_deprecation] class AnyClass is now available as test_deprecation.AnyClass"],
+ )
def test_deprecated_func(self):
any_func = deprecation.callable_deprecated()(self.mk_func())
any_func()
- any_func = deprecation.callable_deprecated('message')(self.mk_func())
+ any_func = deprecation.callable_deprecated("message")(self.mk_func())
any_func()
- self.assertEqual(self.messages,
- ['[logilab.common] The function "any_func" is deprecated', '[logilab.common] message'])
+ self.assertEqual(
+ self.messages,
+ [
+ '[test_deprecation] The function "any_func" is deprecated',
+ "[test_deprecation] message",
+ ],
+ )
def test_deprecated_decorator(self):
@deprecation.callable_deprecated()
def any_func():
pass
+
any_func()
- @deprecation.callable_deprecated('message')
+
+ @deprecation.callable_deprecated("message")
def any_func():
pass
+
any_func()
- self.assertEqual(self.messages,
- ['[logilab.common] The function "any_func" is deprecated', '[logilab.common] message'])
+ self.assertEqual(
+ self.messages,
+ [
+ '[test_deprecation] The function "any_func" is deprecated',
+ "[test_deprecation] message",
+ ],
+ )
def test_attribute_renamed(self):
@deprecation.attribute_renamed(old_name="old", new_name="new")
@@ -106,9 +123,13 @@ class RawInputTC(TestCase):
some_class = SomeClass()
self.assertEqual(some_class.old, some_class.new)
- self.assertEqual(self.messages,
- ['[logilab.common] SomeClass.old has been renamed and is deprecated, use SomeClass.new '
- 'instead'])
+ self.assertEqual(
+ self.messages,
+ [
+ "[test_deprecation] SomeClass.old has been renamed and is deprecated, "
+ "use SomeClass.new instead"
+ ],
+ )
some_class.old = 43
self.assertEqual(some_class.old, 43)
@@ -127,9 +148,13 @@ class RawInputTC(TestCase):
self.assertEqual(some_function(new=42), 42)
self.assertEqual(some_function(old=42), 42)
- self.assertEqual(self.messages,
- ['[logilab.common] argument old of callable some_function has been renamed and is '
- 'deprecated, use keyword argument new instead'])
+ self.assertEqual(
+ self.messages,
+ [
+ "[test_deprecation] argument old of callable some_function has been renamed and is "
+ "deprecated, use keyword argument new instead"
+ ],
+ )
with self.assertRaises(ValueError):
some_function(new=42, old=42)
@@ -141,9 +166,13 @@ class RawInputTC(TestCase):
self.assertEqual(some_function(new=42), 42)
self.assertEqual(some_function(new=10, old=20), 10)
- self.assertEqual(self.messages,
- ['[logilab.common] argument old of callable some_function has been removed and is '
- 'deprecated'])
+ self.assertEqual(
+ self.messages,
+ [
+ "[test_deprecation] argument old of callable some_function has been removed and is "
+ "deprecated"
+ ],
+ )
def test_callable_renamed(self):
def any_func():
@@ -152,16 +181,23 @@ class RawInputTC(TestCase):
old_func = deprecation.callable_renamed("old_func", any_func)
old_func()
- self.assertEqual(self.messages,
- ['[logilab.common] old_func has been renamed and is deprecated, uses any_func instead'])
+ self.assertEqual(
+ self.messages,
+ [
+ "[test_deprecation] old_func has been renamed and is deprecated, "
+ "uses any_func instead"
+ ],
+ )
def test_moved(self):
- module = 'data.deprecation'
- any_func = deprecation.callable_moved(module, 'moving_target')
+ module = "data.deprecation"
+ any_func = deprecation.callable_moved(module, "moving_target")
any_func()
- self.assertEqual(self.messages,
- ['[logilab.common] object moving_target has been moved to module data.deprecation'])
+ self.assertEqual(
+ self.messages,
+ ["[test_deprecation] object moving_target has been moved to module data.deprecation"],
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest_main()
diff --git a/test/test_modutils.py b/test/test_modutils.py
index cd639e1..bcffe07 100644
--- a/test/test_modutils.py
+++ b/test/test_modutils.py
@@ -90,12 +90,15 @@ class get_module_part_tc(ModutilsTestCase):
"""given a dotted name return the module part of the name"""
def test_knownValues_get_module_part_1(self):
- self.assertEqual(modutils.get_module_part('logilab.common.modutils'),
- 'logilab.common.modutils')
+ self.assertEqual(
+ modutils.get_module_part("logilab.common.modutils"), "logilab.common.modutils"
+ )
def test_knownValues_get_module_part_2(self):
- self.assertEqual(modutils.get_module_part('logilab.common.modutils.get_module_part'),
- 'logilab.common.modutils')
+ self.assertEqual(
+ modutils.get_module_part("logilab.common.modutils.get_module_part"),
+ "logilab.common.modutils",
+ )
def test_knownValues_get_module_part_3(self):
"""relative import from given file"""
@@ -120,10 +123,13 @@ class modpath_from_file_tc(ModutilsTestCase):
def test_knownValues_modpath_from_file_1(self):
with warnings.catch_warnings(record=True) as warns:
- self.assertEqual(modutils.modpath_from_file(modutils.__file__),
- ['logilab', 'common', 'modutils'])
- self.assertIn('[logilab.common] you should avoid using modpath_from_file()',
- [str(w.message) for w in warns])
+ self.assertEqual(
+ modutils.modpath_from_file(modutils.__file__), ["logilab", "common", "modutils"]
+ )
+ self.assertIn(
+ "[logilab.common.modutils] you should avoid using modpath_from_file()",
+ [str(w.message) for w in warns],
+ )
def test_knownValues_modpath_from_file_2(self):
self.assertEqual(modutils.modpath_from_file('unittest_modutils.py',
diff --git a/test/test_registry.py b/test/test_registry.py
index 148bf77..377ec48 100644
--- a/test/test_registry.py
+++ b/test/test_registry.py
@@ -189,11 +189,13 @@ class RegistryStoreTC(TestCase):
with warnings.catch_warnings(record=True) as warns:
store.register_objects([self.datapath('regobjects.py'),
self.datapath('regobjects2.py')])
- self.assertIn('[logilab.common] 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']))
+ self.assertIn(
+ "[logilab.common.registry] use register_modnames() instead",
+ [str(w.message) for w in warns],
+ )
def test_autoload_modnames(self):
store = RegistryStore()