|
29 | 29 | # test_cmd_line_script (covers the zipimport support in runpy) |
30 | 30 |
|
31 | 31 | # Retrieve some helpers from other test cases |
32 | | -from test import test_doctest, sample_doctest |
| 32 | +from test import (test_doctest, sample_doctest, sample_doctest_no_doctests, |
| 33 | + sample_doctest_no_docstrings) |
33 | 34 |
|
34 | 35 |
|
35 | 36 | def _run_object_doctest(obj, module): |
@@ -105,16 +106,26 @@ def test_doctest_issue4197(self): |
105 | 106 | "test_zipped_doctest") |
106 | 107 | test_src = test_src.replace("test.sample_doctest", |
107 | 108 | "sample_zipped_doctest") |
108 | | - sample_src = inspect.getsource(sample_doctest) |
109 | | - sample_src = sample_src.replace("test.test_doctest", |
110 | | - "test_zipped_doctest") |
| 109 | + # The sample doctest files rewritten to include in the zipped version. |
| 110 | + sample_sources = {} |
| 111 | + for mod in [sample_doctest, sample_doctest_no_doctests, |
| 112 | + sample_doctest_no_docstrings]: |
| 113 | + src = inspect.getsource(mod) |
| 114 | + src = src.replace("test.test_doctest", "test_zipped_doctest") |
| 115 | + # Rewrite the module name so that, for example, |
| 116 | + # "test.sample_doctest" becomes "sample_zipped_doctest". |
| 117 | + mod_name = mod.__name__.split(".")[-1] |
| 118 | + mod_name = mod_name.replace("sample_", "sample_zipped_") |
| 119 | + sample_sources[mod_name] = src |
| 120 | + |
111 | 121 | with temp_dir() as d: |
112 | 122 | script_name = make_script(d, 'test_zipped_doctest', |
113 | 123 | test_src) |
114 | 124 | zip_name, run_name = make_zip_script(d, 'test_zip', |
115 | 125 | script_name) |
116 | 126 | z = zipfile.ZipFile(zip_name, 'a') |
117 | | - z.writestr("sample_zipped_doctest.py", sample_src) |
| 127 | + for mod_name, src in sample_sources.items(): |
| 128 | + z.writestr(mod_name + ".py", src) |
118 | 129 | z.close() |
119 | 130 | if verbose: |
120 | 131 | zip_file = zipfile.ZipFile(zip_name, 'r') |
|
0 commit comments