diff -r 02d6d3a7a181 Lib/test/doctest/doctest_aliases.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/doctest_aliases.py Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,13 @@ +# Used by test_doctest.py. + +class TwoNames: + '''f() and g() are two names for the same method''' + + def f(self): + ''' + >>> print(TwoNames().f()) + f + ''' + return 'f' + + g = f # define an alias for f diff -r 02d6d3a7a181 Lib/test/doctest/sample_doctest.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/sample_doctest.py Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,76 @@ +"""This is a sample module that doesn't really test anything all that + interesting. + +It simply has a few tests, some of which succeed and some of which fail. + +It's important that the numbers remain constant as another test is +testing the running of these tests. + + +>>> 2+2 +4 +""" + + +def foo(): + """ + + >>> 2+2 + 5 + + >>> 2+2 + 4 + """ + +def bar(): + """ + + >>> 2+2 + 4 + """ + +def test_silly_setup(): + """ + + >>> import test.test_doctest + >>> test.test_doctest.sillySetup + True + """ + +def w_blank(): + """ + >>> if 1: + ... print('a') + ... print() + ... print('b') + a + + b + """ + +x = 1 +def x_is_one(): + """ + >>> x + 1 + """ + +def y_is_one(): + """ + >>> y + 1 + """ + +__test__ = {'good': """ + >>> 42 + 42 + """, + 'bad': """ + >>> 42 + 666 + """, + } + +def test_suite(): + import doctest + return doctest.DocTestSuite() diff -r 02d6d3a7a181 Lib/test/doctest/sample_doctest_no_docstrings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/sample_doctest_no_docstrings.py Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,12 @@ +# This is a sample module used for testing doctest. +# +# This module is for testing how doctest handles a module with no +# docstrings. + + +class Foo(object): + + # A class with no docstring. + + def __init__(self): + pass diff -r 02d6d3a7a181 Lib/test/doctest/sample_doctest_no_doctests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/sample_doctest_no_doctests.py Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,15 @@ +"""This is a sample module used for testing doctest. + +This module is for testing how doctest handles a module with docstrings +but no doctest examples. + +""" + + +class Foo(object): + """A docstring with no doctest examples. + + """ + + def __init__(self): + pass diff -r 02d6d3a7a181 Lib/test/doctest/test_doctest.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/test_doctest.txt Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,17 @@ +This is a sample doctest in a text file. + +In this example, we'll rely on a global variable being set for us +already: + + >>> favorite_color + 'blue' + +We can make this fail by disabling the blank-line feature. + + >>> if 1: + ... print('a') + ... print() + ... print('b') + a + + b diff -r 02d6d3a7a181 Lib/test/doctest/test_doctest2.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/test_doctest2.txt Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,14 @@ +This is a sample doctest in a text file. + +In this example, we'll rely on some silly setup: + + >>> import test.test_doctest + >>> test.test_doctest.sillySetup + True + +This test also has some (random) encoded (utf-8) unicode text: + + ЉЊЈЁЂ + +This doesn't cause a problem in the tect surrounding the examples, but +we include it here (in this test text file) to make sure. :) diff -r 02d6d3a7a181 Lib/test/doctest/test_doctest3.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/test_doctest3.txt Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,5 @@ + +Here we check that `__file__` is provided: + + >>> type(__file__) + diff -r 02d6d3a7a181 Lib/test/doctest/test_doctest4.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest/test_doctest4.txt Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,11 @@ +This is a sample doctest in a text file that contains non-ASCII characters. +This file is encoded using UTF-8. + +In order to get this test to pass, we have to manually specify the +encoding. + + >>> 'föö' + 'f\xf6\xf6' + + >>> 'bąr' + 'b\u0105r' diff -r 02d6d3a7a181 Lib/test/doctest_DocFileSuite_test.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/doctest_DocFileSuite_test.txt Sat Aug 02 16:24:15 2014 +0300 @@ -0,0 +1,1 @@ +This is here just to test test_doctest.DocFileSuite file loader. diff -r 02d6d3a7a181 Lib/test/doctest_aliases.py --- a/Lib/test/doctest_aliases.py Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -# Used by test_doctest.py. - -class TwoNames: - '''f() and g() are two names for the same method''' - - def f(self): - ''' - >>> print(TwoNames().f()) - f - ''' - return 'f' - - g = f # define an alias for f diff -r 02d6d3a7a181 Lib/test/sample_doctest.py --- a/Lib/test/sample_doctest.py Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -"""This is a sample module that doesn't really test anything all that - interesting. - -It simply has a few tests, some of which succeed and some of which fail. - -It's important that the numbers remain constant as another test is -testing the running of these tests. - - ->>> 2+2 -4 -""" - - -def foo(): - """ - - >>> 2+2 - 5 - - >>> 2+2 - 4 - """ - -def bar(): - """ - - >>> 2+2 - 4 - """ - -def test_silly_setup(): - """ - - >>> import test.test_doctest - >>> test.test_doctest.sillySetup - True - """ - -def w_blank(): - """ - >>> if 1: - ... print('a') - ... print() - ... print('b') - a - - b - """ - -x = 1 -def x_is_one(): - """ - >>> x - 1 - """ - -def y_is_one(): - """ - >>> y - 1 - """ - -__test__ = {'good': """ - >>> 42 - 42 - """, - 'bad': """ - >>> 42 - 666 - """, - } - -def test_suite(): - import doctest - return doctest.DocTestSuite() diff -r 02d6d3a7a181 Lib/test/sample_doctest_no_docstrings.py --- a/Lib/test/sample_doctest_no_docstrings.py Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -# This is a sample module used for testing doctest. -# -# This module is for testing how doctest handles a module with no -# docstrings. - - -class Foo(object): - - # A class with no docstring. - - def __init__(self): - pass diff -r 02d6d3a7a181 Lib/test/sample_doctest_no_doctests.py --- a/Lib/test/sample_doctest_no_doctests.py Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -"""This is a sample module used for testing doctest. - -This module is for testing how doctest handles a module with docstrings -but no doctest examples. - -""" - - -class Foo(object): - """A docstring with no doctest examples. - - """ - - def __init__(self): - pass diff -r 02d6d3a7a181 Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Sat Aug 02 01:30:37 2014 -0400 +++ b/Lib/test/test_doctest.py Sat Aug 02 16:24:15 2014 +0300 @@ -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 -r 02d6d3a7a181 Lib/test/test_doctest.txt --- a/Lib/test/test_doctest.txt Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -This is a sample doctest in a text file. - -In this example, we'll rely on a global variable being set for us -already: - - >>> favorite_color - 'blue' - -We can make this fail by disabling the blank-line feature. - - >>> if 1: - ... print('a') - ... print() - ... print('b') - a - - b diff -r 02d6d3a7a181 Lib/test/test_doctest2.txt --- a/Lib/test/test_doctest2.txt Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -This is a sample doctest in a text file. - -In this example, we'll rely on some silly setup: - - >>> import test.test_doctest - >>> test.test_doctest.sillySetup - True - -This test also has some (random) encoded (utf-8) unicode text: - - ЉЊЈЁЂ - -This doesn't cause a problem in the tect surrounding the examples, but -we include it here (in this test text file) to make sure. :) diff -r 02d6d3a7a181 Lib/test/test_doctest3.txt --- a/Lib/test/test_doctest3.txt Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ - -Here we check that `__file__` is provided: - - >>> type(__file__) - diff -r 02d6d3a7a181 Lib/test/test_doctest4.txt --- a/Lib/test/test_doctest4.txt Sat Aug 02 01:30:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -This is a sample doctest in a text file that contains non-ASCII characters. -This file is encoded using UTF-8. - -In order to get this test to pass, we have to manually specify the -encoding. - - >>> 'föö' - 'f\xf6\xf6' - - >>> 'bąr' - 'b\u0105r' diff -r 02d6d3a7a181 Lib/test/test_zipimport_support.py --- a/Lib/test/test_zipimport_support.py Sat Aug 02 01:30:37 2014 -0400 +++ b/Lib/test/test_zipimport_support.py Sat Aug 02 16:24:15 2014 +0300 @@ -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