Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 14f16cd

Browse files
committed
tests: docs: consoletest: Do not use Sphinx builder interface
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
1 parent 5709ada commit 14f16cd

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

docs/tutorials/models/package.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ Let's add some training data to a CSV file.
236236
**train.csv**
237237

238238
.. code-block::
239+
:test:
239240
:filepath: train.csv
240241
241242
Years,Salary

docs/tutorials/models/slr.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Let's first create our training, test, and prediction data CSV files.
183183
**train.csv**
184184

185185
.. code-block::
186+
:test:
186187
:filepath: train.csv
187188
188189
Years,Salary
@@ -195,6 +196,7 @@ Let's first create our training, test, and prediction data CSV files.
195196
**test.csv**
196197

197198
.. code-block::
199+
:test:
198200
:filepath: test.csv
199201
200202
Years,Salary
@@ -204,6 +206,7 @@ Let's first create our training, test, and prediction data CSV files.
204206
**predict.csv**
205207

206208
.. code-block::
209+
:test:
207210
:filepath: predict.csv
208211
209212
Years

docs/tutorials/sources/file.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Add configuration
5353

5454
**dffml_source_ini/misc.py**
5555

56-
.. literalinclude:: ../../../dffml/source/ini.py
56+
.. literalinclude:: /../dffml/source/ini.py
5757
:test:
5858
:filepath: dffml_source_ini/misc.py
5959
:lines: 11-15
@@ -67,7 +67,7 @@ Create Source
6767

6868
**dffml_source_ini/misc.py**
6969

70-
.. literalinclude:: ../../../dffml/source/ini.py
70+
.. literalinclude:: /../dffml/source/ini.py
7171
:test:
7272
:filepath: dffml_source_ini/misc.py
7373
:lines: 18-24
@@ -92,7 +92,7 @@ Add load method
9292

9393
**dffml_source_ini/misc.py**
9494

95-
.. literalinclude:: ../../../dffml/source/ini.py
95+
.. literalinclude:: /../dffml/source/ini.py
9696
:test:
9797
:filepath: dffml_source_ini/misc.py
9898
:lines: 26-47
@@ -116,7 +116,7 @@ Add dump method
116116

117117
**dffml_source_ini/misc.py**
118118

119-
.. literalinclude:: ../../../dffml/source/ini.py
119+
.. literalinclude:: /../dffml/source/ini.py
120120
:test:
121121
:filepath: dffml_source_ini/misc.py
122122
:lines: 49-66
@@ -153,7 +153,7 @@ test methods as coroutines in default event loop.
153153

154154
**tests/test_source.py**
155155

156-
.. literalinclude:: ../../../tests/source/test_ini.py
156+
.. literalinclude:: /../tests/source/test_ini.py
157157
:test:
158158
:filepath: tests/test_source.py
159159
:lines: 10-30

tests/docs/test_consoletest.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tempfile
66
import unittest
77
import contextlib
8+
import dataclasses
89
import unittest.mock
910
import importlib.util
1011

@@ -27,7 +28,7 @@
2728
setattr(sys.modules[__name__], module_name, module)
2829

2930

30-
class TestDocs(unittest.TestCase):
31+
class TestDocs(AsyncTestCase):
3132
"""
3233
A testcase for each doc will be added to this class
3334
"""
@@ -67,9 +68,20 @@ def test__all_docs_being_tested(self):
6768
self.assertListEqual(should_have, docs)
6869

6970

70-
def mktestcase(filepath: pathlib.Path, relative: pathlib.Path):
71-
# The test case itself, assigned to test_doctest of each class
72-
def testcase(self):
71+
def mktestcase(filepath: pathlib.Path, relative: pathlib.Path, builder: bool):
72+
async def testcase(self):
73+
return await consoletest_doc(
74+
[
75+
str(filepath.resolve()),
76+
"--root",
77+
str(ROOT_PATH),
78+
"--docs",
79+
str(DOCS_PATH),
80+
*args,
81+
]
82+
)
83+
84+
def builder_testcase(self):
7385
from sphinx.cmd.build import (
7486
get_parser,
7587
Tee,
@@ -137,6 +149,8 @@ def pickle_load(fileobj):
137149
app.build(False, [])
138150
self.assertFalse(app.statuscode)
139151

152+
if builder:
153+
return builder_testcase
140154
return testcase
141155

142156

@@ -149,23 +163,26 @@ def pickle_load(fileobj):
149163
relative = filepath.relative_to(DOCS_PATH).with_suffix("")
150164
if str(relative) in SKIP_DOCS:
151165
continue
152-
TestDocs.TESTABLE_DOCS.append(str(relative))
153-
name = "test_" + str(relative).replace(os.sep, "_")
154-
# Do not add the tests if we are running with GitHub Actions for the main
155-
# package. This is because there are seperate jobs for each tutorial test
156-
# and the TestDocs.test__all_docs_being_tested ensures that we are running a
157-
# job for each tutorial
158-
if (
159-
"GITHUB_ACTIONS" in os.environ
160-
and "PLUGIN" in os.environ
161-
and os.environ["PLUGIN"] == "."
162-
):
163-
continue
164-
setattr(
165-
TestDocs,
166-
name,
167-
unittest.skipIf(
166+
# Create the testcase
167+
testcase = mktestcase(filepath, relative, True)
168+
if True:
169+
# Don't check for a long test entry in the workflow if doc in NO_SETUP
170+
TestDocs.TESTABLE_DOCS.append(str(relative))
171+
# Skip if not in NO_SETUP and RUN_CONSOLETESTS not set
172+
testcase = unittest.skipIf(
168173
"RUN_CONSOLETESTS" not in os.environ,
169174
"RUN_CONSOLETESTS environment variable not set",
170-
)(mktestcase(filepath, relative)),
171-
)
175+
)(testcase)
176+
# Do not add the tests if we are running with GitHub Actions for the main
177+
# package. This is because there are seperate jobs for each tutorial test
178+
# and the TestDocs.test__all_docs_being_tested ensures that we are running a
179+
# job for each tutorial
180+
if (
181+
"GITHUB_ACTIONS" in os.environ
182+
and "PLUGIN" in os.environ
183+
and os.environ["PLUGIN"] == "."
184+
):
185+
continue
186+
# Add the testcase
187+
name = "test_" + str(relative).replace(os.sep, "_")
188+
setattr(TestDocs, name, testcase)

0 commit comments

Comments
 (0)