2016-04-28 16:37:36 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_correct_year
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test copyright year adjustment
|
|
|
|
|
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
|
|
from util import TestApp
|
|
|
|
|
|
|
|
|
|
|
|
def test_correct_year():
|
2016-05-02 02:57:06 -05:00
|
|
|
try:
|
|
|
|
# save current value of SOURCE_DATE_EPOCH
|
2016-05-29 03:16:46 -05:00
|
|
|
sde = os.environ.pop('SOURCE_DATE_EPOCH', None)
|
2016-05-02 02:57:06 -05:00
|
|
|
|
|
|
|
# test with SOURCE_DATE_EPOCH unset: no modification
|
2016-05-29 03:16:46 -05:00
|
|
|
app = TestApp(buildername='html', testroot='correct-year')
|
2016-05-02 02:57:06 -05:00
|
|
|
app.builder.build_all()
|
|
|
|
content = (app.outdir / 'contents.html').text()
|
|
|
|
app.cleanup()
|
|
|
|
assert '2006-2009' in content
|
|
|
|
|
|
|
|
# test with SOURCE_DATE_EPOCH set: copyright year should be
|
|
|
|
# updated
|
|
|
|
os.environ['SOURCE_DATE_EPOCH'] = "1293840000"
|
2016-05-29 03:16:46 -05:00
|
|
|
app = TestApp(buildername='html', testroot='correct-year')
|
2016-05-02 02:57:06 -05:00
|
|
|
app.builder.build_all()
|
|
|
|
content = (app.outdir / 'contents.html').text()
|
|
|
|
app.cleanup()
|
|
|
|
assert '2006-2011' in content
|
|
|
|
|
|
|
|
os.environ['SOURCE_DATE_EPOCH'] = "1293839999"
|
2016-05-29 03:16:46 -05:00
|
|
|
app = TestApp(buildername='html', testroot='correct-year')
|
2016-05-02 02:57:06 -05:00
|
|
|
app.builder.build_all()
|
|
|
|
content = (app.outdir / 'contents.html').text()
|
|
|
|
app.cleanup()
|
|
|
|
assert '2006-2010' in content
|
|
|
|
|
|
|
|
finally:
|
|
|
|
# Restores SOURCE_DATE_EPOCH
|
2016-05-29 03:16:46 -05:00
|
|
|
if sde is None:
|
|
|
|
os.environ.pop('SOURCE_DATE_EPOCH', None)
|
2016-05-02 02:57:06 -05:00
|
|
|
else:
|
|
|
|
os.environ['SOURCE_DATE_EPOCH'] = sde
|