From 80de7d2536778ff611f432394b8358e98fc1a5a1 2010-01-13 01:18:57 From: Fernando Perez Date: 2010-01-13 01:18:57 Subject: [PATCH] Add new @onlyif decorator, the reverse of @skipif. It's trivial, but it makes certain conditions much cleaner to express. --- diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index fca1b15..6f0e9b8 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -205,7 +205,7 @@ def skipif(skip_condition, msg=None): # Allow for both boolean or callable skip conditions. if callable(skip_condition): - skip_val = lambda : skip_condition() + skip_val = skip_condition else: skip_val = lambda : skip_condition @@ -262,6 +262,16 @@ def skip(msg=None): return skipif(True,msg) +def onlyif(condition, msg): + """The reverse from skipif, see skipif for details.""" + + if callable(condition): + skip_condition = lambda : not condition() + else: + skip_condition = lambda : not condition + + return skipif(skip_condition, msg) + #----------------------------------------------------------------------------- # Utility functions for decorators def numpy_not_available():