diff --git a/coverage/backward.py b/coverage/backward.py index 37b491676..9d1d78e5b 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -9,6 +9,8 @@ import os import sys +from datetime import datetime + from coverage import env @@ -217,6 +219,17 @@ def __eq__(self, other): return self.__dict__ == other.__dict__ +def format_local_datetime(dt): + """Return a string with local timezone representing the date. + If python version is lower than 3.6, the time zone is not included. + """ + try: + return dt.astimezone().strftime('%Y-%m-%d %H:%M %z') + except (TypeError, ValueError): + # Datetime.astimezone in Python 3.5 can not handle naive datetime + return dt.strftime('%Y-%m-%d %H:%M') + + def invalidate_import_caches(): """Invalidate any import caches that may or may not exist.""" if importlib and hasattr(importlib, "invalidate_caches"): diff --git a/coverage/html.py b/coverage/html.py index 596e11435..3596bbe1d 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -11,7 +11,7 @@ import coverage from coverage import env -from coverage.backward import iitems, SimpleNamespace +from coverage.backward import iitems, SimpleNamespace, format_local_datetime from coverage.data import add_data_to_hash from coverage.files import flat_rootname from coverage.misc import CoverageException, ensure_dir, file_be_gone, Hasher, isolate_module @@ -200,7 +200,7 @@ def __init__(self, cov): '__url__': coverage.__url__, '__version__': coverage.__version__, 'title': title, - 'time_stamp': datetime.datetime.now().strftime('%Y-%m-%d %H:%M'), + 'time_stamp': format_local_datetime(datetime.datetime.now()), 'extra_css': self.extra_css, 'has_arcs': self.has_arcs, 'show_contexts': self.config.show_contexts, diff --git a/tests/gold/html/a/a_py.html b/tests/gold/html/a/a_py.html index 2ce524140..9cfb74544 100644 --- a/tests/gold/html/a/a_py.html +++ b/tests/gold/html/a/a_py.html @@ -61,7 +61,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/a/index.html b/tests/gold/html/a/index.html index e1c585fc9..3276f1d65 100644 --- a/tests/gold/html/a/index.html +++ b/tests/gold/html/a/index.html @@ -76,7 +76,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/b_branch/b_py.html b/tests/gold/html/b_branch/b_py.html index ce8bb875e..39a7a9b79 100644 --- a/tests/gold/html/b_branch/b_py.html +++ b/tests/gold/html/b_branch/b_py.html @@ -84,7 +84,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/b_branch/index.html b/tests/gold/html/b_branch/index.html index 8b68b26e2..0dfc20cad 100644 --- a/tests/gold/html/b_branch/index.html +++ b/tests/gold/html/b_branch/index.html @@ -84,7 +84,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/bom/2/bom_py.html b/tests/gold/html/bom/2/bom_py.html index 3d1c98fbd..8802ece8c 100644 --- a/tests/gold/html/bom/2/bom_py.html +++ b/tests/gold/html/bom/2/bom_py.html @@ -67,7 +67,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:32 + created at 2019-10-14 09:32 +0000

diff --git a/tests/gold/html/bom/2/index.html b/tests/gold/html/bom/2/index.html index 3fa67f0fa..28abec0a6 100644 --- a/tests/gold/html/bom/2/index.html +++ b/tests/gold/html/bom/2/index.html @@ -76,7 +76,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-13 11:41 + created at 2019-10-13 11:41 +0000

