From b7ed523ccf3ef180c1e8a6a62abc9fb76597ac57 2014-02-23 05:00:48 From: MinRK Date: 2014-02-23 05:00:48 Subject: [PATCH] add @onlyif_any_cmd_exists like @onlyif_cmds_exist, but pass if any is available instead of all --- diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 04c0dbe..8e5a4bb 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -381,3 +381,20 @@ def onlyif_cmds_exist(*commands): "is installed".format(cmd)) raise e return null_deco + +def onlyif_any_cmd_exists(*commands): + """ + Decorator to skip test unless at least one of `commands` is found. + """ + for cmd in commands: + try: + if is_cmd_found(cmd): + return null_deco + except ImportError as e: + # is_cmd_found uses pywin32 on windows, which might not be available + if sys.platform == 'win32' and 'pywin32' in str(e): + return skip("This test runs only if pywin32 and command '{0}' " + "is installed".format(cmd)) + raise e + return skip("This test runs only if one of the commands {0} " + "is installed".format(commands))