ยปCore Development>Code coverage>Lib/unittest/__init__.py

Python code coverage for Lib/unittest/__init__.py

#countcontent
1n/a"""
2n/aPython unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
3n/aSmalltalk testing framework (used with permission).
4n/a
5n/aThis module contains the core framework classes that form the basis of
6n/aspecific test cases and suites (TestCase, TestSuite etc.), and also a
7n/atext-based utility class for running the tests and reporting the results
8n/a (TextTestRunner).
9n/a
10n/aSimple usage:
11n/a
12n/a import unittest
13n/a
14n/a class IntegerArithmeticTestCase(unittest.TestCase):
15n/a def testAdd(self): # test method names begin with 'test'
16n/a self.assertEqual((1 + 2), 3)
17n/a self.assertEqual(0 + 1, 1)
18n/a def testMultiply(self):
19n/a self.assertEqual((0 * 10), 0)
20n/a self.assertEqual((5 * 8), 40)
21n/a
22n/a if __name__ == '__main__':
23n/a unittest.main()
24n/a
25n/aFurther information is available in the bundled documentation, and from
26n/a
27n/a http://docs.python.org/library/unittest.html
28n/a
29n/aCopyright (c) 1999-2003 Steve Purcell
30n/aCopyright (c) 2003-2010 Python Software Foundation
31n/aThis module is free software, and you may redistribute it and/or modify
32n/ait under the same terms as Python itself, so long as this copyright message
33n/aand disclaimer are retained in their original form.
34n/a
35n/aIN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
36n/aSPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
37n/aTHIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
38n/aDAMAGE.
39n/a
40n/aTHE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
41n/aLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
42n/aPARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
43n/aAND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
44n/aSUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45n/a"""
46n/a
47n/a__all__ = ['TestResult', 'TestCase', 'TestSuite',
48n/a 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main',
49n/a 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
50n/a 'expectedFailure', 'TextTestResult', 'installHandler',
51n/a 'registerResult', 'removeResult', 'removeHandler']
52n/a
53n/a# Expose obsolete functions for backwards compatibility
54n/a__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])
55n/a
56n/a__unittest = True
57n/a
58n/afrom .result import TestResult
59n/afrom .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
60n/a skipUnless, expectedFailure)
61n/afrom .suite import BaseTestSuite, TestSuite
62n/afrom .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
63n/a findTestCases)
64n/afrom .main import TestProgram, main
65n/afrom .runner import TextTestRunner, TextTestResult
66n/afrom .signals import installHandler, registerResult, removeResult, removeHandler
67n/a
68n/a# deprecated
69n/a_TextTestResult = TextTestResult
70n/a
71n/a# There are no tests here, so don't try to run anything discovered from
72n/a# introspecting the symbols (e.g. FunctionTestCase). Instead, all our
73n/a# tests come from within unittest.test.
74n/adef load_tests(loader, tests, pattern):
75n/a import os.path
76n/a # top level directory cached on loader instance
77n/a this_dir = os.path.dirname(__file__)
78n/a return loader.discover(start_dir=this_dir, pattern=pattern)