comparison tests/test_util.py @ 716:38ebf7714cdf

requiresoption: raise SkipTest if available This has the unfortunate (I guess?) side effect that you can no longer use pure unittest to run skipped tests if nose or unittest2 is installed.
author Augie Fackler <durin42@gmail.com>
date Sat, 02 Oct 2010 16:44:37 -0500
parents c33293a34752
children ae5968ffe6fe
comparison
equal deleted inserted replaced
715:c33293a34752 716:38ebf7714cdf
23 from mercurial import i18n 23 from mercurial import i18n
24 from mercurial import node 24 from mercurial import node
25 from mercurial import ui 25 from mercurial import ui
26 from mercurial import extensions 26 from mercurial import extensions
27 27
28 try:
29 from unittest2 import SkipTest
30 except ImportError:
31 try:
32 from nose import SkipTest
33 except ImportError:
34 SkipTest = None
35
28 from hgsubversion import util 36 from hgsubversion import util
29 37
30 # Documentation for Subprocess.Popen() says: 38 # Documentation for Subprocess.Popen() says:
31 # "Note that on Windows, you cannot set close_fds to true and 39 # "Note that on Windows, you cannot set close_fds to true and
32 # also redirect the standard handles by setting stdin, stdout or 40 # also redirect the standard handles by setting stdin, stdout or
92 '''Skip a test if commands.clone does not take the specified option.''' 100 '''Skip a test if commands.clone does not take the specified option.'''
93 def decorator(fn): 101 def decorator(fn):
94 for entry in cmdutil.findcmd('clone', commands.table)[1][1]: 102 for entry in cmdutil.findcmd('clone', commands.table)[1][1]:
95 if entry[1] == option: 103 if entry[1] == option:
96 return fn 104 return fn
105 # no match found, so skip
106 if SkipTest:
107 def skip(*args, **kwargs):
108 raise SkipTest('test requires clone to accept %s' % option)
109 skip.__name__ = fn.__name__
110 return skip
111 # no skipping support, so erase decorated method
112 return
97 if not isinstance(option, str): 113 if not isinstance(option, str):
98 raise TypeError('requiresoption takes a string argument') 114 raise TypeError('requiresoption takes a string argument')
99 return decorator 115 return decorator
100 116
101 def filtermanifest(manifest): 117 def filtermanifest(manifest):