From 7cf452787317f035c92cf71b0509bfe614fbfe52 Mon Sep 17 00:00:00 2001 From: Steffen Hauf <haufs@max-exfl027.desy.de> Date: Fri, 16 Nov 2018 16:59:28 +0100 Subject: [PATCH] Adjust listing format of test reports --- docs/source/conf.py | 45 ++++++++++++++++++++++-------------- docs/source/test_results.rst | 14 ----------- 2 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 docs/source/test_results.rst diff --git a/docs/source/conf.py b/docs/source/conf.py index dd0edbefb..594c726f2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -440,6 +440,7 @@ with open("available_notebooks.rst", "w") as f: # add test results test_artifact_dir = os.path.realpath("../../tests/artifacts") +from datetime import datetime from dateutil.parser import parse from lxml import etree import tabulate @@ -448,8 +449,7 @@ import textwrap def xml_to_rst_report(xml, git_tag): e = etree.fromstring(xml.encode()) - rst = [".. include:: roles.rst"] - rst += [""] + rst = [""] rst += ["Test execution for {test_name} on {ex_date}"] test_name, ex_date = e.get("name").split("-") ex_date = parse(ex_date) @@ -522,18 +522,26 @@ def xml_to_rst_report(xml, git_tag): rst += textwrap.indent(report, " "*4).split("\n") rst += [""] - # console output - rst += ["Console Output"] - rst += ["-"*len(rst[-1])] - rst += [""] - + do_console = False for child in e: - if child.tag != "system-out": - continue - - rst += [".. code-block:: console"] - rst += textwrap.indent(child.text, " "*4).split("\n") - + if child.tag == "system-out" and len(child.text.strip()): + do_console = True + break + + if do_console: + + # console output + rst += ["Console Output"] + rst += ["-"*len(rst[-1])] + rst += [""] + + for child in e: + if child.tag != "system-out": + continue + + rst += [".. code-block:: console"] + rst += textwrap.indent(child.text, " "*4).split("\n") + return "\n".join(rst) @@ -542,7 +550,8 @@ def sorted_dir(folder): path = os.path.join(folder, name) return os.path.getmtime(path) - return sorted(os.listdir(folder), key=getmtime, reverse=True) + sort = sorted(os.listdir(folder), key=getmtime, reverse=True) + return [(s, datetime.fromtimestamp(getmtime(s))) for s in sort] header = """ Test Results @@ -562,10 +571,12 @@ if not os.path.exists("./test_rsts"): with open("test_results.rst", "w") as f: f.write(header) - for commit in sorted_dir(test_artifact_dir): + for commit, modtime in sorted_dir(test_artifact_dir): with open("./test_rsts/{}.rst".format(commit), "w") as fr: - rst = [commit] - rst += ["+"*len(commit)] + rst = [".. include:: roles.rst"] + rst += [""] + rst += ["{} - {}".format(commit[:8], modtime)] + rst += ["+"*len(rst[-1])] rst += [""] fr.write("\n".join(rst)) diff --git a/docs/source/test_results.rst b/docs/source/test_results.rst deleted file mode 100644 index b755afe8c..000000000 --- a/docs/source/test_results.rst +++ /dev/null @@ -1,14 +0,0 @@ - -Test Results -************ - -Results are organized by git commit, and sorted descending by date. - -Contents: - -.. toctree:: - :maxdepth: 2 - - - test_rsts/4962d288a1d6e6b6054fc5440c39ac77e5df5a14 - test_rsts/91ae7b03d948c11c75b80e5ffdc71e326c7591be -- GitLab