comparison tests/test_util.py @ 719:ae52a3b30cfb

test_util: refactor requiresoption to ease creation of other skip decorators
author Augie Fackler <durin42@gmail.com>
date Mon, 04 Oct 2010 23:02:15 -0500
parents ae5968ffe6fe
children a19a208c085b
comparison
equal deleted inserted replaced
718:db0eb6237420 719:ae52a3b30cfb
96 } 96 }
97 97
98 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 98 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
99 'fixtures') 99 'fixtures')
100 100
101
102 def _makeskip(name, message):
103 def skip(*args, **kwargs):
104 raise SkipTest(message)
105 skip.__name__ = name
106 return skip
107
108
101 def requiresoption(option): 109 def requiresoption(option):
102 '''Skip a test if commands.clone does not take the specified option.''' 110 '''Skip a test if commands.clone does not take the specified option.'''
103 def decorator(fn): 111 def decorator(fn):
104 for entry in cmdutil.findcmd('clone', commands.table)[1][1]: 112 for entry in cmdutil.findcmd('clone', commands.table)[1][1]:
105 if entry[1] == option: 113 if entry[1] == option:
106 return fn 114 return fn
107 # no match found, so skip 115 # no match found, so skip
108 if SkipTest: 116 if SkipTest:
109 def skip(*args, **kwargs): 117 return _makeskip(fn.__name__,
110 raise SkipTest('test requires clone to accept %s' % option) 118 'test requires clone to accept %s' % option)
111 skip.__name__ = fn.__name__
112 return skip
113 # no skipping support, so erase decorated method 119 # no skipping support, so erase decorated method
114 return 120 return
115 if not isinstance(option, str): 121 if not isinstance(option, str):
116 raise TypeError('requiresoption takes a string argument') 122 raise TypeError('requiresoption takes a string argument')
117 return decorator 123 return decorator