Skip to content

Commit bed7d04

Browse files
committed
Merged revisions 74095 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r74095 | benjamin.peterson | 2009-07-19 15:18:21 -0500 (Sun, 19 Jul 2009) | 1 line split unittest.py into a package ........
1 parent c4296d1 commit bed7d04

14 files changed

+950
-928
lines changed

Lib/test/test_doctest.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,43 +1813,43 @@ def test_DocTestSuite():
18131813
>>> import test.sample_doctest
18141814
>>> suite = doctest.DocTestSuite(test.sample_doctest)
18151815
>>> suite.run(unittest.TestResult())
1816-
<unittest.TestResult run=9 errors=0 failures=4>
1816+
<unittest.result.TestResult run=9 errors=0 failures=4>
18171817
18181818
We can also supply the module by name:
18191819
18201820
>>> suite = doctest.DocTestSuite('test.sample_doctest')
18211821
>>> suite.run(unittest.TestResult())
1822-
<unittest.TestResult run=9 errors=0 failures=4>
1822+
<unittest.result.TestResult run=9 errors=0 failures=4>
18231823
18241824
We can use the current module:
18251825
18261826
>>> suite = test.sample_doctest.test_suite()
18271827
>>> suite.run(unittest.TestResult())
1828-
<unittest.TestResult run=9 errors=0 failures=4>
1828+
<unittest.result.TestResult run=9 errors=0 failures=4>
18291829
18301830
We can supply global variables. If we pass globs, they will be
18311831
used instead of the module globals. Here we'll pass an empty
18321832
globals, triggering an extra error:
18331833
18341834
>>> suite = doctest.DocTestSuite('test.sample_doctest', globs={})
18351835
>>> suite.run(unittest.TestResult())
1836-
<unittest.TestResult run=9 errors=0 failures=5>
1836+
<unittest.result.TestResult run=9 errors=0 failures=5>
18371837
18381838
Alternatively, we can provide extra globals. Here we'll make an
18391839
error go away by providing an extra global variable:
18401840
18411841
>>> suite = doctest.DocTestSuite('test.sample_doctest',
18421842
... extraglobs={'y': 1})
18431843
>>> suite.run(unittest.TestResult())
1844-
<unittest.TestResult run=9 errors=0 failures=3>
1844+
<unittest.result.TestResult run=9 errors=0 failures=3>
18451845
18461846
You can pass option flags. Here we'll cause an extra error
18471847
by disabling the blank-line feature:
18481848
18491849
>>> suite = doctest.DocTestSuite('test.sample_doctest',
18501850
... optionflags=doctest.DONT_ACCEPT_BLANKLINE)
18511851
>>> suite.run(unittest.TestResult())
1852-
<unittest.TestResult run=9 errors=0 failures=5>
1852+
<unittest.result.TestResult run=9 errors=0 failures=5>
18531853
18541854
You can supply setUp and tearDown functions:
18551855
@@ -1866,7 +1866,7 @@ def test_DocTestSuite():
18661866
>>> suite = doctest.DocTestSuite('test.sample_doctest',
18671867
... setUp=setUp, tearDown=tearDown)
18681868
>>> suite.run(unittest.TestResult())
1869-
<unittest.TestResult run=9 errors=0 failures=3>
1869+
<unittest.result.TestResult run=9 errors=0 failures=3>
18701870
18711871
But the tearDown restores sanity:
18721872
@@ -1884,7 +1884,7 @@ def test_DocTestSuite():
18841884
18851885
>>> suite = doctest.DocTestSuite('test.sample_doctest', setUp=setUp)
18861886
>>> suite.run(unittest.TestResult())
1887-
<unittest.TestResult run=9 errors=0 failures=3>
1887+
<unittest.result.TestResult run=9 errors=0 failures=3>
18881888
18891889
Here, we didn't need to use a tearDown function because we
18901890
modified the test globals, which are a copy of the
@@ -1903,7 +1903,7 @@ def test_DocFileSuite():
19031903
... 'test_doctest2.txt',
19041904
... 'test_doctest4.txt')
19051905
>>> suite.run(unittest.TestResult())
1906-
<unittest.TestResult run=3 errors=0 failures=2>
1906+
<unittest.result.TestResult run=3 errors=0 failures=2>
19071907
19081908
The test files are looked for in the directory containing the
19091909
calling module. A package keyword argument can be provided to
@@ -1915,7 +1915,7 @@ def test_DocFileSuite():
19151915
... 'test_doctest4.txt',
19161916
... package='test')
19171917
>>> suite.run(unittest.TestResult())
1918-
<unittest.TestResult run=3 errors=0 failures=2>
1918+
<unittest.result.TestResult run=3 errors=0 failures=2>
19191919
19201920
Support for using a package's __loader__.get_data() is also
19211921
provided.
@@ -1934,14 +1934,14 @@ def test_DocFileSuite():
19341934
... finally:
19351935
... if added_loader:
19361936
... del test.__loader__
1937-
<unittest.TestResult run=3 errors=0 failures=2>
1937+
<unittest.result.TestResult run=3 errors=0 failures=2>
19381938
19391939
'/' should be used as a path separator. It will be converted
19401940
to a native separator at run time:
19411941
19421942
>>> suite = doctest.DocFileSuite('../test/test_doctest.txt')
19431943
>>> suite.run(unittest.TestResult())
1944-
<unittest.TestResult run=1 errors=0 failures=1>
1944+
<unittest.result.TestResult run=1 errors=0 failures=1>
19451945
19461946
If DocFileSuite is used from an interactive session, then files
19471947
are resolved relative to the directory of sys.argv[0]:
@@ -1966,7 +1966,7 @@ def test_DocFileSuite():
19661966
19671967
>>> suite = doctest.DocFileSuite(test_file, module_relative=False)
19681968
>>> suite.run(unittest.TestResult())
1969-
<unittest.TestResult run=1 errors=0 failures=1>
1969+
<unittest.result.TestResult run=1 errors=0 failures=1>
19701970
19711971
It is an error to specify `package` when `module_relative=False`:
19721972
@@ -1982,7 +1982,7 @@ def test_DocFileSuite():
19821982
... 'test_doctest4.txt',
19831983
... globs={'favorite_color': 'blue'})
19841984
>>> suite.run(unittest.TestResult())
1985-
<unittest.TestResult run=3 errors=0 failures=1>
1985+
<unittest.result.TestResult run=3 errors=0 failures=1>
19861986
19871987
In this case, we supplied a missing favorite color. You can
19881988
provide doctest options:
@@ -1993,7 +1993,7 @@ def test_DocFileSuite():
19931993
... optionflags=doctest.DONT_ACCEPT_BLANKLINE,
19941994
... globs={'favorite_color': 'blue'})
19951995
>>> suite.run(unittest.TestResult())
1996-
<unittest.TestResult run=3 errors=0 failures=2>
1996+
<unittest.result.TestResult run=3 errors=0 failures=2>
19971997
19981998
And, you can provide setUp and tearDown functions:
19991999
@@ -2012,7 +2012,7 @@ def test_DocFileSuite():
20122012
... 'test_doctest4.txt',
20132013
... setUp=setUp, tearDown=tearDown)
20142014
>>> suite.run(unittest.TestResult())
2015-
<unittest.TestResult run=3 errors=0 failures=1>
2015+
<unittest.result.TestResult run=3 errors=0 failures=1>
20162016
20172017
But the tearDown restores sanity:
20182018
@@ -2031,7 +2031,7 @@ def test_DocFileSuite():
20312031
20322032
>>> suite = doctest.DocFileSuite('test_doctest.txt', setUp=setUp)
20332033
>>> suite.run(unittest.TestResult())
2034-
<unittest.TestResult run=1 errors=0 failures=0>
2034+
<unittest.result.TestResult run=1 errors=0 failures=0>
20352035
20362036
Here, we didn't need to use a tearDown function because we
20372037
modified the test globals. The test globals are
@@ -2043,7 +2043,7 @@ def test_DocFileSuite():
20432043
20442044
>>> suite = doctest.DocFileSuite('test_doctest3.txt')
20452045
>>> suite.run(unittest.TestResult())
2046-
<unittest.TestResult run=1 errors=0 failures=0>
2046+
<unittest.result.TestResult run=1 errors=0 failures=0>
20472047
20482048
If the tests contain non-ASCII characters, we have to specify which
20492049
encoding the file is encoded with. We do so by using the `encoding`
@@ -2054,7 +2054,7 @@ def test_DocFileSuite():
20542054
... 'test_doctest4.txt',
20552055
... encoding='utf-8')
20562056
>>> suite.run(unittest.TestResult())
2057-
<unittest.TestResult run=3 errors=0 failures=2>
2057+
<unittest.result.TestResult run=3 errors=0 failures=2>
20582058
20592059
"""
20602060

Lib/test/test_linecache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
TESTS = 'cjkencodings_test inspect_fodder inspect_fodder2 mapping_tests'
1313
TESTS = TESTS.split()
1414
TEST_PATH = os.path.dirname(support.__file__)
15-
MODULES = "linecache unittest".split()
15+
MODULES = "linecache abc".split()
1616
MODULE_PATH = os.path.dirname(FILENAME)
1717

1818
SOURCE_1 = '''

Lib/test/test_pyclbr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def defined_in(item, module):
141141
def test_easy(self):
142142
self.checkModule('pyclbr')
143143
self.checkModule('ast')
144-
self.checkModule('doctest', ignore=("TestResults", "_SpoofOut"))
144+
self.checkModule('doctest', ignore=("TestResults", "_SpoofOut",
145+
"DocTestCase"))
145146
self.checkModule('difflib', ignore=("Match",))
146147

147148
def test_decorators(self):

Lib/test/test_unittest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
TestCase.{assert,fail}* methods (some are tested implicitly)
77
"""
88

