changeset 711:cfc7df19e4dc

test_util: add requiresoption decorator function.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Wed, 29 Sep 2010 18:04:26 +0200
parents db56e65906f4
children 1041fb1bec8c
files tests/test_util.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)