|
1 | 1 | """Test the sphinx.config.Config class."""
|
2 | 2 |
|
| 3 | +import time |
3 | 4 | from unittest import mock
|
4 | 5 |
|
5 | 6 | import pytest
|
@@ -444,23 +445,67 @@ def test_conf_py_nitpick_ignore_list(tempdir):
|
444 | 445 | assert cfg.nitpick_ignore_regex == []
|
445 | 446 |
|
446 | 447 |
|
| 448 | +@pytest.fixture(params=[ |
| 449 | + # test with SOURCE_DATE_EPOCH unset: no modification |
| 450 | + None, |
| 451 | + # test with SOURCE_DATE_EPOCH set: copyright year should be updated |
| 452 | + 1293840000, |
| 453 | + 1293839999, |
| 454 | +]) |
| 455 | +def source_date_year(request, monkeypatch): |
| 456 | + sde = request.param |
| 457 | + with monkeypatch.context() as m: |
| 458 | + if sde: |
| 459 | + m.setenv('SOURCE_DATE_EPOCH', sde) |
| 460 | + yield time.gmtime(sde).tm_year |
| 461 | + else: |
| 462 | + m.delenv('SOURCE_DATE_EPOCH', raising=False) |
| 463 | + yield None |
| 464 | + |
| 465 | + |
447 | 466 | @pytest.mark.sphinx(testroot='copyright-multiline')
|
448 |
| -def test_multi_line_copyright(app, status, warning): |
| 467 | +def test_multi_line_copyright(source_date_year, app, monkeypatch): |
449 | 468 | app.builder.build_all()
|
450 | 469 |
|
451 | 470 | content = (app.outdir / 'index.html').read_text(encoding='utf-8')
|
452 | 471 |
|
453 |
| - assert ' © Copyright 2006-2009, Alice.<br/>' in content |
454 |
| - assert ' © Copyright 2010-2013, Bob.<br/>' in content |
455 |
| - assert ' © Copyright 2014-2017, Charlie.<br/>' in content |
456 |
| - assert ' © Copyright 2018-2021, David.<br/>' in content |
457 |
| - assert ' © Copyright 2022-2025, Eve.' in content |
458 |
| - |
459 |
| - lines = ( |
460 |
| - ' © Copyright 2006-2009, Alice.<br/>\n \n' |
461 |
| - ' © Copyright 2010-2013, Bob.<br/>\n \n' |
462 |
| - ' © Copyright 2014-2017, Charlie.<br/>\n \n' |
463 |
| - ' © Copyright 2018-2021, David.<br/>\n \n' |
464 |
| - ' © Copyright 2022-2025, Eve.\n \n' |
465 |
| - ) |
466 |
| - assert lines in content |
| 472 | + if source_date_year is None: |
| 473 | + # check the copyright footer line by line (empty lines ignored) |
| 474 | + assert ' © Copyright 2006-2009, Alice.<br/>\n' in content |
| 475 | + assert ' © Copyright 2010-2013, Bob.<br/>\n' in content |
| 476 | + assert ' © Copyright 2014-2017, Charlie.<br/>\n' in content |
| 477 | + assert ' © Copyright 2018-2021, David.<br/>\n' in content |
| 478 | + assert ' © Copyright 2022-2025, Eve.' in content |
| 479 | + |
| 480 | + # check the raw copyright footer block (empty lines included) |
| 481 | + assert ( |
| 482 | + ' © Copyright 2006-2009, Alice.<br/>\n' |
| 483 | + ' \n' |
| 484 | + ' © Copyright 2010-2013, Bob.<br/>\n' |
| 485 | + ' \n' |
| 486 | + ' © Copyright 2014-2017, Charlie.<br/>\n' |
| 487 | + ' \n' |
| 488 | + ' © Copyright 2018-2021, David.<br/>\n' |
| 489 | + ' \n' |
| 490 | + ' © Copyright 2022-2025, Eve.' |
| 491 | + ) in content |
| 492 | + else: |
| 493 | + # check the copyright footer line by line (empty lines ignored) |
| 494 | + assert f' © Copyright 2006-{source_date_year}, Alice.<br/>\n' in content |
| 495 | + assert f' © Copyright 2010-{source_date_year}, Bob.<br/>\n' in content |
| 496 | + assert f' © Copyright 2014-{source_date_year}, Charlie.<br/>\n' in content |
| 497 | + assert f' © Copyright 2018-{source_date_year}, David.<br/>\n' in content |
| 498 | + assert f' © Copyright 2022-{source_date_year}, Eve.' in content |
| 499 | + |
| 500 | + # check the raw copyright footer block (empty lines included) |
| 501 | + assert ( |
| 502 | + f' © Copyright 2006-{source_date_year}, Alice.<br/>\n' |
| 503 | + f' \n' |
| 504 | + f' © Copyright 2010-{source_date_year}, Bob.<br/>\n' |
| 505 | + f' \n' |
| 506 | + f' © Copyright 2014-{source_date_year}, Charlie.<br/>\n' |
| 507 | + f' \n' |
| 508 | + f' © Copyright 2018-{source_date_year}, David.<br/>\n' |
| 509 | + f' \n' |
| 510 | + f' © Copyright 2022-{source_date_year}, Eve.' |
| 511 | + ) in content |
0 commit comments