diff --git a/fmn/lib/hinting.py b/fmn/lib/hinting.py index cbd12b2..23babca 100644 --- a/fmn/lib/hinting.py +++ b/fmn/lib/hinting.py @@ -15,24 +15,26 @@ """ import collections -import functools +import decorator import fedmsg.config def hint(invertible=True, **hints): """ A decorator that can optionally hang datanommer hints on a rule. """ - def wrapper(fn): - @functools.wraps(fn) - def replacement(*args, **kwargs): - return fn(*args, **kwargs) - # Hang hints on the function. - replacement.hints = hints - replacement.hinting_invertible = invertible - return replacement + @decorator.decorator + def wrapper(fn, *args, **kwargs): + return fn(*args, **kwargs) - return wrapper + def wrapper_wrapper(fn): + wrapped = wrapper(fn) + # Hang hints on the wrapped function. + wrapped.hints = hints + wrapped.hinting_invertible = invertible + return wrapped + + return wrapper_wrapper def prefixed(topic, prefix='org.fedoraproject'): diff --git a/fmn/lib/tests/test_hinting.py b/fmn/lib/tests/test_hinting.py index be8c780..e13f6eb 100644 --- a/fmn/lib/tests/test_hinting.py +++ b/fmn/lib/tests/test_hinting.py @@ -1,13 +1,15 @@ -from nose.tools import eq_, assert_not_equals +from nose.tools import eq_ import fmn.lib.tests -class TestDefaults(fmn.lib.tests.Base): +class TestHintDecoration(fmn.lib.tests.Base): def test_hint_decoration(self): rules = self.valid_paths['fmn.lib.tests.example_rules'] rule = rules['hint_masked_rule'] - import pprint; - pprint.pprint(rule) + eq_(rule['title'], u'This is a docstring.') - eq_(len(rule['args']), 1) + + eq_(len(rule['args']), 3) + + eq_(rule['datanommer-hints'], {'categories': ['whatever']}) diff --git a/setup.py b/setup.py index 7f99579..64bd51c 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ def get_description(): 'fmn.rules', 'docutils', 'markupsafe', + 'decorator', ] if sys.version_info[0] == 2 and sys.version_info[1] <= 6: