##// END OF EJS Templates
Work to address the review comments on Fernando's branch....
Work to address the review comments on Fernando's branch. * Added comment about Magic(object) (r1224) * Moved InteractiveTB.set_mode from IPythonApp -> InteractiveShell (r1229) * Moved pylabtools.py to IPython/lib (r1229) * Cleaned up comments and copyrights in testing (r1233) * Added comment about ip.shell._ofind (r1237) * Removed "Bye." from quitter (r1240). * Refactored and removed :mod:`IPython.utils.genutils` and :mod:`IPython.utils.platutils`. These modules have been replaced by topical focused modules in :mod:`IPython.utils`. * Refactored tests in :mod:`IPython.utils.tests`. * Moved :func:`IPython.testing.tools.temp_pyfile` to :mod:`IPython.utils.io`. * Moved :func:`IPython.testing.tools.cmd2argv` to :func:`IPython.testing.tools.pycmd2argv` and documented the fact that this only works with Python based command line programs. * Created a new :func:`IPython.utils.path.get_ipython_module_path` to use in finding paths to IPython modules.

File last commit:

r2498:3eae1372
r2498:3eae1372
Show More
_paramtestpy3.py
69 lines | 2.2 KiB | text/x-python | PythonLexer
"""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 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):
return unittest.FunctionTestCase(next_test,
self.setUp,
self.tearDown)
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