diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-10-01 22:24:38 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-10-01 22:36:03 -0400 |
commit | b2c20d8a532dc302ea324ee00b2f18e58b98d382 (patch) | |
tree | ac69338b513f4620b4cf4691c107899302b00465 /test/base/test_tutorials.py | |
parent | befa8e92675dea992423011b929dfc7ca45de6b6 (diff) | |
download | sqlalchemy-b2c20d8a532dc302ea324ee00b2f18e58b98d382.tar.gz |
add disable doctest tag for autodoc test suite
ahead of trying to get everything formatted, some more
flexibility so that we can use doctest for all
python + sql code, while still being able to tell the
test suite to not run doctests on a sample. All of the
"non-console python with SQL" in the docs is because I was
showing an example that I didn't want tested.
Change-Id: Iae876ae1ffd93c36b096c6c2d6048843ae9698c8
Diffstat (limited to 'test/base/test_tutorials.py')
-rw-r--r-- | test/base/test_tutorials.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/test/base/test_tutorials.py b/test/base/test_tutorials.py index 31207c7a5..0d0ed2bd9 100644 --- a/test/base/test_tutorials.py +++ b/test/base/test_tutorials.py @@ -81,37 +81,35 @@ class DocTest(fixtures.TestBase): config.skip_test("Can't find documentation file %r" % path) buf = [] - line_counter = 0 - last_line_counter = 0 + with open(path, encoding="utf-8") as file_: def load_include(m): fname = m.group(1) sub_path = os.path.join(os.path.dirname(path), fname) with open(sub_path, encoding="utf-8") as file_: - for line in file_: - buf.append(line) + for i, line in enumerate(file_, 1): + buf.append((i, line)) return fname def run_buf(fname, is_include): if not buf: return - nonlocal last_line_counter + test = parser.get_doctest( - "".join(buf), + "".join(line for _, line in buf), globs, fname, fname, - last_line_counter if not is_include else 0, + buf[0][0], ) buf[:] = [] runner.run(test, clear_globs=False) globs.update(test.globs) - if not is_include: - last_line_counter = line_counter + doctest_enabled = True - for line in file_: + for line_counter, line in enumerate(file_, 1): line = re.sub(r"{(?:stop|sql|opensql)}", "", line) include = re.match(r"\.\. doctest-include (.+\.rst)", line) @@ -119,9 +117,17 @@ class DocTest(fixtures.TestBase): run_buf(fname, False) include_fname = load_include(include) run_buf(include_fname, True) + + doctest_disable = re.match( + r"\.\. doctest-(enable|disable)", line + ) + if doctest_disable: + doctest_enabled = doctest_disable.group(1) == "enable" + + if doctest_enabled: + buf.append((line_counter, line)) else: - buf.append(line) - line_counter += 1 + buf.append((line_counter, "\n")) run_buf(fname, False) |