2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-10-03 15:56:50 -05:00
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-10-04 04:48:47 -05:00
|
|
|
LT = time.localtime()
|
|
|
|
LT_NEW = (2009, *LT[1:], LT.tm_zone, LT.tm_gmtoff)
|
|
|
|
LOCALTIME_2009 = type(LT)(LT_NEW)
|
|
|
|
|
2024-10-03 15:56:50 -05:00
|
|
|
|
Tests: explicitly unset SOURCE_DATE_EPOCH during 'test_html_multi_line_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 <cjwatson@debian.org>
Co-authored-by: Colin Watson <cjwatson@debian.org>
Authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
Co-authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
2025-01-10 05:21:11 -06:00
|
|
|
@pytest.fixture
|
|
|
|
def no_source_date_year(monkeypatch):
|
2025-01-14 09:55:02 -06:00
|
|
|
"""Explicitly clear SOURCE_DATE_EPOCH from the environment; this
|
Tests: explicitly unset SOURCE_DATE_EPOCH during 'test_html_multi_line_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 <cjwatson@debian.org>
Co-authored-by: Colin Watson <cjwatson@debian.org>
Authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
Co-authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
2025-01-10 05:21:11 -06:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-10-03 15:56:50 -05:00
|
|
|
@pytest.fixture(
|
|
|
|
params=[
|
2024-10-04 04:48:47 -05:00
|
|
|
1199145600, # 2008-01-01 00:00:00
|
|
|
|
1199145599, # 2007-12-31 23:59:59
|
2024-10-03 15:56:50 -05:00
|
|
|
]
|
|
|
|
)
|
|
|
|
def source_date_year(request, monkeypatch):
|
|
|
|
source_date_epoch = request.param
|
|
|
|
with monkeypatch.context() as m:
|
2024-10-04 04:48:47 -05:00
|
|
|
m.setattr(time, 'localtime', lambda *a: LOCALTIME_2009)
|
2024-10-03 15:56:50 -05:00
|
|
|
m.setenv('SOURCE_DATE_EPOCH', str(source_date_epoch))
|
|
|
|
yield time.gmtime(source_date_epoch).tm_year
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='copyright-multiline')
|
Tests: explicitly unset SOURCE_DATE_EPOCH during 'test_html_multi_line_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 <cjwatson@debian.org>
Co-authored-by: Colin Watson <cjwatson@debian.org>
Authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
Co-authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
2025-01-10 05:21:11 -06:00
|
|
|
def test_html_multi_line_copyright(no_source_date_year, app):
|
2024-10-03 15:56:50 -05:00
|
|
|
app.build(force_all=True)
|
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf-8')
|
|
|
|
|
|
|
|
# check the copyright footer line by line (empty lines ignored)
|
|
|
|
assert ' © Copyright 2006.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2006-2009, Alice.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2010-2013, Bob.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2014-2017, Charlie.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2018-2021, David.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2022-2025, Eve.' in content
|
|
|
|
|
|
|
|
# check the raw copyright footer block (empty lines included)
|
|
|
|
assert (
|
|
|
|
' © Copyright 2006.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2006-2009, Alice.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2010-2013, Bob.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2014-2017, Charlie.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2018-2021, David.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2022-2025, Eve.'
|
|
|
|
) in content
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='copyright-multiline')
|
|
|
|
def test_html_multi_line_copyright_sde(source_date_year, app):
|
|
|
|
app.build(force_all=True)
|
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf-8')
|
|
|
|
|
|
|
|
# check the copyright footer line by line (empty lines ignored)
|
2024-10-04 04:48:47 -05:00
|
|
|
assert ' © Copyright 2006.<br/>\n' in content
|
2024-10-03 15:56:50 -05:00
|
|
|
assert f' © Copyright 2006-{source_date_year}, Alice.<br/>\n' in content
|
2024-10-04 04:48:47 -05:00
|
|
|
assert ' © Copyright 2010-2013, Bob.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2014-2017, Charlie.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2018-2021, David.<br/>\n' in content
|
|
|
|
assert ' © Copyright 2022-2025, Eve.' in content
|
2024-10-03 15:56:50 -05:00
|
|
|
|
|
|
|
# check the raw copyright footer block (empty lines included)
|
|
|
|
assert (
|
2024-10-04 04:48:47 -05:00
|
|
|
' © Copyright 2006.<br/>\n'
|
|
|
|
' \n'
|
2024-10-03 15:56:50 -05:00
|
|
|
f' © Copyright 2006-{source_date_year}, Alice.<br/>\n'
|
2024-10-04 04:48:47 -05:00
|
|
|
' \n'
|
|
|
|
' © Copyright 2010-2013, Bob.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2014-2017, Charlie.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2018-2021, David.<br/>\n'
|
|
|
|
' \n'
|
|
|
|
' © Copyright 2022-2025, Eve.'
|
2024-10-03 15:56:50 -05:00
|
|
|
) in content
|