diff --git a/IPython/testing/decorators_trial.py b/IPython/testing/decorators_trial.py deleted file mode 100644 index 231054b..0000000 --- a/IPython/testing/decorators_trial.py +++ /dev/null @@ -1,132 +0,0 @@ -# encoding: utf-8 -""" -Testing related decorators for use with twisted.trial. - -The decorators in this files are designed to follow the same API as those -in the decorators module (in this same directory). But they can be used -with twisted.trial -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2009 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -import os -import sys - -from IPython.testing.decorators import make_label_dec - -#----------------------------------------------------------------------------- -# Testing decorators -#----------------------------------------------------------------------------- - - -def skipif(skip_condition, msg=None): - """Create a decorator that marks a test function for skipping. - - The is a decorator factory that returns a decorator that will - conditionally skip a test based on the value of skip_condition. The - skip_condition argument can either be a boolean or a callable that returns - a boolean. - - Parameters - ---------- - skip_condition : boolean or callable - If this evaluates to True, the test is skipped. - msg : str - The message to print if the test is skipped. - - Returns - ------- - decorator : function - The decorator function that can be applied to the test function. - """ - - def skip_decorator(f): - - # Allow for both boolean or callable skip conditions. - if callable(skip_condition): - skip_val = lambda : skip_condition() - else: - skip_val = lambda : skip_condition - - if msg is None: - out = 'Test skipped due to test condition.' - else: - out = msg - final_msg = "Skipping test: %s. %s" % (f.__name__,out) - - if skip_val(): - f.skip = final_msg - - return f - return skip_decorator - - -def skip(msg=None): - """Create a decorator that marks a test function for skipping. - - This is a decorator factory that returns a decorator that will cause - tests to be skipped. - - Parameters - ---------- - msg : str - Optional message to be added. - - Returns - ------- - decorator : function - Decorator, which, when applied to a function, sets the skip - attribute of the function causing `twisted.trial` to skip it. - """ - - return skipif(True,msg) - - -def numpy_not_available(): - """Can numpy be imported? Returns true if numpy does NOT import. - - This is used to make a decorator to skip tests that require numpy to be - available, but delay the 'import numpy' to test execution time. - """ - try: - import numpy - np_not_avail = False - except ImportError: - np_not_avail = True - - return np_not_avail - -#----------------------------------------------------------------------------- -# Decorators for public use -#----------------------------------------------------------------------------- - -# Decorators to skip certain tests on specific platforms. -skip_win32 = skipif(sys.platform == 'win32', - "This test does not run under Windows") -skip_linux = skipif(sys.platform == 'linux2', - "This test does not run under Linux") -skip_osx = skipif(sys.platform == 'darwin',"This test does not run under OS X") - -# Decorators to skip tests if not on specific platforms. -skip_if_not_win32 = skipif(sys.platform != 'win32', - "This test only runs under Windows") -skip_if_not_linux = skipif(sys.platform != 'linux2', - "This test only runs under Linux") -skip_if_not_osx = skipif(sys.platform != 'darwin', - "This test only runs under OSX") - -# Other skip decorators -skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy") - -skipknownfailure = skip('This test is known to fail') - - diff --git a/IPython/testing/tests/test_decorators_trial.py b/IPython/testing/tests/test_decorators_trial.py index 6462285..427bede 100644 --- a/IPython/testing/tests/test_decorators_trial.py +++ b/IPython/testing/tests/test_decorators_trial.py @@ -1,6 +1,6 @@ # encoding: utf-8 """ -Tests for decorators_trial.py +Tests for decorators.py compatibility with Twisted.trial """ #----------------------------------------------------------------------------- @@ -14,19 +14,24 @@ Tests for decorators_trial.py # Imports #----------------------------------------------------------------------------- -# Tell nose to skip this module +# Tell nose to skip this module, since this is for twisted only __test__ = {} import os import sys from twisted.trial import unittest -import IPython.testing.decorators_trial as dec +import IPython.testing.decorators as dec #----------------------------------------------------------------------------- # Tests #----------------------------------------------------------------------------- +# Note: this code is identical to that in test_decorators, but that one uses +# stdlib unittest, not the one from twisted, which we are using here. While +# somewhat redundant, we want to check both with the stdlib and with twisted, +# so the duplication is OK. + class TestDecoratorsTrial(unittest.TestCase): @dec.skip() @@ -49,4 +54,4 @@ class TestDecoratorsTrial(unittest.TestCase): @dec.skip_osx def test_osx(self): - self.assertNotEquals(sys.platform,'darwin',"This test can't run under osx") \ No newline at end of file + self.assertNotEquals(sys.platform,'darwin',"This test can't run under osx")