Skip to content

Commit

Permalink
Merge pull request #49 from lrowe/rebase-42
Browse files Browse the repository at this point in the history
Rebase of #42 (fix for #40)
  • Loading branch information
tseaver committed Feb 24, 2016
2 parents 7aefe47 + 4b8b880 commit 003e8ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,10 @@
1.1 (unreleased)
----------------

- Fix bug where using the same venusian decorator on both a class and its
methods would cause the method decorations to be ignored. See
https://github.com/Pylons/venusian/issues/40

- Deprecate support for Python 2.6: it will be removed in the 1.2
release.

Expand Down
2 changes: 1 addition & 1 deletion venusian/__init__.py
Expand Up @@ -316,7 +316,7 @@ def attach(wrapped, callback, category=None, depth=1, name=None):
else:
categories = getattr(wrapped, ATTACH_ATTR, None)
if categories is None or not categories.attached_to(
module_name, class_name, wrapped
module_name, wrapped_name, wrapped
):
# if there aren't any attached categories, or we've retrieved
# some by inheritance, we need to create new ones
Expand Down
9 changes: 9 additions & 0 deletions venusian/tests/fixtures/class_and_method.py
@@ -0,0 +1,9 @@
from venusian.tests.fixtures import decorator


@decorator(class_=True)
class ClassWithMethod(object):

@decorator(method=True)
def method_on_class(self): # pragma: no cover
pass
15 changes: 15 additions & 0 deletions venusian/tests/test_venusian.py
Expand Up @@ -251,6 +251,21 @@ def test_classdecorator(self):
classdecorator.SuperClass)
self.assertEqual(test.registrations[1]['superclass'], True)

def test_class_and_method_decorator(self):
from venusian.tests.fixtures import class_and_method
test = Test()
scanner = self._makeOne(test=test)
scanner.scan(class_and_method)
self.assertEqual(len(test.registrations), 2)
self.assertEqual(test.registrations[0]['name'], 'ClassWithMethod')
self.assertEqual(test.registrations[0]['ob'],
class_and_method.ClassWithMethod)
self.assertEqual(test.registrations[0]['method'], True)
self.assertEqual(test.registrations[1]['name'], 'ClassWithMethod')
self.assertEqual(test.registrations[1]['ob'],
class_and_method.ClassWithMethod)
self.assertEqual(test.registrations[1]['class_'], True)

def test_scan_only_finds_classdecoration_once(self):
from venusian.tests.fixtures import two
from venusian.tests.fixtures.two.mod1 import Class
Expand Down

0 comments on commit 003e8ca

Please sign in to comment.