diff options
author | Eli Schwartz <eschwartz93@gmail.com> | 2020-08-05 15:55:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-05 22:55:49 +0300 |
commit | 1c9ad5b7c607cfca25ea9f23b60c9c7f1526482e (patch) | |
tree | d646b4b38f010632e32c71819cacc655caf7de24 | |
parent | a98a6dabe832e041428e44ca4d7cd47e9060e1a7 (diff) | |
download | asciidoc-py3-1c9ad5b7c607cfca25ea9f23b60c9c7f1526482e.tar.gz |
simplify timestamp mocking in testasciidoc.py (#132)
$SOURCE_DATE_EPOCH is now the officially supported mechanism for
guaranteeing stable output timestamps, which means we can simply run the
tests using that, and drop some code.
This also fixes #131 since the variable would override the mocked time,
resulting in tests failing if $SOURCE_DATE_EPOCH was set in the
environment (e.g. for linux distro packaging).
-rwxr-xr-x | tests/testasciidoc.py | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/tests/testasciidoc.py b/tests/testasciidoc.py index 347b7be..4d2605a 100755 --- a/tests/testasciidoc.py +++ b/tests/testasciidoc.py @@ -10,7 +10,6 @@ from pathlib import Path import re import shutil import sys -import time sys.path.append(str(Path(__file__).resolve().parent.parent)) import asciidocapi # noqa: E402 @@ -68,28 +67,6 @@ def normalize_data(lines): return result -def mock_localtime(f, _localtime=time.localtime): - """Mock time module to generate stable output.""" - _frozentime = 0X3DE170D6 - _frozentz = 'UTC+00' - - def _frozen_localtime(t=_frozentime + 1): - assert t > _frozentime, 'File created before first public release' - return _localtime(_frozentime) - - def generate_expected(self, backend): - time.localtime = _frozen_localtime - os.environ['TZ'] = _frozentz - time.tzset() - try: - return f(self, backend) - finally: - time.localtime = _localtime - del os.environ['TZ'] - time.tzset() - return generate_expected - - class AsciiDocTest(object): def __init__(self): self.number = None # Test number (1..). @@ -188,7 +165,6 @@ class AsciiDocTest(object): result = [s.rstrip() for s in result] return result - @mock_localtime def generate_expected(self, backend): """ Generate and return test data output for backend. @@ -386,6 +362,8 @@ class Lines(list): if __name__ == '__main__': + # guarantee a stable timestamp matching the test fixtures + os.environ['SOURCE_DATE_EPOCH'] = '1038184662' # Process command line options. from argparse import ArgumentParser parser = ArgumentParser(description='Run AsciiDoc conformance tests specified in ' |