summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-07-07 12:57:26 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-07-07 12:57:26 +0200
commitd5038ebadc190753c67c02c9f5930a14ca2dc1e7 (patch)
tree98ff9d0703f1404540d00c68bbf4cc468208b131
parent80aa40537a3596f24593b5a67adb6d635fe4fa22 (diff)
downloadgitpython-d5038ebadc190753c67c02c9f5930a14ca2dc1e7.tar.gz
removed now superfluous InstanceDecorator, as it was just complicating things after all
-rw-r--r--git/test/lib/helper.py58
1 files changed, 17 insertions, 41 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 87600489..2045f9d3 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -22,8 +22,7 @@ from base import (
__all__ = (
- 'StringProcessAdapter', 'GlobalsItemDeletorMetaCls', 'InheritedTestMethodsOverrideWrapperInstanceDecorator',
- 'InheritedTestMethodsOverrideWrapperMetaClsAutoMixin',
+ 'StringProcessAdapter', 'GlobalsItemDeletorMetaCls', 'InheritedTestMethodsOverrideWrapperMetaClsAutoMixin',
'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'needs_module_or_skip'
)
@@ -239,44 +238,7 @@ class GlobalsItemDeletorMetaCls(type):
#END skip case that people import our base without actually using it
#END handle deletion
return new_type
-
-
-class InheritedTestMethodsOverrideWrapperInstanceDecorator(object):
- """Utility to wrap all inherited methods into a given decorator and set up new
- overridden methods on our actual type. This allows to adjust tests which are inherited
- by our parent type, automatically. The decorator set in a derived type should
- do what it has to do, possibly skipping the test if some prerequesites are not met.
-
- To use it, instatiate it and use it as a wrapper for the __new__ function of your metacls, as in
-
- __new__ = @InheritedTestMethodsOverrideWrapperInstanceDecorator(mydecorator)(MyMetaclsBase.__new__)"""
-
- def __init__(self, decorator):
- self.decorator = decorator
-
- def _patch_methods_recursive(self, bases, clsdict):
- """depth-first patching of methods"""
- for base in bases:
- self._patch_methods_recursive(base.__bases__, clsdict)
- for name, item in base.__dict__.iteritems():
- if not name.startswith('test_'):
- continue
- #END skip non-tests
- clsdict[name] = self.decorator(item)
- #END for each item
- #END for each base
-
- def __call__(self, func):
- def wrapper(metacls, name, bases, clsdict):
- self._patch_methods_recursive(bases, clsdict)
- return func(metacls, name, bases, clsdict)
- #END wrapper
- assert func.__name__ == '__new__', "Can only wrap __new__ function of metaclasses"
- wrapper.__name__ = func.__name__
- return wrapper
-
-
class InheritedTestMethodsOverrideWrapperMetaClsAutoMixin(object):
"""Automatically picks up the actual metaclass of the the type to be created,
@@ -299,11 +261,25 @@ class InheritedTestMethodsOverrideWrapperMetaClsAutoMixin(object):
return metacls._find_metacls(base.__bases__)
#END for each base
raise AssertionError("base class had not metaclass attached")
-
+
+ @classmethod
+ def _patch_methods_recursive(metacls, bases, clsdict):
+ """depth-first patching of methods"""
+ for base in bases:
+ metacls._patch_methods_recursive(base.__bases__, clsdict)
+ for name, item in base.__dict__.iteritems():
+ if not name.startswith('test_'):
+ continue
+ #END skip non-tests
+ clsdict[name] = metacls.decorator[0](item)
+ #END for each item
+ #END for each base
+
def __new__(metacls, name, bases, clsdict):
assert metacls.decorator, "'decorator' member needs to be set in subclass"
base_metacls = metacls._find_metacls(bases)
- return InheritedTestMethodsOverrideWrapperInstanceDecorator(metacls.decorator[0])(base_metacls.__new__)(base_metacls, name, bases, clsdict)
+ metacls._patch_methods_recursive(bases, clsdict)
+ return base_metacls.__new__(base_metacls, name, bases, clsdict)
#} END meta classes