(self, *fnames)
| 60 | self._teardown_logger() |
| 61 | |
| 62 | def _run_doctest(self, *fnames): |
| 63 | here = os.path.dirname(__file__) |
| 64 | sqla_base = os.path.normpath(os.path.join(here, "..", "..")) |
| 65 | |
| 66 | optionflags = ( |
| 67 | doctest.ELLIPSIS |
| 68 | | doctest.NORMALIZE_WHITESPACE |
| 69 | | doctest.IGNORE_EXCEPTION_DETAIL |
| 70 | ) |
| 71 | runner = doctest.DocTestRunner( |
| 72 | verbose=config.options.verbose >= 2, optionflags=optionflags |
| 73 | ) |
| 74 | parser = doctest.DocTestParser() |
| 75 | globs = {"print_function": print} |
| 76 | |
| 77 | for fname in fnames: |
| 78 | path = os.path.join(sqla_base, "doc/build", fname) |
| 79 | if not os.path.exists(path): |
| 80 | config.skip_test("Can't find documentation file %r" % path) |
| 81 | |
| 82 | buf = [] |
| 83 | |
| 84 | with open(path, encoding="utf-8") as file_: |
| 85 | |
| 86 | def load_include(m): |
| 87 | fname = m.group(1) |
| 88 | sub_path = os.path.join(os.path.dirname(path), fname) |
| 89 | with open(sub_path, encoding="utf-8") as file_: |
| 90 | for i, line in enumerate(file_, 1): |
| 91 | buf.append((i, line)) |
| 92 | return fname |
| 93 | |
| 94 | def run_buf(fname, is_include): |
| 95 | if not buf: |
| 96 | return |
| 97 | |
| 98 | test = parser.get_doctest( |
| 99 | "".join(line for _, line in buf), |
| 100 | globs, |
| 101 | fname, |
| 102 | fname, |
| 103 | buf[0][0], |
| 104 | ) |
| 105 | buf[:] = [] |
| 106 | runner.run(test, clear_globs=False) |
| 107 | globs.update(test.globs) |
| 108 | |
| 109 | doctest_enabled = True |
| 110 | |
| 111 | for line_counter, line in enumerate(file_, 1): |
| 112 | line = re.sub( |
| 113 | r"{(?:stop|sql|opensql|execsql|printsql)}", "", line |
| 114 | ) |
| 115 | |
| 116 | include = re.match(r"\.\. doctest-include (.+\.rst)", line) |
| 117 | if include: |
| 118 | run_buf(fname, False) |
| 119 | include_fname = load_include(include) |
no test coverage detected