-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Add custom thumbnails for failing examples (#1313)
Co-authored-by: Lucy Liu <jliu176@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
- Loading branch information
1 parent
73b7ec8
commit d2c8e47
Showing
10 changed files
with
181 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Example that fails to execute (with normal thumbnail behaviour) | ||
=============================================================== | ||
By default, examples with code blocks that raise an error will have the broken | ||
image stamp as their gallery thumbnail. However, this may not be desired, e.g. | ||
if only part of the example is expected to fail and it should not look like the | ||
entire example fails. | ||
In these cases, the `sphinx_gallery_failing_thumbnail` variable can be set to | ||
``False``, which will change the thumbnail selection to the default behaviour | ||
as for non-failing examples. | ||
""" | ||
|
||
# Code source: Thomas S. Binns | ||
# License: BSD 3 clause | ||
# sphinx_gallery_line_numbers = True | ||
|
||
# sphinx_gallery_failing_thumbnail = False | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.pcolormesh(np.random.randn(100, 100)) | ||
|
||
# %% | ||
# This block will raise an AssertionError | ||
|
||
assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+20.9 KB
sphinx_gallery/tests/tinybuild/doc/_static_nonstandard/broken_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
sphinx_gallery/tests/tinybuild/examples/plot_failing_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Failing example test | ||
==================== | ||
Test failing thumbnail appears for files in expected_failing_examples. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.pcolormesh(np.random.randn(100, 100)) | ||
|
||
# %% | ||
# will raise AssertionError | ||
|
||
assert False |
18 changes: 18 additions & 0 deletions
18
sphinx_gallery/tests/tinybuild/examples/plot_failing_example_thumbnail.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Failing example test with normal thumbnail behaviour | ||
==================================================== | ||
Test files in expected_failing_examples run, but normal thumbnail behaviour is | ||
retained when sphinx_gallery_failing_thumbnail = False. | ||
""" | ||
|
||
# sphinx_gallery_failing_thumbnail = False | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.pcolormesh(np.random.randn(100, 100)) | ||
|
||
# %% | ||
# will raise AssertionError | ||
|
||
assert False |