Skip to content

Commit

Permalink
Merge pull request ipython#3883 from ivanov/no-x11
Browse files Browse the repository at this point in the history
skip test on unix when x11 not available

If you just use DISPLAY= iptest then Qt console tests were failing with a
generic : cannot connect to X server
  • Loading branch information
Carreau committed Aug 16, 2013
2 parents 0d01022 + 9c29ae8 commit 83a624e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions IPython/lib/tests/test_irunner_pylab_magic.py
Expand Up @@ -66,6 +66,7 @@ def _test_runner(self,runner,source,output):
self.assertTrue(mismatch==0,'Number of mismatched lines: %s' %
mismatch)

@decorators.skip_if_no_x11
@decorators.skipif_not_matplotlib
@decorators.skipif(pylab_not_importable, "Likely a run without X.")
def test_pylab_import_all_enabled(self):
Expand All @@ -92,6 +93,7 @@ def test_pylab_import_all_enabled(self):
runner = irunner.IPythonRunner(out=self.out)
self._test_runner(runner,source,output)

@decorators.skip_if_no_x11
@decorators.skipif_not_matplotlib
@decorators.skipif(pylab_not_importable, "Likely a run without X.")
def test_pylab_import_all_disabled(self):
Expand Down
2 changes: 2 additions & 0 deletions IPython/qt/console/tests/test_console_widget.py
Expand Up @@ -6,7 +6,9 @@

# 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):

Expand Down
2 changes: 2 additions & 0 deletions IPython/qt/console/tests/test_kill_ring.py
Expand Up @@ -6,7 +6,9 @@

# 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):

Expand Down
25 changes: 25 additions & 0 deletions IPython/testing/decorators.py
Expand Up @@ -49,6 +49,7 @@

# Stdlib imports
import sys
import os
import tempfile
import unittest

Expand Down Expand Up @@ -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

Expand All @@ -314,6 +328,17 @@ def module_not_available(module):
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.get('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
Expand Down

0 comments on commit 83a624e

Please sign in to comment.