Index: Doc/library/unittest.rst =================================================================== --- Doc/library/unittest.rst (revision 86537) +++ Doc/library/unittest.rst (working copy) @@ -8,6 +8,8 @@ .. sectionauthor:: Fred L. Drake, Jr. .. sectionauthor:: Raymond Hettinger +(If you are already familiar with the basic concepts of testing, you might want +to skip to :ref:`the list of assert* methods `.) The Python unit testing framework, sometimes referred to as "PyUnit," is a Python language version of JUnit, by Kent Beck and Erich Gamma. JUnit is, in @@ -776,8 +778,8 @@ by the test to be propagated to the caller, and can be used to support running tests under a debugger. + .. _assert-methods: - The :class:`TestCase` class provides a number of methods to check for and report failures, such as: @@ -821,6 +823,10 @@ | ` | | | +-----------------------------------------+-----------------------------+---------------+ + All the assert* methods (except :meth:`assertRaises`, + :meth:`assertRaisesRegexp`, :meth:`assertWarns`, :meth:`assertWarnsRegexp`) + accept a *msg* argument that, if specified, is used as the error message on + failure (see also :data:`longMessage`). .. method:: assertEqual(first, second, msg=None) @@ -831,10 +837,9 @@ list, tuple, dict, set, frozenset or str or any type that a subclass registers with :meth:`addTypeEqualityFunc` the type specific equality function will be called in order to generate a more useful default - error message. + error message (see also the :ref:`list of type-specific methods + `). - If specified, *msg* will be used as the error message on failure. - .. versionchanged:: 3.1 Added the automatic calling of type specific equality function. @@ -1145,10 +1150,30 @@ .. deprecated:: 3.2 + .. _type-specific-methods: - The following methods are used automatically by :meth:`~TestCase.assertEqual` - and usually is not necessary to invoke them directly: + The :meth:`assertEqual` method dispatches the equality check for objects of + the same type to different type-specific methods. These methods are already + implemented for most of the built-in types, but it's also possible to + register new methods using :meth:`addTypeEqualityFunc`: + .. method:: addTypeEqualityFunc(typeobj, function) + + Registers a type-specific method called by :meth:`assertEqual` to check + if two objects of exactly the same *typeobj* (not subclasses) compare + equal. *function* must take two positional arguments and a third msg=None + keyword argument just as :meth:`assertEqual` does. It must raise + :data:`self.failureException(msg) ` when inequality + between the first two parameters is detected -- possibly providing useful + information and explaining the inequalities in details in the error + message. + + .. versionadded:: 3.1 + + The list of type-specific methods automatically used by + :meth:`~TestCase.assertEqual` are summarized in the following table. Note + that it's usually not necessary to invoke these methods directly. + +-----------------------------------------+-----------------------------+--------------+ | Method | Used to compare | New in | +=========================================+=============================+==============+ @@ -1190,7 +1215,8 @@ be raised. If the sequences are different an error message is constructed that shows the difference between the two. - This method is used to implement :meth:`assertListEqual` and + This method is not called directly by :meth:`assertEqual`, but + it's used to used to implement :meth:`assertListEqual` and :meth:`assertTupleEqual`. .. versionadded:: 3.1 @@ -1231,6 +1257,8 @@ + .. _other-methods-and-attrs: + Finally the :class:`TestCase` provides the following methods and attributes: @@ -1252,11 +1280,12 @@ .. attribute:: longMessage If set to True then any explicit failure message you pass in to the - assert methods will be appended to the end of the normal failure message. - The normal messages contain useful information about the objects involved, - for example the message from assertEqual shows you the repr of the two - unequal objects. Setting this attribute to True allows you to have a - custom error message in addition to the normal one. + :ref:`assert methods ` will be appended to the end of the + normal failure message. The normal messages contain useful information + about the objects involved, for example the message from assertEqual + shows you the repr of the two unequal objects. Setting this attribute + to True allows you to have a custom error message in addition to the + normal one. This attribute defaults to False, meaning that a custom message passed to an assert method will silence the normal message. @@ -1322,23 +1351,7 @@ with unittest extensions and adding the test name was moved to the :class:`TextTestResult`. - .. method:: addTypeEqualityFunc(typeobj, function) - Registers a type specific :meth:`assertEqual` equality checking - function to be called by :meth:`assertEqual` when both objects it has - been asked to compare are exactly *typeobj* (not subclasses). - *function* must take two positional arguments and a third msg=None - keyword argument just as :meth:`assertEqual` does. It must raise - ``self.failureException`` when inequality between the first two - parameters is detected. - - One good use of custom equality checking functions for a type - is to raise ``self.failureException`` with an error message useful - for debugging the problem by explaining the inequalities in detail. - - .. versionadded:: 3.1 - - .. method:: addCleanup(function, *args, **kwargs) Add a function to be called after :meth:`tearDown` to cleanup resources Index: Doc/library/functions.rst =================================================================== --- Doc/library/functions.rst (revision 86537) +++ Doc/library/functions.rst (working copy) @@ -7,6 +7,24 @@ The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order. +=================== ================= ================== ================ ==================== +.. .. Built-in Functions .. .. +=================== ================= ================== ================ ==================== +:func:`abs` :func:`dir` :func:`hex` :func:`next` :func:`slice` +:func:`all` :func:`divmod` :func:`id` :func:`object` :func:`sorted` +:func:`any` :func:`enumerate` :func:`input` :func:`oct` :func:`staticmethod` +:func:`ascii` :func:`eval` :func:`int` :func:`open` :func:`str` +:func:`bin` :func:`exec` :func:`isinstance` :func:`ord` :func:`sum` +:func:`bool` :func:`filter` :func:`issubclass` :func:`pow` :func:`super` +:func:`bytearray` :func:`float` :func:`iter` :func:`print` :func:`tuple` +:func:`bytes` :func:`format` :func:`len` :func:`property` :func:`type` +:func:`chr` :func:`frozenset` :func:`list` :func:`range` :func:`type` +:func:`classmethod` :func:`getattr` :func:`locals` :func:`repr` :func:`vars` +:func:`compile` :func:`globals` :func:`map` :func:`reversed` :func:`zip` +:func:`complex` :func:`hasattr` :func:`max` :func:`round` :func:`__import__` +:func:`delattr` :func:`hash` :func:`memoryview` :func:`set` +:func:`dict` :func:`help` :func:`min` :func:`setattr` +=================== ================= ================== ================ ==================== .. function:: abs(x)

AltStyle によって変換されたページ (->オリジナル) /