9+
import builtins
910
import os
1011
import re
1112
import sys
@@ -3389,9 +3390,10 @@ class TestDiscovery(TestCase):
33893390
def test_get_module_from_path(self):
33903391
loader = unittest.TestLoader()
33913392

3393+
old_import = __import__
33923394
def restore_import():
3393-
unittest.__import__ = __import__
3394-
unittest.__import__ = lambda *_: None
3395+
builtins.__import__ = old_import
3396+
builtins.__import__ = lambda *_: None
33953397
self.addCleanup(restore_import)
33963398

33973399
expected_module = object()

Lib/unittest/__init__.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
3+
Smalltalk testing framework.
4+
5+
This module contains the core framework classes that form the basis of
6+
specific test cases and suites (TestCase, TestSuite etc.), and also a
7+
text-based utility class for running the tests and reporting the results
8+
(TextTestRunner).
9+
10+
Simple usage:
11+
12+
import unittest
13+
14+
class IntegerArithmenticTestCase(unittest.TestCase):
15+
def testAdd(self): ## test method names begin 'test*'
16+
self.assertEqual((1 + 2), 3)
17+
self.assertEqual(0 + 1, 1)
18+
def testMultiply(self):
19+
self.assertEqual((0 * 10), 0)
20+
self.assertEqual((5 * 8), 40)
21+
22+
if __name__ == '__main__':
23+
unittest.main()
24+
25+
Further information is available in the bundled documentation, and from
26+
27+
http://docs.python.org/library/unittest.html
28+
29+
Copyright (c) 1999-2003 Steve Purcell
30+
Copyright (c) 2003-2009 Python Software Foundation
31+
This module is free software, and you may redistribute it and/or modify
32+
it under the same terms as Python itself, so long as this copyright message
33+
and disclaimer are retained in their original form.
34+
35+
IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
36+
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
37+
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
38+
DAMAGE.
39+
40+
THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
41+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
42+
PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
43+
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
44+
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45+
"""
46+
47+
__all__ = ['TestResult', 'TestCase', 'TestSuite',
48+
'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main',
49+
'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
50+
'expectedFailure']
51+
52+
# Expose obsolete functions for backwards compatibility
53+
__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])
54+
55+
56+
from .result import TestResult
57+
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
58+
skipUnless, expectedFailure)
59+
from .suite import TestSuite
60+
from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
61+
findTestCases)
62+
from .main import TestProgram, main
63+
from .runner import TextTestRunner

Lib/unittest/__main__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Main entry point"""
2+
3+
import sys
4+
if sys.argv[0].endswith("__main__.py"):
5+
sys.argv[0] = "unittest"
6+
7+
from .main import main
8+
main(module=None)

0 commit comments

Comments
 (0)