Skip to content

Commit

Permalink
Tests: explicitly unset SOURCE_DATE_EPOCH during 'test_html_multi_lin…
Browse files Browse the repository at this point in the history
…e_copyright' (#13224)

Sphinx's copyright substitution currently allows years identified as
the current year to be downgraded to previous years when
``SOURCE_DATE_EPOCH`` is configured, to assist reproducibility [1] of
documentation builds.

However, we have a test case ``test_html_multi_line_copyright``,
written in 2024, that mentioned a future year (2025).

Now that we have reached 2025, it is eligible for substitution when
``SOURCE_DATE_EPOCH`` is configured.  Many buildsystems, such as those
used by Debian and Fedora, choose the most-recent packaging/commit
timestamp to use as `SOURCE_DATE_EPOCH`'s timestamp, since those
correspond sensibly to a time-of-build.

However, for the Sphinx 8.1.3 release including the updated
substitution logic, the year-of-release/commit was 2024. Thus, if a
commit/packaging date from that year is chosen, and
``SOURCE_DATE_EPOCH`` is configured when the unit tests run, the
``test_html_multi_line_copyright`` test will fail.

The fix suggested here is to explicitly unset ``SOURCE_DATE_EPOCH``
within ``test_html_multi_line_copyright``.

[1]: https://www.reproducible-builds.org/

Authored-by: Colin Watson <[email protected]>
Co-authored-by: Colin Watson <[email protected]>
Authored-by: James Addison <[email protected]>
Co-authored-by: James Addison <[email protected]>
  • Loading branch information
jayaddison and cjwatson authored Jan 10, 2025
1 parent 95df419 commit 267fe9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ Bugs fixed

Testing
-------

* #13224: Correctness fixup for ``test_html_multi_line_copyright``.
Patch by Colin Watson, applied by James Addison.
14 changes: 13 additions & 1 deletion tests/test_builders/test_build_html_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
LOCALTIME_2009 = type(LT)(LT_NEW)


@pytest.fixture
def no_source_date_year(monkeypatch):
"""
Explicitly clear SOURCE_DATE_EPOCH from the environment; this
fixture can be used to ensure that copyright substitution logic
does not occur during selected test cases.
"""
with monkeypatch.context() as m:
m.delenv('SOURCE_DATE_EPOCH', raising=False)
yield


@pytest.fixture(
params=[
1199145600, # 2008-01-01 00:00:00
Expand All @@ -24,7 +36,7 @@ def source_date_year(request, monkeypatch):


@pytest.mark.sphinx('html', testroot='copyright-multiline')
def test_html_multi_line_copyright(app):
def test_html_multi_line_copyright(no_source_date_year, app):
app.build(force_all=True)

content = (app.outdir / 'index.html').read_text(encoding='utf-8')
Expand Down

0 comments on commit 267fe9a

Please sign in to comment.