diff --git a/tests/gold/html/bom/bom_py.html b/tests/gold/html/bom/bom_py.html index 635f8b514..63679d4bc 100644 --- a/tests/gold/html/bom/bom_py.html +++ b/tests/gold/html/bom/bom_py.html @@ -67,7 +67,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/bom/index.html b/tests/gold/html/bom/index.html index b08e9c1c9..0e56a99a6 100644 --- a/tests/gold/html/bom/index.html +++ b/tests/gold/html/bom/index.html @@ -76,7 +76,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/isolatin1/index.html b/tests/gold/html/isolatin1/index.html index 7e33e754d..ec9c50b52 100644 --- a/tests/gold/html/isolatin1/index.html +++ b/tests/gold/html/isolatin1/index.html @@ -76,7 +76,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/isolatin1/isolatin1_py.html b/tests/gold/html/isolatin1/isolatin1_py.html index 9c12c445d..549c55cc8 100644 --- a/tests/gold/html/isolatin1/isolatin1_py.html +++ b/tests/gold/html/isolatin1/isolatin1_py.html @@ -61,7 +61,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_1/index.html b/tests/gold/html/omit_1/index.html index d8d02f6ab..a97add0f6 100644 --- a/tests/gold/html/omit_1/index.html +++ b/tests/gold/html/omit_1/index.html @@ -97,7 +97,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_1/m1_py.html b/tests/gold/html/omit_1/m1_py.html index 60923930b..8dcafac8d 100644 --- a/tests/gold/html/omit_1/m1_py.html +++ b/tests/gold/html/omit_1/m1_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_1/m2_py.html b/tests/gold/html/omit_1/m2_py.html index de060f321..1545dc0b4 100644 --- a/tests/gold/html/omit_1/m2_py.html +++ b/tests/gold/html/omit_1/m2_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_1/m3_py.html b/tests/gold/html/omit_1/m3_py.html index 76a91a4a9..f49336eb6 100644 --- a/tests/gold/html/omit_1/m3_py.html +++ b/tests/gold/html/omit_1/m3_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_1/main_py.html b/tests/gold/html/omit_1/main_py.html index 9f242537f..d0c8ba2b0 100644 --- a/tests/gold/html/omit_1/main_py.html +++ b/tests/gold/html/omit_1/main_py.html @@ -66,7 +66,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_2/index.html b/tests/gold/html/omit_2/index.html index d51ebd2a9..5b5e3c6ea 100644 --- a/tests/gold/html/omit_2/index.html +++ b/tests/gold/html/omit_2/index.html @@ -90,7 +90,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_2/m2_py.html b/tests/gold/html/omit_2/m2_py.html index de060f321..1545dc0b4 100644 --- a/tests/gold/html/omit_2/m2_py.html +++ b/tests/gold/html/omit_2/m2_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_2/m3_py.html b/tests/gold/html/omit_2/m3_py.html index 76a91a4a9..f49336eb6 100644 --- a/tests/gold/html/omit_2/m3_py.html +++ b/tests/gold/html/omit_2/m3_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_2/main_py.html b/tests/gold/html/omit_2/main_py.html index 9f242537f..d0c8ba2b0 100644 --- a/tests/gold/html/omit_2/main_py.html +++ b/tests/gold/html/omit_2/main_py.html @@ -66,7 +66,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_3/index.html b/tests/gold/html/omit_3/index.html index 0d8ff217d..f5bc1aaeb 100644 --- a/tests/gold/html/omit_3/index.html +++ b/tests/gold/html/omit_3/index.html @@ -83,7 +83,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_3/m3_py.html b/tests/gold/html/omit_3/m3_py.html index 76a91a4a9..f49336eb6 100644 --- a/tests/gold/html/omit_3/m3_py.html +++ b/tests/gold/html/omit_3/m3_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_3/main_py.html b/tests/gold/html/omit_3/main_py.html index 9f242537f..d0c8ba2b0 100644 --- a/tests/gold/html/omit_3/main_py.html +++ b/tests/gold/html/omit_3/main_py.html @@ -66,7 +66,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_4/index.html b/tests/gold/html/omit_4/index.html index d91291fc4..861ba02e3 100644 --- a/tests/gold/html/omit_4/index.html +++ b/tests/gold/html/omit_4/index.html @@ -90,7 +90,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_4/m1_py.html b/tests/gold/html/omit_4/m1_py.html index 60923930b..8dcafac8d 100644 --- a/tests/gold/html/omit_4/m1_py.html +++ b/tests/gold/html/omit_4/m1_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_4/m3_py.html b/tests/gold/html/omit_4/m3_py.html index 76a91a4a9..f49336eb6 100644 --- a/tests/gold/html/omit_4/m3_py.html +++ b/tests/gold/html/omit_4/m3_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_4/main_py.html b/tests/gold/html/omit_4/main_py.html index 9f242537f..d0c8ba2b0 100644 --- a/tests/gold/html/omit_4/main_py.html +++ b/tests/gold/html/omit_4/main_py.html @@ -66,7 +66,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_5/index.html b/tests/gold/html/omit_5/index.html index f1e0fe605..8afbebad5 100644 --- a/tests/gold/html/omit_5/index.html +++ b/tests/gold/html/omit_5/index.html @@ -83,7 +83,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_5/m1_py.html b/tests/gold/html/omit_5/m1_py.html index 60923930b..8dcafac8d 100644 --- a/tests/gold/html/omit_5/m1_py.html +++ b/tests/gold/html/omit_5/m1_py.html @@ -58,7 +58,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/omit_5/main_py.html b/tests/gold/html/omit_5/main_py.html index 9f242537f..d0c8ba2b0 100644 --- a/tests/gold/html/omit_5/main_py.html +++ b/tests/gold/html/omit_5/main_py.html @@ -66,7 +66,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/other/blah_blah_other_py.html b/tests/gold/html/other/blah_blah_other_py.html index d3a4ebfc3..3774fdd4f 100644 --- a/tests/gold/html/other/blah_blah_other_py.html +++ b/tests/gold/html/other/blah_blah_other_py.html @@ -60,7 +60,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/other/here_py.html b/tests/gold/html/other/here_py.html index df2715d6f..2693ac584 100644 --- a/tests/gold/html/other/here_py.html +++ b/tests/gold/html/other/here_py.html @@ -62,7 +62,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/other/index.html b/tests/gold/html/other/index.html index fa1a770f4..644d14909 100644 --- a/tests/gold/html/other/index.html +++ b/tests/gold/html/other/index.html @@ -83,7 +83,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/partial/index.html b/tests/gold/html/partial/index.html index fa1ec4ad9..f766c0b4c 100644 --- a/tests/gold/html/partial/index.html +++ b/tests/gold/html/partial/index.html @@ -84,7 +84,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 12:01 + created at 2019-10-14 12:01 +0000

