Skip to content

Commit 1c49ffe

Browse files
committed
Generate stable output when running tests: patch localtime
1 parent ddb0947 commit 1c49ffe

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/testasciidoc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323

2424
import os, sys, re, difflib
25+
import time
2526

2627
if sys.platform[:4] == 'java':
2728
# Jython cStringIO is more compatible with CPython StringIO.
@@ -75,6 +76,28 @@ def normalize_data(lines):
7576
return result
7677

7778

79+
def mock_localtime(f, _localtime=time.localtime):
80+
"""Mock time module to generate stable output."""
81+
_frozentime = 0X3DE170D6
82+
_frozentz = 'Pacific/Auckland'
83+
84+
def _fake_localtime(t=_frozentime + 1):
85+
assert t > _frozentime, 'File created before first public release'
86+
return _localtime(_frozentime)
87+
88+
def generate_expected(self, backend):
89+
time.localtime = _fake_localtime
90+
os.environ['TZ'] = _frozentz
91+
time.tzset()
92+
try:
93+
return f(self, backend)
94+
finally:
95+
time.localtime = _localtime
96+
del os.environ['TZ']
97+
time.tzset()
98+
return generate_expected
99+
100+
78101
class AsciiDocTest(object):
79102

80103
def __init__(self):
@@ -172,6 +195,7 @@ def get_expected(self, backend):
172195
f.close()
173196
return result
174197

198+
@mock_localtime
175199
def generate_expected(self, backend):
176200
"""
177201
Generate and return test data output for backend.

0 commit comments

Comments
 (0)