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