Skip to content

Commit 5564197

Browse files
dgarcia360foster999
authored andcommitted
🧪 TESTS: Add tests for disable_css_loading option
1 parent 54776a3 commit 5564197

File tree

7 files changed

+112
-7
lines changed

7 files changed

+112
-7
lines changed

‎sphinx_tabs/tabs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,13 @@ def update_config(app, config):
299299
app.add_css_file(path.as_posix())
300300
else:
301301
app.add_stylesheet(path.as_posix())
302-
if path.suffix == ".js":
302+
if path.suffix == ".js":
303303
if "add_script_file" in dir(app):
304304
app.add_script_file(path.as_posix())
305305
else:
306306
app.add_js_file(path.as_posix())
307307

308+
308309
# pylint: disable=unused-argument
309310
def update_context(app, pagename, templatename, context, doctree):
310311
"""Remove sphinx-tabs CSS and JS asset files if not used in a page"""

‎tests/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ def check_asset_links(get_sphinx_app_output):
130130
"""
131131

132132
def check(
133-
app, buildername="html", filename="index.html", encoding="utf-8", present=True
133+
app,
134+
buildername="html",
135+
filename="index.html",
136+
encoding="utf-8",
137+
cssPresent=True,
138+
jsPresent=True,
134139
):
135140
content = get_sphinx_app_output(app, buildername, filename, encoding)
136141

@@ -146,13 +151,16 @@ def check(
146151

147152
all_refs = css_refs + js_refs
148153

149-
if present:
154+
if cssPresent:
150155
css_present = all(any(a in ref for ref in all_refs) for a in css_assets)
151-
js_present = all(any(a in ref for ref in js_refs) for a in js_assets)
152156
assert css_present
157+
else:
158+
assert not "sphinx_tabs" in css_refs
159+
if jsPresent:
160+
js_present = all(any(a in ref for ref in js_refs) for a in js_assets)
153161
assert js_present
154162
else:
155-
assert not "sphinx_tabs" in css_refs + js_refs
163+
assert not "sphinx_tabs" in js_refs
156164

157165
return check
158166

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
project = "sphinx-tabs test"
2+
master_doc = "index"
3+
source_suffix = ".rst"
4+
extensions = ["sphinx_tabs.tabs"]
5+
pygments_style = "sphinx"
6+
7+
sphinx_tabs_disable_css_loading = True
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. tabs::
2+
3+
.. tab:: Apples
4+
5+
Apples are green, or sometimes red.
6+
7+
.. tab:: Pears
8+
9+
Pears are green.
10+
11+
.. tab:: Oranges
12+
13+
Oranges are orange.
14+
15+
.. tab:: 404
16+
17+
A number in the name.

‎tests/test_build.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_basic():
1010

1111
@pytest.mark.sphinx(testroot="notabs")
1212
def test_no_tabs(app, check_asset_links):
13-
check_asset_links(app, present=False)
13+
check_asset_links(app, cssPresent=False, jsPresent=False)
1414

1515

1616
@pytest.mark.parametrize("docname", ["index", "no_tabs1", "no_tabs2"])
@@ -19,7 +19,9 @@ def test_conditional_assets(app, docname, check_asset_links):
1919
if docname == "index":
2020
check_asset_links(app)
2121
else:
22-
check_asset_links(app, filename=docname + ".html", present=False)
22+
check_asset_links(
23+
app, filename=docname + ".html", cssPresent=False, jsPresent=False
24+
)
2325

2426

2527
@pytest.mark.sphinx(testroot="linenos")
@@ -62,3 +64,8 @@ def test_rinohtype_pdf(
6264
@pytest.mark.sphinx(testroot="disable-closing")
6365
def test_disable_closing(app, check_asset_links):
6466
check_asset_links(app)
67+
68+
69+
@pytest.mark.sphinx(testroot="disable-css-loading")
70+
def test_disable_css_loading(app, check_asset_links):
71+
check_asset_links(app, cssPresent=False)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div class="documentwrapper">
2+
<div class="bodywrapper">
3+
<div class="body" role="main">
4+
<div class="sphinx-tabs docutils container">
5+
<div aria-label="Tabbed content" class="closeable" role="tablist">
6+
<button aria-controls="panel-0-0-0" aria-selected="true" class="sphinx-tabs-tab" id="tab-0-0-0" name="0-0" role="tab" tabindex="0">
7+
Apples
8+
</button>
9+
<button aria-controls="panel-0-0-1" aria-selected="false" class="sphinx-tabs-tab" id="tab-0-0-1" name="0-1" role="tab" tabindex="-1">
10+
Pears
11+
</button>
12+
<button aria-controls="panel-0-0-2" aria-selected="false" class="sphinx-tabs-tab" id="tab-0-0-2" name="0-2" role="tab" tabindex="-1">
13+
Oranges
14+
</button>
15+
<button aria-controls="panel-0-0-3" aria-selected="false" class="sphinx-tabs-tab" id="tab-0-0-3" name="0-3" role="tab" tabindex="-1">
16+
404
17+
</button>
18+
</div>
19+
<div aria-labelledby="tab-0-0-0" class="sphinx-tabs-panel" id="panel-0-0-0" name="0-0" role="tabpanel" tabindex="0">
20+
<p>
21+
Apples are green, or sometimes red.
22+
</p>
23+
</div>
24+
<div aria-labelledby="tab-0-0-1" class="sphinx-tabs-panel" hidden="true" id="panel-0-0-1" name="0-1" role="tabpanel" tabindex="0">
25+
<p>
26+
Pears are green.
27+
</p>
28+
</div>
29+
<div aria-labelledby="tab-0-0-2" class="sphinx-tabs-panel" hidden="true" id="panel-0-0-2" name="0-2" role="tabpanel" tabindex="0">
30+
<p>
31+
Oranges are orange.
32+
</p>
33+
</div>
34+
<div aria-labelledby="tab-0-0-3" class="sphinx-tabs-panel" hidden="true" id="panel-0-0-3" name="0-3" role="tabpanel" tabindex="0">
35+
<p>
36+
A number in the name.
37+
</p>
38+
</div>
39+
</div>
40+
</div>
41+
</div>
42+
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<document source="index.rst">
2+
<container classes="sphinx-tabs" type="tab-element">
3+
<div aria-label="Tabbed content" classes="closeable" role="tablist">
4+
<button aria-controls="panel-0-0-0" aria-selected="true" classes="sphinx-tabs-tab" ids="tab-0-0-0" name="0-0" role="tab" tabindex="0">
5+
Apples
6+
<button aria-controls="panel-0-0-1" aria-selected="false" classes="sphinx-tabs-tab" ids="tab-0-0-1" name="0-1" role="tab" tabindex="-1">
7+
Pears
8+
<button aria-controls="panel-0-0-2" aria-selected="false" classes="sphinx-tabs-tab" ids="tab-0-0-2" name="0-2" role="tab" tabindex="-1">
9+
Oranges
10+
<button aria-controls="panel-0-0-3" aria-selected="false" classes="sphinx-tabs-tab" ids="tab-0-0-3" name="0-3" role="tab" tabindex="-1">
11+
404
12+
<div aria-labelledby="tab-0-0-0" classes="sphinx-tabs-panel" ids="panel-0-0-0" name="0-0" role="tabpanel" tabindex="0">
13+
<paragraph>
14+
Apples are green, or sometimes red.
15+
<div aria-labelledby="tab-0-0-1" classes="sphinx-tabs-panel" hidden="true" ids="panel-0-0-1" name="0-1" role="tabpanel" tabindex="0">
16+
<paragraph>
17+
Pears are green.
18+
<div aria-labelledby="tab-0-0-2" classes="sphinx-tabs-panel" hidden="true" ids="panel-0-0-2" name="0-2" role="tabpanel" tabindex="0">
19+
<paragraph>
20+
Oranges are orange.
21+
<div aria-labelledby="tab-0-0-3" classes="sphinx-tabs-panel" hidden="true" ids="panel-0-0-3" name="0-3" role="tabpanel" tabindex="0">
22+
<paragraph>
23+
A number in the name.

0 commit comments

Comments
 (0)