From 2817a5bd347975b0352ad1e7e6f05011018fde3a Mon Sep 17 00:00:00 2001 From: marco Date: Fri, 14 Aug 2020 17:44:21 +0200 Subject: [PATCH] template migliorato per tests --- platformcode/logger.py | 10 +-- tests/template.html | 200 +++++++++++++++++++++++++++++++++++++++++ tests/test_generic.py | 2 +- 3 files changed, 202 insertions(+), 10 deletions(-) create mode 100644 tests/template.html diff --git a/platformcode/logger.py b/platformcode/logger.py index d5fbe7aa..785dd5cf 100644 --- a/platformcode/logger.py +++ b/platformcode/logger.py @@ -13,12 +13,7 @@ PY3 = False if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int loggeractive = (config.get_setting("debug") == True) -try: - xbmc.KodiStub() - testMode = True - import cgi -except: - testMode = False + def log_enable(active): global loggeractive @@ -44,9 +39,6 @@ def encode_log(message=""): else: message = str(message) - if testMode: - message = cgi.escape(message).replace('\n', '
') - return message diff --git a/tests/template.html b/tests/template.html new file mode 100644 index 00000000..bbc37f49 --- /dev/null +++ b/tests/template.html @@ -0,0 +1,200 @@ + + + + {{ title }} + + + + + +
+
+
+

{{ title }}

+

Start Time: {{ header_info.start_time.strftime("%Y-%m-%d %H:%M:%S") }}

+

Duration: {{ header_info.status.duration }}

+

Summary: Total: {{ header_info.status.total }}, Pass: {{ header_info.status.success }}{% if header_info.status.failure %}, Fail: {{ header_info.status.failure }}{% endif %}{% if header_info.status.error %}, Error: {{ header_info.status.error }}{% endif %}{% if header_info.status.skip %}, Skip: {{ header_info.status.skip }}{% endif %}

+
+
+ {%- for test_case_name, tests_results in all_results|dictsort %} + {%- if tests_results %} +
+
+ + + + + + + + + + {%- for test_case in tests_results %} + {%- if not test_case.subtests is defined %} + + + + + + {%- if (test_case.stdout or test_case.err or test_case.err) and test_case.outcome != test_case.SKIP %} + + + + {%- endif %} + {%- if (test_case.stdout or test_case.err or test_case.err) and test_case.outcome == test_case.SKIP %} + + + + {%- endif %} + {%- else %} + + + + + + {%- if test_case.subtests %} + + + + {%- endif %} + {%- endif %} + {%- endfor %} + + + + +
{{ test_case_name }}Status
{{ test_case.test_id.split(".")[-1] }} + + {%- if test_case.outcome == test_case.SUCCESS -%} + Pass + {%- elif test_case.outcome == test_case.SKIP -%} + Skip + {%- elif test_case.outcome == test_case.FAILURE -%} + Fail + {%- else -%} + Error + {%- endif -%} + + + {%- if (test_case.stdout or test_case.err) %} + + {%- endif %} +
+ {%- if test_case.stdout %}

{{ test_case.stdout|e }}

{% endif %} + {%- if test_case.err %}

{{ test_case.err[0].__name__ }}: {{ test_case.err[1] }}

{% endif %} + {%- if test_case.err %}

{{ test_case.test_exception_info }}

{% endif %} +
+ {%- if test_case.stdout %}

{{ test_case.stdout|e }}

{% endif %} + {%- if test_case.err %}

{{ test_case.err }}

{% endif %} +
{{ test_case.test_id.split(".")[-1] }} + + {%- if test_case.outcome == test_case.SUCCESS -%} + Pass + {%- else -%} + Fail + {%- endif -%} + + + {%- if test_case.subtests %} + + {%- endif %} +
+ + + + {%- for subtest in test_case.subtests %} + + + + + + {%- if subtest.err or subtest.err %} + + + + {%- endif %} + {% endfor %} + +
{{ subtest.test_id.split(".")[-1] }} + + {%- if subtest.outcome == subtest.SUCCESS -%} + Pass + {%- else -%} + Fail + {%- endif -%} + + + {%- if subtest.err %} + + {%- endif %} +
+ {%- if subtest.err %}

{{ subtest.err[0].__name__ }}: {{ subtest.err[1] }}

{% endif %} + {%- if subtest.err %}

{{ subtest.test_exception_info }}

{% endif %} +
+
+ Total: {{ summaries[test_case_name].total }}, Pass: {{ summaries[test_case_name].success }}{% if summaries[test_case_name].failure %}, Fail: {{ summaries[test_case_name].failure }}{% endif %}{% if summaries[test_case_name].error %}, Error: {{ summaries[test_case_name].error }}{% endif %}{% if summaries[test_case_name].skip %}, Skip: {{ summaries[test_case_name].skip }}{% endif %} -- Duration: {{ summaries[test_case_name].duration }} +
+
+
+ {%- endif %} + {%- endfor %} +
+ + + + \ No newline at end of file diff --git a/tests/test_generic.py b/tests/test_generic.py index 012d5d62..bcba9c69 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -292,6 +292,6 @@ class GenericServerTest(unittest.TestCase): if __name__ == '__main__': if 'KOD_TST_CH' not in os.environ: unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(report_name='report', add_timestamp=False, combine_reports=True, - report_title='KoD Test Suite'), exit=False) + report_title='KoD Test Suite', template=os.path.join(config.get_runtime_path(), 'tests', 'template.html')), exit=False) else: unittest.main()