diff options
author | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-10 17:55:52 +0200 |
---|---|---|
committer | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-10 17:55:52 +0200 |
commit | dbc6734cbc23730c7fd3f46f7994d5950d14c1fb (patch) | |
tree | b4e3525e87533cc23c5bf84860310a47f5ce2701 /decorators.py | |
parent | 0d5810a7f643e7a2af88fc07b47f671add2c2a71 (diff) | |
download | logilab-common-dbc6734cbc23730c7fd3f46f7994d5950d14c1fb.tar.gz |
add @require_version('version') that skip a test if the version is too old
Diffstat (limited to 'decorators.py')
-rw-r--r-- | decorators.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/decorators.py b/decorators.py index 2c2834d..7ed4554 100644 --- a/decorators.py +++ b/decorators.py @@ -8,6 +8,7 @@ __docformat__ = "restructuredtext en" from types import MethodType from time import clock +import sys, re # XXX rewrite so we can use the decorator syntax when keyarg has to be specified @@ -143,3 +144,26 @@ def locked(acquire, release): return wrapper return decorator +def require_version(version): + """ Compare version of python interpretor to the given one. Skip the test + if older. + """ + def check_require_version(f): + current = sys.version_info[:3] + version_rgx = re.compile('^(\d+)\.(\d+)\.?(\d+)?$') # version = X.Y[.Z] + match = re.search(version_rgx, version) + if match == None: + raise ValueError('%s is not a correct version : sould be X.Y[.Z].' % version) + compare = tuple([ int(x) for x in match.groups() if x ]) + #print 'comp', current, compare + if current < compare: + #print 'version too old' + def new_f(self, *args, **kwargs): + self.skip('Need at least %s version of python. Current version is %s.' % (version, '.'.join([str(element) for element in current]))) + new_f.__name__ = f.__name__ + return new_f + else: + #print 'version young enough' + return f + return check_require_version + |