Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5038eb

Browse files
committed
removed now superfluous InstanceDecorator, as it was just complicating things after all
1 parent80aa405 commitd5038eb

File tree

1 file changed

+17
-41
lines changed

1 file changed

+17
-41
lines changed

‎git/test/lib/helper.py

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323

2424
__all__= (
25-
'StringProcessAdapter','GlobalsItemDeletorMetaCls','InheritedTestMethodsOverrideWrapperInstanceDecorator',
26-
'InheritedTestMethodsOverrideWrapperMetaClsAutoMixin',
25+
'StringProcessAdapter','GlobalsItemDeletorMetaCls','InheritedTestMethodsOverrideWrapperMetaClsAutoMixin',
2726
'with_rw_repo','with_rw_and_rw_remote_repo','TestBase','TestCase','needs_module_or_skip'
2827
)
2928

@@ -239,44 +238,7 @@ def __new__(metacls, name, bases, clsdict):
239238
#END skip case that people import our base without actually using it
240239
#END handle deletion
241240
returnnew_type
242-
243-
244-
classInheritedTestMethodsOverrideWrapperInstanceDecorator(object):
245-
"""Utility to wrap all inherited methods into a given decorator and set up new
246-
overridden methods on our actual type. This allows to adjust tests which are inherited
247-
by our parent type, automatically. The decorator set in a derived type should
248-
do what it has to do, possibly skipping the test if some prerequesites are not met.
249-
250-
To use it, instatiate it and use it as a wrapper for the __new__ function of your metacls, as in
251-
252-
__new__ = @InheritedTestMethodsOverrideWrapperInstanceDecorator(mydecorator)(MyMetaclsBase.__new__)"""
253241

254-
255-
def__init__(self,decorator):
256-
self.decorator=decorator
257-
258-
def_patch_methods_recursive(self,bases,clsdict):
259-
"""depth-first patching of methods"""
260-
forbaseinbases:
261-
self._patch_methods_recursive(base.__bases__,clsdict)
262-
forname,iteminbase.__dict__.iteritems():
263-
ifnotname.startswith('test_'):
264-
continue
265-
#END skip non-tests
266-
clsdict[name]=self.decorator(item)
267-
#END for each item
268-
#END for each base
269-
270-
def__call__(self,func):
271-
defwrapper(metacls,name,bases,clsdict):
272-
self._patch_methods_recursive(bases,clsdict)
273-
returnfunc(metacls,name,bases,clsdict)
274-
#END wrapper
275-
assertfunc.__name__=='__new__',"Can only wrap __new__ function of metaclasses"
276-
wrapper.__name__=func.__name__
277-
returnwrapper
278-
279-
280242

281243
classInheritedTestMethodsOverrideWrapperMetaClsAutoMixin(object):
282244
"""Automatically picks up the actual metaclass of the the type to be created,
@@ -299,11 +261,25 @@ def _find_metacls(metacls, bases):
299261
returnmetacls._find_metacls(base.__bases__)
300262
#END for each base
301263
raiseAssertionError("base class had not metaclass attached")
302-
264+
265+
@classmethod
266+
def_patch_methods_recursive(metacls,bases,clsdict):
267+
"""depth-first patching of methods"""
268+
forbaseinbases:
269+
metacls._patch_methods_recursive(base.__bases__,clsdict)
270+
forname,iteminbase.__dict__.iteritems():
271+
ifnotname.startswith('test_'):
272+
continue
273+
#END skip non-tests
274+
clsdict[name]=metacls.decorator[0](item)
275+
#END for each item
276+
#END for each base
277+
303278
def__new__(metacls,name,bases,clsdict):
304279
assertmetacls.decorator,"'decorator' member needs to be set in subclass"
305280
base_metacls=metacls._find_metacls(bases)
306-
returnInheritedTestMethodsOverrideWrapperInstanceDecorator(metacls.decorator[0])(base_metacls.__new__)(base_metacls,name,bases,clsdict)
281+
metacls._patch_methods_recursive(bases,clsdict)
282+
returnbase_metacls.__new__(base_metacls,name,bases,clsdict)
307283

308284
#} END meta classes
309285

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp