From e9afc369b05dd2b4802e9039225ac8b6170cf357 2013-09-03 17:05:55 From: Thomas Kluyver Date: 2013-09-03 17:05:55 Subject: [PATCH] Remove parametric testing machinery --- diff --git a/IPython/testing/_paramtestpy2.py b/IPython/testing/_paramtestpy2.py deleted file mode 100644 index 102bc85..0000000 --- a/IPython/testing/_paramtestpy2.py +++ /dev/null @@ -1,97 +0,0 @@ -"""Implementation of the parametric test support for Python 2.x -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2009-2011 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 sys -import unittest -from compiler.consts import CO_GENERATOR - -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- - -def isgenerator(func): - try: - return func.func_code.co_flags & CO_GENERATOR != 0 - except AttributeError: - return False - -class ParametricTestCase(unittest.TestCase): - """Write parametric tests in normal unittest testcase form. - - Limitations: the last iteration misses printing out a newline when running - in verbose mode. - """ - def run_parametric(self, result, testMethod): - # But if we have a test generator, we iterate it ourselves - testgen = testMethod() - while True: - try: - # Initialize test - result.startTest(self) - - # SetUp - try: - self.setUp() - except KeyboardInterrupt: - raise - except: - result.addError(self, sys.exc_info()) - return - # Test execution - ok = False - try: - next(testgen) - ok = True - except StopIteration: - # We stop the loop - break - except self.failureException: - result.addFailure(self, sys.exc_info()) - except KeyboardInterrupt: - raise - except: - result.addError(self, sys.exc_info()) - # TearDown - try: - self.tearDown() - except KeyboardInterrupt: - raise - except: - result.addError(self, sys.exc_info()) - ok = False - if ok: result.addSuccess(self) - - finally: - result.stopTest(self) - - def run(self, result=None): - if result is None: - result = self.defaultTestResult() - testMethod = getattr(self, self._testMethodName) - # For normal tests, we just call the base class and return that - if isgenerator(testMethod): - return self.run_parametric(result, testMethod) - else: - return super(ParametricTestCase, self).run(result) - - -def parametric(func): - """Decorator to make a simple function into a normal test via unittest.""" - - class Tester(ParametricTestCase): - test = staticmethod(func) - - Tester.__name__ = func.__name__ - - return Tester diff --git a/IPython/testing/_paramtestpy3.py b/IPython/testing/_paramtestpy3.py deleted file mode 100644 index 5956b5f..0000000 --- a/IPython/testing/_paramtestpy3.py +++ /dev/null @@ -1,71 +0,0 @@ -"""Implementation of the parametric test support for Python 3.x. - -Thanks for the py3 version to Robert Collins, from the Testing in Python -mailing list. -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2009-2011 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 unittest -from unittest import TestSuite - -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- - - -def isgenerator(func): - return hasattr(func,'_generator') - - -class IterCallableSuite(TestSuite): - def __init__(self, iterator, adapter): - self._iter = iterator - self._adapter = adapter - def __iter__(self): - yield self._adapter(self._iter.__next__) - -class ParametricTestCase(unittest.TestCase): - """Write parametric tests in normal unittest testcase form. - - Limitations: the last iteration misses printing out a newline when - running in verbose mode. - """ - - def run(self, result=None): - testMethod = getattr(self, self._testMethodName) - # For normal tests, we just call the base class and return that - if isgenerator(testMethod): - def adapter(next_test): - ftc = unittest.FunctionTestCase(next_test, - self.setUp, - self.tearDown) - self._nose_case = ftc # Nose 1.0 rejects the test without this - return ftc - - return IterCallableSuite(testMethod(),adapter).run(result) - else: - return super(ParametricTestCase, self).run(result) - - -def parametric(func): - """Decorator to make a simple function into a normal test via -unittest.""" - # Hack, until I figure out how to write isgenerator() for python3!! - func._generator = True - - class Tester(ParametricTestCase): - test = staticmethod(func) - - Tester.__name__ = func.__name__ - - return Tester diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index 8763002..d556783 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -16,10 +16,6 @@ Included decorators: Lightweight testing that remains unittest-compatible. -- @parametric, for parametric test support that is vastly easier to use than - nose's for debugging. With ours, if a test fails, the stack under inspection - is that of the test and not that of the test framework. - - An @as_unittest decorator can be used to tag any normal parameter-less function as a unittest TestCase. Then, both nose and normal unittest will recognize it as such. This will make it easier to migrate away from Nose if @@ -58,12 +54,6 @@ import unittest # This is Michele Simionato's decorator module, kept verbatim. from IPython.external.decorator import decorator -# We already have python3-compliant code for parametric tests -if sys.version[0]=='2': - from _paramtestpy2 import parametric -else: - from _paramtestpy3 import parametric - # Expose the unittest-driven decorators from ipunittest import ipdoctest, ipdocstring diff --git a/IPython/testing/ipunittest.py b/IPython/testing/ipunittest.py index 67f0f83..bfb6e6c 100644 --- a/IPython/testing/ipunittest.py +++ b/IPython/testing/ipunittest.py @@ -41,12 +41,6 @@ import sys import unittest from doctest import DocTestFinder, DocTestRunner, TestResults -# We already have python3-compliant code for parametric tests -if sys.version[0]=='2': - from ._paramtestpy2 import ParametricTestCase -else: - from ._paramtestpy3 import ParametricTestCase - #----------------------------------------------------------------------------- # Classes and functions #-----------------------------------------------------------------------------