diff --git a/tests/gold/html/partial/partial_py.html b/tests/gold/html/partial/partial_py.html index f004808a2..e47cd9685 100644 --- a/tests/gold/html/partial/partial_py.html +++ b/tests/gold/html/partial/partial_py.html @@ -74,7 +74,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 12:01 + created at 2019-10-14 12:01 +0000

diff --git a/tests/gold/html/styled/a_py.html b/tests/gold/html/styled/a_py.html index 4687e4642..51a7389f6 100644 --- a/tests/gold/html/styled/a_py.html +++ b/tests/gold/html/styled/a_py.html @@ -62,7 +62,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/styled/index.html b/tests/gold/html/styled/index.html index 6e182fa63..d1a9259b6 100644 --- a/tests/gold/html/styled/index.html +++ b/tests/gold/html/styled/index.html @@ -77,7 +77,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/unicode/index.html b/tests/gold/html/unicode/index.html index bfa09a38d..b2de7b3d1 100644 --- a/tests/gold/html/unicode/index.html +++ b/tests/gold/html/unicode/index.html @@ -76,7 +76,7 @@

Coverage report:

coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/gold/html/unicode/unicode_py.html b/tests/gold/html/unicode/unicode_py.html index 467229616..40280ad5f 100644 --- a/tests/gold/html/unicode/unicode_py.html +++ b/tests/gold/html/unicode/unicode_py.html @@ -61,7 +61,7 @@

« index     coverage.py v5.0a9, - created at 2019-10-14 09:27 + created at 2019-10-14 09:27 +0000

diff --git a/tests/test_html.py b/tests/test_html.py index b543fa08e..0c003016f 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -70,6 +70,11 @@ def get_html_index_content(self): """ with open("htmlcov/index.html") as f: index = f.read() + index = re.sub( + r"created at \d{4}-\d{2}-\d{2} \d{2}:\d{2} \+\d{4}", + r"created at YYYY-MM-DD HH:MM +ZZZZ", + index, + ) index = re.sub( r"created at \d{4}-\d{2}-\d{2} \d{2}:\d{2}", r"created at YYYY-MM-DD HH:MM", @@ -620,6 +625,7 @@ def compare_html(expected, actual): scrubs = [ (r'/coverage.readthedocs.io/?[-.\w/]*', '/coverage.readthedocs.io/VER'), (r'coverage.py v[\d.abc]+', 'coverage.py vVER'), + (r'created at \d\d\d\d-\d\d-\d\d \d\d:\d\d \+\d\d\d\d', 'created at DATE'), (r'created at \d\d\d\d-\d\d-\d\d \d\d:\d\d', 'created at DATE'), # Some words are identifiers in one version, keywords in another. (r'(print|True|False)', r'\2'),