MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _run_doctest_impl

Method _run_doctest_impl

test/base/test_tutorials.py:90–155  ·  view source on GitHub ↗
(self, fnames, sqla_base, runner, parser, globs)

Source from the content-addressed store, hash-verified

88 del globs
89
90 def _run_doctest_impl(self, fnames, sqla_base, runner, parser, globs):
91 for fname in fnames:
92 path = os.path.join(sqla_base, "doc/build", fname)
93 if not os.path.exists(path):
94 config.skip_test("Can't find documentation file %r" % path)
95
96 buf = []
97
98 with open(path, encoding="utf-8") as file_:
99
100 def load_include(m):
101 fname = m.group(1)
102 sub_path = os.path.join(os.path.dirname(path), fname)
103 with open(sub_path, encoding="utf-8") as file_:
104 for i, line in enumerate(file_, 1):
105 buf.append((i, line))
106 return fname
107
108 def run_buf(fname, is_include):
109 if not buf:
110 return
111
112 test = parser.get_doctest(
113 "".join(line for _, line in buf),
114 globs,
115 fname,
116 fname,
117 buf[0][0],
118 )
119 buf[:] = []
120 try:
121 runner.run(test, clear_globs=False)
122 globs.update(test.globs)
123 finally:
124 # Clear test object references
125 test.globs.clear()
126 test.examples.clear()
127
128 doctest_enabled = True
129
130 for line_counter, line in enumerate(file_, 1):
131 line = re.sub(
132 r"{(?:stop|sql|opensql|execsql|printsql)}", "", line
133 )
134
135 include = re.match(r"\.\. doctest-include (.+\.rst)", line)
136 if include:
137 run_buf(fname, False)
138 include_fname = load_include(include)
139 run_buf(include_fname, True)
140
141 doctest_disable = re.match(
142 r"\.\. doctest-(enable|disable)", line
143 )
144 if doctest_disable:
145 doctest_enabled = doctest_disable.group(1) == "enable"
146
147 if doctest_enabled:

Callers 1

_run_doctestMethod · 0.95

Calls 7

openFunction · 0.85
skip_testMethod · 0.80
subMethod · 0.80
joinMethod · 0.45
existsMethod · 0.45
matchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected