Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de52aae

Browse filesBrowse files
committed
tests and cleaner div
1 parent 2f5c51c commit de52aae
Copy full SHA for de52aae

File tree

Expand file treeCollapse file tree

3 files changed

+41
-22
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+41
-22
lines changed

‎sphinx_gallery/backreferences.py

Copy file name to clipboardExpand all lines: sphinx_gallery/backreferences.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
2828
<div class="sphx-glr-thumbnails">
2929
30+
.. thumbnail-parent-div-open
3031
"""
3132

3233
THUMBNAIL_PARENT_DIV_CLOSE = """
34+
.. thumbnail-parent-div-close
35+
3336
.. raw:: html
3437
3538
</div>

‎sphinx_gallery/directives.py

Copy file name to clipboardExpand all lines: sphinx_gallery/directives.py
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,21 @@ def get_backrefs(obj):
8888
path if (os.path.isfile(path) and os.path.getsize(path) > 0) else False
8989
)
9090

91-
example_dirs = config.sphinx_gallery_conf["examples_dirs"]
91+
example_dirs = [
92+
os.path.normpath(os.path.join(src_dir, edir))
93+
for edir in config.sphinx_gallery_conf["examples_dirs"]
94+
]
9295
gallery_dirs = config.sphinx_gallery_conf["gallery_dirs"]
9396

97+
lines.append(THUMBNAIL_PARENT_DIV)
9498
for obj in obj_list:
95-
print(f"obj_list: {obj}")
9699
if paths := glob.glob(path := os.path.normpath(os.path.join(src_dir, obj))):
97100
# index of example dir that matches one of the dirs in path
98-
ix = [i for i, e in enumerate(example_dirs) if obj.startswith(e)]
99-
target_dir = gallery_dirs[ix[0]]
101+
ix = [i for i, e in enumerate(example_dirs) if path.startswith(e)]
102+
target_dir = os.path.normpath(
103+
os.path.join(src_dir, gallery_dirs[ix[0]])
104+
)
100105

101-
lines.append(THUMBNAIL_PARENT_DIV)
102106
for p in paths:
103107
# figure out what's causing animation to be weird here
104108
_, script_blocks = split_code_and_text_blocks(p, return_node=False)
@@ -109,20 +113,21 @@ def get_backrefs(obj):
109113
target_dir, src_dir, p.split(os.sep)[-1], intro, title
110114
)
111115
lines.append(thumbnail)
112-
lines.append(THUMBNAIL_PARENT_DIV_CLOSE)
113-
114116
elif path := get_backrefs(obj):
115117
# Insert the backreferences file(s) using the `include` directive.
116118
# This already includes the opening <div class="sphx-glr-thumbnails">
117119
# and its closing </div>.
120+
118121
lines.append(
119122
f"""\
120123
.. include:: {path}
121-
:start-after: start-sphx-glr-thumbnails"""
124+
:start-after: thumbnail-parent-div-open
125+
:end-before: thumbnail-parent-div-close"""
122126
)
123127
else:
124128
path = ""
125129

130+
lines.append(THUMBNAIL_PARENT_DIV_CLOSE)
126131
text = "\n".join(lines)
127132
include_lines = statemachine.string2lines(text, convert_whitespace=True)
128133
self.state_machine.insert_input(include_lines, path)

‎sphinx_gallery/tests/test_full.py

Copy file name to clipboardExpand all lines: sphinx_gallery/tests/test_full.py
+25-14Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,31 +1066,38 @@ def test_backreference_labels(sphinx_app):
10661066

10671067

10681068
@pytest.mark.parametrize(
1069-
"test, nlines, filenamesortkey",
1069+
"test, nlines, sortkey",
10701070
[
10711071
# first example, no heading
1072-
("Test 1-N", 5, False),
1072+
("Test 1-N", 4, "explicit"),
10731073
# first example, default heading, default level
1074-
("Test 1-D-D", 7, False),
1074+
("Test 1-D-D", 6, "explicit"),
10751075
# first example, default heading, custom level
1076-
("Test 1-D-C", 7, False),
1076+
("Test 1-D-C", 6, "explicit"),
10771077
# first example, custom heading, default level
1078-
("Test 1-C-D", 8, False),
1078+
("Test 1-C-D", 8, "explicit"),
10791079
# both examples, no heading
1080-
("Test 2-N", 10, True),
1080+
("Test 2-N", 7, "filename"),
10811081
# both examples, default heading, default level
1082-
("Test 2-D-D", 13, True),
1082+
("Test 2-D-D", 10, "filename"),
10831083
# both examples, custom heading, custom level
1084-
("Test 2-C-C", 14, True),
1084+
("Test 2-C-C", 11, "filename"),
1085+
# filepath, no heading
1086+
("Test 1-F", 3, None),
1087+
# glob, no heading
1088+
("Test 2-F-G", 10, None),
1089+
# all files
1090+
("Test 3-F-G-B", 21, "all"),
10851091
],
10861092
)
1087-
def test_minigallery_directive(sphinx_app, test, nlines, filenamesortkey):
1093+
def test_minigallery_directive(sphinx_app, test, nlines, sortkey):
10881094
"""Tests the functionality of the minigallery directive."""
10891095
out_dir = sphinx_app.outdir
10901096

10911097
minigallery_html = op.join(out_dir, "minigallery.html")
10921098
with codecs.open(minigallery_html, "r", "utf-8") as fid:
10931099
lines = fid.readlines()
1100+
10941101
# Regular expressions for matching
10951102
any_heading = re.compile(r"<h([1-6])>.+<\/h\1>")
10961103
explicitorder_example = re.compile(
@@ -1108,6 +1115,9 @@ def test_minigallery_directive(sphinx_app, test, nlines, filenamesortkey):
11081115
"Test 2-N": None,
11091116
"Test 2-D-D": r"<h2>Examples using one of multiple objects.*<\/h2>",
11101117
"Test 2-C-C": r"<h1>This is a different custom heading.*<\/h1>",
1118+
"Test 1-F": None,
1119+
"Test 2-F-G": None,
1120+
"Test 3-F-G-B": r"<h2>All the input types.*<\/h2>",
11111121
}
11121122
for i in range(len(lines)):
11131123
if test in lines[i]:
@@ -1122,11 +1132,12 @@ def test_minigallery_directive(sphinx_app, test, nlines, filenamesortkey):
11221132
assert any_heading.search(text) is None
11231133

11241134
# Check for examples
1125-
assert explicitorder_example.search(text) is not None
1126-
if filenamesortkey:
1127-
assert filenamesortkey_example.search(text) is not None
1128-
else:
1129-
assert filenamesortkey_example.search(text) is None
1135+
if sortkey in ["filename", "explicit", "all"]:
1136+
assert explicitorder_example.search(text) is not None
1137+
if sortkey == ["filename", "all"]:
1138+
assert filenamesortkey_example.search(text) is not None
1139+
elif sortkey == "explicit":
1140+
assert filenamesortkey_example.search(text) is None
11301141

11311142

11321143
def test_matplotlib_warning_filter(sphinx_app):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.