diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-07-19 21:01:52 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-07-19 21:01:52 (GMT) |
commit | bed7d04fedd800a8d3bd8a7c9c3ff823e365c236 (patch) | |
tree | f7e20f085f4c4a6a4cc0227ab16aa73d1dd7dc8e /Lib/test | |
parent | c4296d1edc1f05f96cc7b6b3e1c3df9dd596d5f4 (diff) | |
download | cpython-bed7d04fedd800a8d3bd8a7c9c3ff823e365c236.zip cpython-bed7d04fedd800a8d3bd8a7c9c3ff823e365c236.tar.gz cpython-bed7d04fedd800a8d3bd8a7c9c3ff823e365c236.tar.bz2 |
Merged revisions 74095 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74095 | benjamin.peterson | 2009-07-19 15:18:21 -0500 (Sun, 19 Jul 2009) | 1 line
split unittest.py into a package
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_doctest.py | 38 | ||||
-rw-r--r-- | Lib/test/test_linecache.py | 2 | ||||
-rw-r--r-- | Lib/test/test_pyclbr.py | 3 | ||||
-rw-r--r-- | Lib/test/test_unittest.py | 6 |
4 files changed, 26 insertions, 23 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 59ba74f..e4ac830 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -1813,19 +1813,19 @@ def test_DocTestSuite(): >>> import test.sample_doctest >>> suite = doctest.DocTestSuite(test.sample_doctest) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=4> + <unittest.result.TestResult run=9 errors=0 failures=4> We can also supply the module by name: >>> suite = doctest.DocTestSuite('test.sample_doctest') >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=4> + <unittest.result.TestResult run=9 errors=0 failures=4> We can use the current module: >>> suite = test.sample_doctest.test_suite() >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=4> + <unittest.result.TestResult run=9 errors=0 failures=4> We can supply global variables. If we pass globs, they will be used instead of the module globals. Here we'll pass an empty @@ -1833,7 +1833,7 @@ def test_DocTestSuite(): >>> suite = doctest.DocTestSuite('test.sample_doctest', globs={}) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=5> + <unittest.result.TestResult run=9 errors=0 failures=5> Alternatively, we can provide extra globals. Here we'll make an error go away by providing an extra global variable: @@ -1841,7 +1841,7 @@ def test_DocTestSuite(): >>> suite = doctest.DocTestSuite('test.sample_doctest', ... extraglobs={'y': 1}) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=3> + <unittest.result.TestResult run=9 errors=0 failures=3> You can pass option flags. Here we'll cause an extra error by disabling the blank-line feature: @@ -1849,7 +1849,7 @@ def test_DocTestSuite(): >>> suite = doctest.DocTestSuite('test.sample_doctest', ... optionflags=doctest.DONT_ACCEPT_BLANKLINE) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=5> + <unittest.result.TestResult run=9 errors=0 failures=5> You can supply setUp and tearDown functions: @@ -1866,7 +1866,7 @@ def test_DocTestSuite(): >>> suite = doctest.DocTestSuite('test.sample_doctest', ... setUp=setUp, tearDown=tearDown) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=3> + <unittest.result.TestResult run=9 errors=0 failures=3> But the tearDown restores sanity: @@ -1884,7 +1884,7 @@ def test_DocTestSuite(): >>> suite = doctest.DocTestSuite('test.sample_doctest', setUp=setUp) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=9 errors=0 failures=3> + <unittest.result.TestResult run=9 errors=0 failures=3> Here, we didn't need to use a tearDown function because we modified the test globals, which are a copy of the @@ -1903,7 +1903,7 @@ def test_DocFileSuite(): ... 'test_doctest2.txt', ... 'test_doctest4.txt') >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=3 errors=0 failures=2> + <unittest.result.TestResult run=3 errors=0 failures=2> The test files are looked for in the directory containing the calling module. A package keyword argument can be provided to @@ -1915,7 +1915,7 @@ def test_DocFileSuite(): ... 'test_doctest4.txt', ... package='test') >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=3 errors=0 failures=2> + <unittest.result.TestResult run=3 errors=0 failures=2> Support for using a package's __loader__.get_data() is also provided. @@ -1934,14 +1934,14 @@ def test_DocFileSuite(): ... finally: ... if added_loader: ... del test.__loader__ - <unittest.TestResult run=3 errors=0 failures=2> + <unittest.result.TestResult run=3 errors=0 failures=2> '/' should be used as a path separator. It will be converted to a native separator at run time: >>> suite = doctest.DocFileSuite('../test/test_doctest.txt') >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=1 errors=0 failures=1> + <unittest.result.TestResult run=1 errors=0 failures=1> If DocFileSuite is used from an interactive session, then files are resolved relative to the directory of sys.argv[0]: @@ -1966,7 +1966,7 @@ def test_DocFileSuite(): >>> suite = doctest.DocFileSuite(test_file, module_relative=False) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=1 errors=0 failures=1> + <unittest.result.TestResult run=1 errors=0 failures=1> It is an error to specify `package` when `module_relative=False`: @@ -1982,7 +1982,7 @@ def test_DocFileSuite(): ... 'test_doctest4.txt', ... globs={'favorite_color': 'blue'}) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=3 errors=0 failures=1> + <unittest.result.TestResult run=3 errors=0 failures=1> In this case, we supplied a missing favorite color. You can provide doctest options: @@ -1993,7 +1993,7 @@ def test_DocFileSuite(): ... optionflags=doctest.DONT_ACCEPT_BLANKLINE, ... globs={'favorite_color': 'blue'}) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=3 errors=0 failures=2> + <unittest.result.TestResult run=3 errors=0 failures=2> And, you can provide setUp and tearDown functions: @@ -2012,7 +2012,7 @@ def test_DocFileSuite(): ... 'test_doctest4.txt', ... setUp=setUp, tearDown=tearDown) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=3 errors=0 failures=1> + <unittest.result.TestResult run=3 errors=0 failures=1> But the tearDown restores sanity: @@ -2031,7 +2031,7 @@ def test_DocFileSuite(): >>> suite = doctest.DocFileSuite('test_doctest.txt', setUp=setUp) >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=1 errors=0 failures=0> + <unittest.result.TestResult run=1 errors=0 failures=0> Here, we didn't need to use a tearDown function because we modified the test globals. The test globals are @@ -2043,7 +2043,7 @@ def test_DocFileSuite(): >>> suite = doctest.DocFileSuite('test_doctest3.txt') >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=1 errors=0 failures=0> + <unittest.result.TestResult run=1 errors=0 failures=0> If the tests contain non-ASCII characters, we have to specify which encoding the file is encoded with. We do so by using the `encoding` @@ -2054,7 +2054,7 @@ def test_DocFileSuite(): ... 'test_doctest4.txt', ... encoding='utf-8') >>> suite.run(unittest.TestResult()) - <unittest.TestResult run=3 errors=0 failures=2> + <unittest.result.TestResult run=3 errors=0 failures=2> """ diff --git a/Lib/test/test_linecache.py b/Lib/test/test_linecache.py index 14d8d59..16767f4 100644 --- a/Lib/test/test_linecache.py +++ b/Lib/test/test_linecache.py @@ -12,7 +12,7 @@ EMPTY = '' TESTS = 'cjkencodings_test inspect_fodder inspect_fodder2 mapping_tests' TESTS = TESTS.split() TEST_PATH = os.path.dirname(support.__file__) -MODULES = "linecache unittest".split() +MODULES = "linecache abc".split() MODULE_PATH = os.path.dirname(FILENAME) SOURCE_1 = ''' diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index 30d8249..d81234c 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -141,7 +141,8 @@ class PyclbrTest(TestCase): def test_easy(self): self.checkModule('pyclbr') self.checkModule('ast') - self.checkModule('doctest', ignore=("TestResults", "_SpoofOut")) + self.checkModule('doctest', ignore=("TestResults", "_SpoofOut", + "DocTestCase")) self.checkModule('difflib', ignore=("Match",)) def test_decorators(self): diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 991740c..10932de 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -6,6 +6,7 @@ Still need testing: TestCase.{assert,fail}* methods (some are tested implicitly) """ +import builtins import os import re import sys @@ -3389,9 +3390,10 @@ class TestDiscovery(TestCase): def test_get_module_from_path(self): loader = unittest.TestLoader() + old_import = __import__ def restore_import(): - unittest.__import__ = __import__ - unittest.__import__ = lambda *_: None + builtins.__import__ = old_import + builtins.__import__ = lambda *_: None self.addCleanup(restore_import) expected_module = object() |