|
22 | 22 |
|
23 | 23 |
|
24 | 24 | import os, sys, re, difflib
|
| 25 | +import time |
25 | 26 |
|
26 | 27 | if sys.platform[:4] == 'java':
|
27 | 28 | # Jython cStringIO is more compatible with CPython StringIO.
|
@@ -75,6 +76,28 @@ def normalize_data(lines):
|
75 | 76 | return result
|
76 | 77 |
|
77 | 78 |
|
| 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 | + |
78 | 101 | class AsciiDocTest(object):
|
79 | 102 |
|
80 | 103 | def __init__(self):
|
@@ -172,6 +195,7 @@ def get_expected(self, backend):
|
172 | 195 | f.close()
|
173 | 196 | return result
|
174 | 197 |
|
| 198 | + @mock_localtime |
175 | 199 | def generate_expected(self, backend):
|
176 | 200 | """
|
177 | 201 | Generate and return test data output for backend.
|
|
0 commit comments