Code enhancements (thanks to mitya57 and tk0miya):

* use tuple instead of list
* compile regex to find copyright year
* enclose test inside try/finally
This commit is contained in:
Alexis Bienvenüe
2016-05-02 09:57:06 +02:00
parent 7a89015a54
commit 6509130ff2
2 changed files with 33 additions and 31 deletions

View File

@@ -14,34 +14,36 @@ from util import TestApp
def test_correct_year():
# save current value of SOURCE_DATE_EPOCH
sde = os.environ.pop('SOURCE_DATE_EPOCH',None)
try:
# save current value of SOURCE_DATE_EPOCH
sde = os.environ.pop('SOURCE_DATE_EPOCH',None)
# test with SOURCE_DATE_EPOCH unset: no modification
app = TestApp(buildername='html',testroot='correct-year')
app.builder.build_all()
content = (app.outdir / 'contents.html').text()
app.cleanup()
assert '2006-2009' in content
# test with SOURCE_DATE_EPOCH unset: no modification
app = TestApp(buildername='html',testroot='correct-year')
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"
app = TestApp(buildername='html',testroot='correct-year')
app.builder.build_all()
content = (app.outdir / 'contents.html').text()
app.cleanup()
assert '2006-2011' in content
# test with SOURCE_DATE_EPOCH set: copyright year should be
# updated
os.environ['SOURCE_DATE_EPOCH'] = "1293840000"
app = TestApp(buildername='html',testroot='correct-year')
app.builder.build_all()
content = (app.outdir / 'contents.html').text()
app.cleanup()
assert '2006-2011' in content
os.environ['SOURCE_DATE_EPOCH'] = "1293839999"
app = TestApp(buildername='html',testroot='correct-year')
app.builder.build_all()
content = (app.outdir / 'contents.html').text()
app.cleanup()
assert '2006-2010' in content
os.environ['SOURCE_DATE_EPOCH'] = "1293839999"
app = TestApp(buildername='html',testroot='correct-year')
app.builder.build_all()
content = (app.outdir / 'contents.html').text()
app.cleanup()
assert '2006-2010' in content
# Restores SOURCE_DATE_EPOCH
if sde == None:
os.environ.pop('SOURCE_DATE_EPOCH',None)
else:
os.environ['SOURCE_DATE_EPOCH'] = sde
finally:
# Restores SOURCE_DATE_EPOCH
if sde == None:
os.environ.pop('SOURCE_DATE_EPOCH',None)
else:
os.environ['SOURCE_DATE_EPOCH'] = sde