From f7cdf1ffd1e4e8685ca3d30957f69b2f0ffd6a57 2013-08-03 07:29:36 From: Paul Ivanov Date: 2013-08-03 07:29:36 Subject: [PATCH] skip tests when display variable is not set --- diff --git a/IPython/qt/console/tests/test_console_widget.py b/IPython/qt/console/tests/test_console_widget.py index cd86c2a..ead193c 100644 --- a/IPython/qt/console/tests/test_console_widget.py +++ b/IPython/qt/console/tests/test_console_widget.py @@ -6,7 +6,9 @@ from IPython.external.qt import QtCore, QtGui # Local imports from IPython.qt.console.console_widget import ConsoleWidget +import IPython.testing.decorators as dec +setup = dec.skip_file_no_x11(__name__) class TestConsoleWidget(unittest.TestCase): diff --git a/IPython/qt/console/tests/test_kill_ring.py b/IPython/qt/console/tests/test_kill_ring.py index 1626330..459cf58 100644 --- a/IPython/qt/console/tests/test_kill_ring.py +++ b/IPython/qt/console/tests/test_kill_ring.py @@ -6,7 +6,9 @@ from IPython.external.qt import QtGui # Local imports from IPython.qt.console.kill_ring import KillRing, QtKillRing +import IPython.testing.decorators as dec +setup = dec.skip_file_no_x11(__name__) class TestKillRing(unittest.TestCase): diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 68bede7..9c3284f 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -49,6 +49,7 @@ Authors # Stdlib imports import sys +import os import tempfile import unittest @@ -295,6 +296,19 @@ def module_not_available(module): return mod_not_avail + +def decorated_dummy(dec, name): + """Return a dummy function decorated with dec, with the given name. + + Examples + -------- + import IPython.testing.decorators as dec + setup = dec.decorated_dummy(dec.skip_if_no_x11, __name__) + """ + dummy = lambda: None + dummy.__name__ = name + return dec(dummy) + #----------------------------------------------------------------------------- # Decorators for public use @@ -314,6 +328,17 @@ skip_if_not_linux = skipif(not sys.platform.startswith('linux'), skip_if_not_osx = skipif(sys.platform != 'darwin', "This test only runs under OSX") + +_x11_skip_cond = (sys.platform not in ('darwin', 'win32') and + os.environ['DISPLAY']=='') +_x11_skip_msg = "Skipped under *nix when X11/XOrg not available" + +skip_if_no_x11 = skipif(_x11_skip_cond, _x11_skip_msg) + +# not a decorator itself, returns a dummy function to be used as setup +def skip_file_no_x11(name): + return decorated_dummy(skip_if_no_x11, name) if _x11_skip_cond else None + # Other skip decorators # generic skip without module