diff --git a/Lib/test/doctest_aliases.py b/Lib/test/doctest/doctest_aliases.py rename from Lib/test/doctest_aliases.py rename to Lib/test/doctest/doctest_aliases.py diff --git a/Lib/test/sample_doctest.py b/Lib/test/doctest/sample_doctest.py rename from Lib/test/sample_doctest.py rename to Lib/test/doctest/sample_doctest.py diff --git a/Lib/test/sample_doctest_no_docstrings.py b/Lib/test/doctest/sample_doctest_no_docstrings.py rename from Lib/test/sample_doctest_no_docstrings.py rename to Lib/test/doctest/sample_doctest_no_docstrings.py diff --git a/Lib/test/sample_doctest_no_doctests.py b/Lib/test/doctest/sample_doctest_no_doctests.py rename from Lib/test/sample_doctest_no_doctests.py rename to Lib/test/doctest/sample_doctest_no_doctests.py diff --git a/Lib/test/test_doctest.txt b/Lib/test/doctest/test_doctest.txt rename from Lib/test/test_doctest.txt rename to Lib/test/doctest/test_doctest.txt diff --git a/Lib/test/test_doctest2.txt b/Lib/test/doctest/test_doctest2.txt rename from Lib/test/test_doctest2.txt rename to Lib/test/doctest/test_doctest2.txt diff --git a/Lib/test/test_doctest3.txt b/Lib/test/doctest/test_doctest3.txt rename from Lib/test/test_doctest3.txt rename to Lib/test/doctest/test_doctest3.txt diff --git a/Lib/test/test_doctest4.txt b/Lib/test/doctest/test_doctest4.txt rename from Lib/test/test_doctest4.txt rename to Lib/test/doctest/test_doctest4.txt diff --git a/Lib/test/doctest_DocFileSuite_test.txt b/Lib/test/doctest_DocFileSuite_test.txt new file mode 100644 --- /dev/null +++ b/Lib/test/doctest_DocFileSuite_test.txt @@ -0,0 +1,1 @@ +This is here just to test test_doctest.DocFileSuite file loader. diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -559,14 +559,14 @@ If a single object is listed twice (under different names), then tests will only be generated for it once: - >>> from test import doctest_aliases + >>> from test.doctest import doctest_aliases >>> assert doctest_aliases.TwoNames.f >>> assert doctest_aliases.TwoNames.g >>> tests = excl_empty_finder.find(doctest_aliases) >>> print(len(tests)) 2 >>> print(tests[0].name) - test.doctest_aliases.TwoNames + test.doctest.doctest_aliases.TwoNames TwoNames.f and TwoNames.g are bound to the same object. We can't guess which will be found in doctest's traversal of @@ -2079,39 +2079,39 @@ by passing a module object: >>> import unittest - >>> import test.sample_doctest - >>> suite = doctest.DocTestSuite(test.sample_doctest) + >>> import test.doctest.sample_doctest + >>> suite = doctest.DocTestSuite(test.doctest.sample_doctest) >>> suite.run(unittest.TestResult()) We can also supply the module by name: - >>> suite = doctest.DocTestSuite('test.sample_doctest') + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest') >>> suite.run(unittest.TestResult()) The module need not contain any doctest examples: - >>> suite = doctest.DocTestSuite('test.sample_doctest_no_doctests') + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest_no_doctests') >>> suite.run(unittest.TestResult()) The module need not contain any docstrings either: - >>> suite = doctest.DocTestSuite('test.sample_doctest_no_docstrings') + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest_no_docstrings') >>> suite.run(unittest.TestResult()) We can use the current module: - >>> suite = test.sample_doctest.test_suite() + >>> suite = test.doctest.sample_doctest.test_suite() >>> suite.run(unittest.TestResult()) We can also provide a DocTestFinder: >>> finder = doctest.DocTestFinder() - >>> suite = doctest.DocTestSuite('test.sample_doctest', + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest', ... test_finder=finder) >>> suite.run(unittest.TestResult()) @@ -2119,7 +2119,7 @@ The DocTestFinder need not return any tests: >>> finder = doctest.DocTestFinder() - >>> suite = doctest.DocTestSuite('test.sample_doctest_no_docstrings', + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest_no_docstrings', ... test_finder=finder) >>> suite.run(unittest.TestResult()) @@ -2128,14 +2128,14 @@ used instead of the module globals. Here we'll pass an empty globals, triggering an extra error: - >>> suite = doctest.DocTestSuite('test.sample_doctest', globs={}) + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest', globs={}) >>> suite.run(unittest.TestResult()) Alternatively, we can provide extra globals. Here we'll make an error go away by providing an extra global variable: - >>> suite = doctest.DocTestSuite('test.sample_doctest', + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest', ... extraglobs={'y': 1}) >>> suite.run(unittest.TestResult()) @@ -2143,7 +2143,7 @@ You can pass option flags. Here we'll cause an extra error by disabling the blank-line feature: - >>> suite = doctest.DocTestSuite('test.sample_doctest', + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest', ... optionflags=doctest.DONT_ACCEPT_BLANKLINE) >>> suite.run(unittest.TestResult()) @@ -2160,7 +2160,7 @@ Here, we installed a silly variable that the test expects: - >>> suite = doctest.DocTestSuite('test.sample_doctest', + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest', ... setUp=setUp, tearDown=tearDown) >>> suite.run(unittest.TestResult()) @@ -2179,7 +2179,7 @@ >>> def setUp(test): ... test.globs['y'] = 1 - >>> suite = doctest.DocTestSuite('test.sample_doctest', setUp=setUp) + >>> suite = doctest.DocTestSuite('test.doctest.sample_doctest', setUp=setUp) >>> suite.run(unittest.TestResult()) @@ -2196,11 +2196,9 @@ files that include examples: >>> import unittest - >>> suite = doctest.DocFileSuite('test_doctest.txt', - ... 'test_doctest2.txt', - ... 'test_doctest4.txt') + >>> suite = doctest.DocFileSuite('doctest_DocFileSuite_test.txt',) >>> suite.run(unittest.TestResult()) - + The test files are looked for in the directory containing the calling module. A package keyword argument can be provided to @@ -2210,7 +2208,7 @@ >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', ... 'test_doctest4.txt', - ... package='test') + ... package='test.doctest') >>> suite.run(unittest.TestResult()) @@ -2226,7 +2224,7 @@ ... suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', ... 'test_doctest4.txt', - ... package='test') + ... package='test.doctest') ... suite.run(unittest.TestResult()) ... finally: ... if added_loader: @@ -2236,7 +2234,7 @@ '/' 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 = doctest.DocFileSuite('../test/doctest/test_doctest.txt') >>> suite.run(unittest.TestResult()) @@ -2246,7 +2244,7 @@ >>> import types, os.path, test.test_doctest >>> save_argv = sys.argv >>> sys.argv = [test.test_doctest.__file__] - >>> suite = doctest.DocFileSuite('test_doctest.txt', + >>> suite = doctest.DocFileSuite('doctest/test_doctest.txt', ... package=types.ModuleType('__main__')) >>> sys.argv = save_argv @@ -2259,7 +2257,7 @@ >>> test_pkg_path = os.path.split(test_doctest_path)[0] >>> # Use it to find the absolute path of test_doctest.txt. - >>> test_file = os.path.join(test_pkg_path, 'test_doctest.txt') + >>> test_file = os.path.join(test_pkg_path, 'doctest/test_doctest.txt') >>> suite = doctest.DocFileSuite(test_file, module_relative=False) >>> suite.run(unittest.TestResult()) @@ -2277,6 +2275,7 @@ >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', ... 'test_doctest4.txt', + ... package='test.doctest', ... globs={'favorite_color': 'blue'}) >>> suite.run(unittest.TestResult()) @@ -2287,6 +2286,7 @@ >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', ... 'test_doctest4.txt', + ... package='test.doctest', ... optionflags=doctest.DONT_ACCEPT_BLANKLINE, ... globs={'favorite_color': 'blue'}) >>> suite.run(unittest.TestResult()) @@ -2307,6 +2307,7 @@ >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', ... 'test_doctest4.txt', + ... package='test.doctest', ... setUp=setUp, tearDown=tearDown) >>> suite.run(unittest.TestResult()) @@ -2326,7 +2327,8 @@ >>> def setUp(test): ... test.globs['favorite_color'] = 'blue' - >>> suite = doctest.DocFileSuite('test_doctest.txt', setUp=setUp) + >>> suite = doctest.DocFileSuite('doctest/test_doctest.txt', + ... setUp=setUp) >>> suite.run(unittest.TestResult()) @@ -2338,7 +2340,7 @@ `__file__` global, which is set to the name of the file containing the tests: - >>> suite = doctest.DocFileSuite('test_doctest3.txt') + >>> suite = doctest.DocFileSuite('doctest/test_doctest3.txt') >>> suite.run(unittest.TestResult()) @@ -2349,6 +2351,7 @@ >>> suite = doctest.DocFileSuite('test_doctest.txt', ... 'test_doctest2.txt', ... 'test_doctest4.txt', + ... package='test.doctest', ... encoding='utf-8') >>> suite.run(unittest.TestResult()) @@ -2373,7 +2376,7 @@ output without the flag. The file test_doctest.txt file has two tests. They both fail if blank lines are disabled: - >>> suite = doctest.DocFileSuite('test_doctest.txt', + >>> suite = doctest.DocFileSuite('doctest/test_doctest.txt', ... optionflags=doctest.DONT_ACCEPT_BLANKLINE) >>> import unittest >>> result = suite.run(unittest.TestResult()) @@ -2409,7 +2412,7 @@ If we give any reporting options when we set up the tests, however: - >>> suite = doctest.DocFileSuite('test_doctest.txt', + >>> suite = doctest.DocFileSuite('doctest/test_doctest.txt', ... optionflags=doctest.DONT_ACCEPT_BLANKLINE | doctest.REPORT_NDIFF) Then the default eporting options are ignored: @@ -2453,7 +2456,7 @@ ... sys.argv = [arg for arg in save_argv if arg != '-v'] - >>> doctest.testfile('test_doctest.txt') # doctest: +ELLIPSIS + >>> doctest.testfile('doctest/test_doctest.txt') # doctest: +ELLIPSIS ********************************************************************** File "...", line 6, in test_doctest.txt Failed example: @@ -2475,12 +2478,12 @@ Globals may be specified with the `globs` and `extraglobs` parameters: >>> globs = {'favorite_color': 'blue'} - >>> doctest.testfile('test_doctest.txt', globs=globs) + >>> doctest.testfile('doctest/test_doctest.txt', globs=globs) TestResults(failed=0, attempted=2) >>> doctest.master = None # Reset master. >>> extraglobs = {'favorite_color': 'red'} - >>> doctest.testfile('test_doctest.txt', globs=globs, + >>> doctest.testfile('doctest/test_doctest.txt', globs=globs, ... extraglobs=extraglobs) # doctest: +ELLIPSIS ********************************************************************** File "...", line 6, in test_doctest.txt @@ -2500,14 +2503,14 @@ The file may be made relative to a given module or package, using the optional `module_relative` parameter: - >>> doctest.testfile('test_doctest.txt', globs=globs, + >>> doctest.testfile('doctest/test_doctest.txt', globs=globs, ... module_relative='test') TestResults(failed=0, attempted=2) >>> doctest.master = None # Reset master. Verbosity can be increased with the optional `verbose` parameter: - >>> doctest.testfile('test_doctest.txt', globs=globs, verbose=True) + >>> doctest.testfile('doctest/test_doctest.txt', globs=globs, verbose=True) Trying: favorite_color Expecting: @@ -2534,7 +2537,7 @@ The name of the test may be specified with the optional `name` parameter: - >>> doctest.testfile('test_doctest.txt', name='newname') + >>> doctest.testfile('doctest/test_doctest.txt', name='newname') ... # doctest: +ELLIPSIS ********************************************************************** File "...", line 6, in newname @@ -2545,7 +2548,7 @@ The summary report may be suppressed with the optional `report` parameter: - >>> doctest.testfile('test_doctest.txt', report=False) + >>> doctest.testfile('doctest/test_doctest.txt', report=False) ... # doctest: +ELLIPSIS ********************************************************************** File "...", line 6, in test_doctest.txt @@ -2561,7 +2564,7 @@ exception on the first error (which may be useful for postmortem debugging): - >>> doctest.testfile('test_doctest.txt', raise_on_error=True) + >>> doctest.testfile('doctest/test_doctest.txt', raise_on_error=True) ... # doctest: +ELLIPSIS Traceback (most recent call last): doctest.UnexpectedException: ... @@ -2571,7 +2574,7 @@ it's unknown which encoding is used. The encoding can be specified using the optional keyword argument `encoding`: - >>> doctest.testfile('test_doctest4.txt', encoding='latin-1') # doctest: +ELLIPSIS + >>> doctest.testfile('doctest/test_doctest4.txt', encoding='latin-1') # doctest: +ELLIPSIS ********************************************************************** File "...", line 7, in test_doctest4.txt Failed example: @@ -2589,13 +2592,13 @@ TestResults(failed=2, attempted=2) >>> doctest.master = None # Reset master. - >>> doctest.testfile('test_doctest4.txt', encoding='utf-8') + >>> doctest.testfile('doctest/test_doctest4.txt', encoding='utf-8') TestResults(failed=0, attempted=2) >>> doctest.master = None # Reset master. Test the verbose output: - >>> doctest.testfile('test_doctest4.txt', encoding='utf-8', verbose=True) + >>> doctest.testfile('doctest/test_doctest4.txt', encoding='utf-8', verbose=True) Trying: 'föö' Expecting: diff --git a/Lib/test/test_zipimport_support.py b/Lib/test/test_zipimport_support.py --- a/Lib/test/test_zipimport_support.py +++ b/Lib/test/test_zipimport_support.py @@ -29,7 +29,8 @@ # test_cmd_line_script (covers the zipimport support in runpy) # Retrieve some helpers from other test cases -from test import (test_doctest, sample_doctest, sample_doctest_no_doctests, +from test import test_doctest +from test.doctest import (sample_doctest, sample_doctest_no_doctests, sample_doctest_no_docstrings) @@ -104,7 +105,7 @@ "import test_zipped_doctest as test_doctest") test_src = test_src.replace("test.test_doctest", "test_zipped_doctest") - test_src = test_src.replace("test.sample_doctest", + test_src = test_src.replace("test.doctest.sample_doctest", "sample_zipped_doctest") # The sample doctest files rewritten to include in the zipped version. sample_sources = {} @@ -113,7 +114,7 @@ src = inspect.getsource(mod) src = src.replace("test.test_doctest", "test_zipped_doctest") # Rewrite the module name so that, for example, - # "test.sample_doctest" becomes "sample_zipped_doctest". + # "test.doctest.sample_doctest" becomes "sample_zipped_doctest". mod_name = mod.__name__.split(".")[-1] mod_name = mod_name.replace("sample_", "sample_zipped_") sample_sources[mod_name] = src