##// END OF EJS Templates
Backport PR #2757: check for complete pyside presence before trying to import...
Backport PR #2757: check for complete pyside presence before trying to import importing pyside partially and then falling back to pyqt causes a crash in sip (see gh-1431) To avoid it try to locate all modules before the import and should that fail print a warning. debian splits pyside into many small packages so sometimes people end up with incomplete pyside installations.

File last commit:

r5619:d1331138
r9857:b7de0897
Show More
_paramtestpy2.py
97 lines | 3.2 KiB | text/x-python | PythonLexer
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 """Implementation of the parametric test support for Python 2.x
"""
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2009-2011 The IPython Development Team
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
MinRK
don't use private TestCase._exc_info() method in parametric test...
r5619 import sys
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 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:
MinRK
don't use private TestCase._exc_info() method in parametric test...
r5619 result.addError(self, sys.exc_info())
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 return
# Test execution
ok = False
try:
testgen.next()
ok = True
except StopIteration:
# We stop the loop
break
except self.failureException:
MinRK
don't use private TestCase._exc_info() method in parametric test...
r5619 result.addFailure(self, sys.exc_info())
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 except KeyboardInterrupt:
raise
except:
MinRK
don't use private TestCase._exc_info() method in parametric test...
r5619 result.addError(self, sys.exc_info())
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 # TearDown
try:
self.tearDown()
except KeyboardInterrupt:
raise
except:
MinRK
don't use private TestCase._exc_info() method in parametric test...
r5619 result.addError(self, sys.exc_info())
Fernando Perez
Added test support for better parametric tests and nose fixes....
r2367 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