From 3cc41c05fad5601c0dd1832f64a6e9efca017727 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Mon, 1 Apr 2019 11:36:04 -0400 Subject: [PATCH] robottime: Honor the SOURCE_DATE_EPOCH environment variable. Honoring the SOURCE_DATE_EPOCH environment variable allows building the documentation using libdoc reproducibly, by setting the generated timestamp to a fixed value. For more background on reproducible builds and the SOURCE_DATE_EPOCH environment variable, see: https://reproducible-builds.org/specs/source-date-epoch/. * src/robot/utils/robottime.py: import `os'. (TimestampCache._get_epoch): Retrieve date from SOURCE_DATE_EPOCH if it is defined, otherwise from time.time(). * utest/output/test_logger.py (TestLogger.test_write_to_one_logger): Check for the existance of a timestamp attribute instead of checking for its content as the later is easy to break when using the SOURCE_DATE_EPOCH environment variable. --- src/robot/utils/robottime.py | 3 +++ utest/output/test_logger.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/robot/utils/robottime.py b/src/robot/utils/robottime.py index 06432a4a6..91526f826 100644 --- a/src/robot/utils/robottime.py +++ b/src/robot/utils/robottime.py @@ -14,6 +14,7 @@ # limitations under the License. import datetime +import os import time import re @@ -395,6 +396,8 @@ class TimestampCache(object): # Seam for mocking def _get_epoch(self): + if os.getenv('SOURCE_DATE_EPOCH'): + return float(os.getenv('SOURCE_DATE_EPOCH')) return time.time() def _use_cache(self, secs, *separators): diff --git a/utest/output/test_logger.py b/utest/output/test_logger.py index 92fe6d77d..e980227aa 100644 --- a/utest/output/test_logger.py +++ b/utest/output/test_logger.py @@ -46,7 +46,7 @@ class TestLogger(unittest.TestCase): logger = LoggerMock(('Hello, world!', 'INFO')) self.logger.register_logger(logger) self.logger.write('Hello, world!', 'INFO') - assert_true(logger.msg.timestamp.startswith('20')) + assert_true(hasattr(logger.msg, 'timestamp')) def test_write_to_one_logger_with_trace_level(self): logger = LoggerMock(('expected message', 'TRACE')) -- 2.20.1 t'>Author 2021-05-20The #guix channel is hosted by Libera Chat....Tobias Geerinckx-Rice 2020-10-23doc: Update README....Maxim Cournoyer 2020-10-22README: Refer to the manual for building from Git....Maxim Cournoyer 2020-06-02doc: Update README to refer to the manual....Ludovic Courtès 2019-11-09doc: Mention value /var to localstatedir option....zimoun 2019-09-04doc: Update 'README'....Ludovic Courtès 2019-01-09build: Require Guile 2.2....Ludovic Courtès 2018-12-02Make Guile-JSON a required dependency....Eric Bavier 2018-11-23Update Guile-SQLite3 URL everywhere....Ludovic Courtès 2018-09-04Switch to Guile-Gcrypt....Ludovic Courtès 2018-06-27doc: Specify Guile-SQLite3 minimum version....Ludovic Courtès 2018-06-14build: Require Guile-SQLite3....Ludovic Courtès 2018-02-26build: Require Guile >= 2.0.13....Ludovic Courtès 2018-01-07doc: Mark zlib as mandatory, libbz2 as optional....Ludovic Courtès 2018-01-01doc: Update requirements in 'README'....Mathieu Lirzin 2017-09-25README: Replace http:// with https:// where applicable.Marius Bakke 2017-03-18build: Require Guile >= 2.0.9....Ludovic Courtès 2017-01-30maint: Fix invalid calls to 'info'....Mathieu Lirzin