Rewrap a few long lines.

This commit is contained in:
Georg Brandl 2009-05-30 10:45:40 +00:00
parent 6da0e6ac5a
commit 2fcd17324d

View file

@ -79,16 +79,20 @@ need to derive from a specific class.
Module :mod:`doctest` Module :mod:`doctest`
Another test-support module with a very different flavor. Another test-support module with a very different flavor.
`Simple Smalltalk Testing: With Patterns <http://www.XProgramming.com/testfram.htm>`_ `Simple Smalltalk Testing: With Patterns
Kent Beck's original paper on testing frameworks using the pattern shared by <http://www.XProgramming.com/testfram.htm>`_
:mod:`unittest`. Kent Beck's original paper on testing frameworks using the pattern shared
by :mod:`unittest`.
`Nose <http://code.google.com/p/python-nose/>`_ and `py.test <http://pytest.org>`_ `Nose <http://code.google.com/p/python-nose/>`_ and `py.test
Third-party unittest frameworks with a lighter-weight syntax <http://pytest.org>`_
for writing tests. For example, ``assert func(10) == 42``. Third-party unittest frameworks with a lighter-weight syntax for writing
tests. For example, ``assert func(10) == 42``.
`python-mock <http://python-mock.sourceforge.net/>`_ and `minimock <http://blog.ianbicking.org/minimock.html>`_ `python-mock <http://python-mock.sourceforge.net/>`_ and
Tools for creating mock test objects (objects simulating external resources). `minimock <http://blog.ianbicking.org/minimock.html>`_
Tools for creating mock test objects (objects simulating external
resources).
@ -277,13 +281,12 @@ The simplest :class:`TestCase` subclass will simply override the
self.assertEqual(widget.size(), (50, 50), 'incorrect default size') self.assertEqual(widget.size(), (50, 50), 'incorrect default size')
Note that in order to test something, we use the one of the :meth:`assert\*` Note that in order to test something, we use the one of the :meth:`assert\*`
methods provided by the :class:`TestCase` base class. If the methods provided by the :class:`TestCase` base class. If the test fails, an
test fails, an exception will be raised, and :mod:`unittest` will identify the exception will be raised, and :mod:`unittest` will identify the test case as a
test case as a :dfn:`failure`. Any other exceptions will be treated as :dfn:`failure`. Any other exceptions will be treated as :dfn:`errors`. This
:dfn:`errors`. This helps you identify where the problem is: :dfn:`failures` are helps you identify where the problem is: :dfn:`failures` are caused by incorrect
caused by incorrect results - a 5 where you expected a 6. :dfn:`Errors` are results - a 5 where you expected a 6. :dfn:`Errors` are caused by incorrect
caused by incorrect code - e.g., a :exc:`TypeError` caused by an incorrect code - e.g., a :exc:`TypeError` caused by an incorrect function call.
function call.
The way to run a test case will be described later. For now, note that to The way to run a test case will be described later. For now, note that to
construct an instance of such a test case, we call its constructor without construct an instance of such a test case, we call its constructor without
@ -482,10 +485,10 @@ may treat :exc:`AssertionError` differently.
.. note:: .. note::
Even though :class:`FunctionTestCase` can be used to quickly convert an existing Even though :class:`FunctionTestCase` can be used to quickly convert an
test base over to a :mod:`unittest`\ -based system, this approach is not existing test base over to a :mod:`unittest`\ -based system, this approach is
recommended. Taking the time to set up proper :class:`TestCase` subclasses will not recommended. Taking the time to set up proper :class:`TestCase`
make future test refactorings infinitely easier. subclasses will make future test refactorings infinitely easier.
In some cases, the existing tests may have been written using the :mod:`doctest` In some cases, the existing tests may have been written using the :mod:`doctest`
module. If so, :mod:`doctest` provides a :class:`DocTestSuite` class that can module. If so, :mod:`doctest` provides a :class:`DocTestSuite` class that can
@ -514,7 +517,8 @@ Basic skipping looks like this: ::
def test_nothing(self): def test_nothing(self):
self.fail("shouldn't happen") self.fail("shouldn't happen")
@unittest.skipIf(mylib.__version__ < (1, 3), "not supported in this library version") @unittest.skipIf(mylib.__version__ < (1, 3),
"not supported in this library version")
def test_format(self): def test_format(self):
# Tests that work for only a certain version of the library. # Tests that work for only a certain version of the library.
pass pass
@ -1079,10 +1083,10 @@ Test cases
.. class:: FunctionTestCase(testFunc[, setUp[, tearDown[, description]]]) .. class:: FunctionTestCase(testFunc[, setUp[, tearDown[, description]]])
This class implements the portion of the :class:`TestCase` interface which This class implements the portion of the :class:`TestCase` interface which
allows the test runner to drive the test, but does not provide the methods which allows the test runner to drive the test, but does not provide the methods
test code can use to check and report errors. This is used to create test cases which test code can use to check and report errors. This is used to create
using legacy test code, allowing it to be integrated into a :mod:`unittest`\ test cases using legacy test code, allowing it to be integrated into a
-based test framework. :mod:`unittest`-based test framework.
.. _testsuite-objects: .. _testsuite-objects:
@ -1117,8 +1121,8 @@ Grouping tests
Add all the tests from an iterable of :class:`TestCase` and :class:`TestSuite` Add all the tests from an iterable of :class:`TestCase` and :class:`TestSuite`
instances to this test suite. instances to this test suite.
This is equivalent to iterating over *tests*, calling :meth:`addTest` for each This is equivalent to iterating over *tests*, calling :meth:`addTest` for
element. each element.
:class:`TestSuite` shares the following methods with :class:`TestCase`: :class:`TestSuite` shares the following methods with :class:`TestCase`:
@ -1217,15 +1221,14 @@ Loading and running tests
rather than "a callable object". rather than "a callable object".
For example, if you have a module :mod:`SampleTests` containing a For example, if you have a module :mod:`SampleTests` containing a
:class:`TestCase`\ -derived class :class:`SampleTestCase` with three :class:`TestCase`\ -derived class :class:`SampleTestCase` with three test
test methods (:meth:`test_one`, :meth:`test_two`, and methods (:meth:`test_one`, :meth:`test_two`, and :meth:`test_three`), the
:meth:`test_three`), the specifier ``'SampleTests.SampleTestCase'`` specifier ``'SampleTests.SampleTestCase'`` would cause this method to
would cause this method to return a suite which will run all three test return a suite which will run all three test methods. Using the specifier
methods. Using the specifier ``'SampleTests.SampleTestCase.test_two'`` ``'SampleTests.SampleTestCase.test_two'`` would cause it to return a test
would cause it to return a test suite which will run only the suite which will run only the :meth:`test_two` test method. The specifier
:meth:`test_two` test method. The specifier can refer to modules and can refer to modules and packages which have not been imported; they will
packages which have not been imported; they will be imported as a be imported as a side-effect.
side-effect.
The method optionally resolves *name* relative to the given *module*. The method optionally resolves *name* relative to the given *module*.