Skip to content

Commit 32b13bf

Browse files
committed
blackifying tests
1 parent 938be79 commit 32b13bf

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

docs/contributing.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Steps to develop the theme
114114
2. Install theme dependencies
115115
3. Run development server
116116
4. Build production assets
117+
5. Install the testing infrastructure
117118

118119
.. Attention::
119120

@@ -189,6 +190,28 @@ run:
189190
yarn build:production
190191
191192
193+
Install the test infrastructure
194+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195+
196+
This theme uses ``pytest`` for its testing, with a lightweight fixture defined
197+
in the ``test_build.py`` script that makes it easy to run a Sphinx build using
198+
this theme and inspect the results.
199+
200+
In addition, we use `pytest-regressions <https://pytest-regressions.readthedocs.io/en/latest/>`_
201+
to ensure that the HTML generated by the theme is what we'd expect. This module
202+
provides a ``file_regression`` fixture that will check the contents of an object
203+
against a reference file on disk. If the structure of the two differs, then the
204+
test will fail. If we *expect* the structure to differ, then delete the file on
205+
disk and run the test. A new file will be created, and subsequent tests will pass.
206+
207+
Install the testing dependencies with:
208+
209+
.. code-block:: bash
210+
211+
pip install pytest pytest-regressions
212+
213+
Then run the tests by calling ``pytest`` from the repository root.
214+
192215
Changing fonts
193216
--------------
194217

tests/sites/base/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@
1717
html_sourcelink_suffix = ""
1818

1919
# Base options, we can add other key/vals later
20-
html_theme_options = {
21-
}
20+
html_theme_options = {}

tests/test_build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def test_build_book(file_regression, sphinx_build):
6363

6464
# Sidebar subpage
6565
sidebar = subpage_html.select(".bd-sidebar")[0]
66-
file_regression.check(sidebar.prettify(), basename="sidebar_subpage", extension=".html")
66+
file_regression.check(
67+
sidebar.prettify(), basename="sidebar_subpage", extension=".html"
68+
)
6769

6870
sphinx_build.clean()

0 commit comments

Comments
 (0)