# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1285776266 -7200 # Node ID cfc7df19e4dc9b1b3d340052f9fee5a54275a859 # Parent db56e65906f4e3f49ac50c969071acb0bdcb14e0 test_util: add requiresoption decorator function. diff --git a/tests/test_util.py b/tests/test_util.py --- a/tests/test_util.py +++ b/tests/test_util.py @@ -15,6 +15,7 @@ import urllib _rootdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, _rootdir) +from mercurial import cmdutil from mercurial import commands from mercurial import context from mercurial import dispatch @@ -87,6 +88,21 @@ subdir = {'truncatedhistory.svndump': '/ FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fixtures') +def requiresoption(option): + ''' + Decorator for test functions which require clone to accept the given option. + If the option isn't available, the test is skipped. + + Takes one argument: the required option. + ''' + def decorator(fn): + for entry in cmdutil.findcmd('clone', commands.table)[1][1]: + if entry[1] == option: + return fn + if not isinstance(option, str): + raise TypeError('requiresoption takes a string argument') + return decorator + def filtermanifest(manifest): return filter(lambda x: x not in ('.hgtags', '.hgsvnexternals', ), manifest)