Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Get and test all three: argspec, docstring, and custom attrs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Jan 13, 2015
1 parent b0aad0b commit f9bb4df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
22 changes: 12 additions & 10 deletions fmn/lib/hinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
12 changes: 7 additions & 5 deletions fmn/lib/tests/test_hinting.py
Original file line number Diff line number Diff line change
@@ -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']})
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_description():
'fmn.rules',
'docutils',
'markupsafe',
'decorator',
]

if sys.version_info[0] == 2 and sys.version_info[1] <= 6:
Expand Down

0 comments on commit f9bb4df

Please sign in to comment.