From 68b1b9559511c8b437be71c44ae38a6f2b1ed4ec Mon Sep 17 00:00:00 2001 From: Josef Skladanka Date: Oct 05 2018 14:59:28 +0000 Subject: [PATCH 1/2] Store testcase-stats also as JSON --- diff --git a/relval/cli.py b/relval/cli.py index 0789fad..1555127 100755 --- a/relval/cli.py +++ b/relval/cli.py @@ -30,6 +30,7 @@ import sys import tempfile from collections import defaultdict, OrderedDict from operator import attrgetter +import json import relval.user_stats as uss import relval.testcase_stats as tcs @@ -433,6 +434,7 @@ def testcase_stats(args, site): # identifying the compose from which it comes). Result rows for which # all three attributes match are grouped together - they're considered # to be results for the same test in different composes. + jsondata = {'allcomposes': allcomposes, 'stats': dict()} for index, (testtype, pages) in enumerate(allpages.items()): print('Processing type [{0}/{1}]: {2}'.format(index + 1, len(allpages), testtype)) @@ -456,8 +458,13 @@ def testcase_stats(args, site): print("Post-processing results...") tests = tcs.post_process(tests, allcomposes) tcs.print_results_html(testtype, pages, allcomposes, tests, outdir) + jsondata['stats'][testtype] = tcs.get_results_data(allcomposes, tests) tcs.print_summary_html(outdir, allpages) + with open(os.path.join(outdir, 'data.json'), 'w') as outfile: + print("JSON output: {}".format(os.path.join(outdir, 'data.json'))) + json.dump(jsondata, outfile, sort_keys=True, indent=4) + if args.out: try: shutil.rmtree(args.out) diff --git a/relval/testcase_stats.py b/relval/testcase_stats.py index 17dadb0..d873468 100644 --- a/relval/testcase_stats.py +++ b/relval/testcase_stats.py @@ -447,6 +447,34 @@ def print_results_html(testtype, pages, allcomposes, tests, outdir): template % {'timestamp': datetime.datetime.utcnow(), 'body': body}) fout.close() +def get_results_data(allcomposes, tests): + """Returns a dictionary containing the testcase-stats, to be used + for the JSON formatted output.""" + data = {} + for (name, testcase, section), test in tests.items(): + # Sanitize inputs, Bobby + name = name + testcase = testcase + section = section + + data.setdefault(section, list()) + if testcase != name: + dispname = ' - ' + name + else: + dispname = '' + bitmap = {c: [0, 'n/a'] for c in allcomposes} + bitmap.update(test.bitmap) + + trow = { + 'testcase_url': 'https://fedoraproject.org/wiki/%s' % testcase, + 'testcase_name': '%s%s' % (testcase, dispname), + 'milestone': test.milestone, + 'last_tested': test.last_tested, + 'bitmap': bitmap, + } + data[section].append(trow) + return data + def print_summary_html(outdir, allpages): """Despite the name, this writes the top-level index.html linking to the page for each test type. From 7a71007297823a8e04e4067c949ce9ad3e9dbc5c Mon Sep 17 00:00:00 2001 From: Josef Skladanka Date: Oct 05 2018 16:30:16 +0000 Subject: [PATCH 2/2] Fixed to meet common standards! --- diff --git a/relval/cli.py b/relval/cli.py index 1555127..3bc6164 100755 --- a/relval/cli.py +++ b/relval/cli.py @@ -462,7 +462,6 @@ def testcase_stats(args, site): tcs.print_summary_html(outdir, allpages) with open(os.path.join(outdir, 'data.json'), 'w') as outfile: - print("JSON output: {}".format(os.path.join(outdir, 'data.json'))) json.dump(jsondata, outfile, sort_keys=True, indent=4) if args.out: @@ -477,11 +476,14 @@ def testcase_stats(args, site): print("All output moved to: {0}".format(args.out)) print("Index page at: {0}".format(os.path.join(args.out, "index.html"))) + print("JSON data at: {0}".format(os.path.join(args.out, + "data.json"))) except (PermissionError, FileExistsError): print("Could not write to: {0}! " "Output is at: {1}".format(args.out, outdir)) else: print("HTML Output: " + os.path.join(outdir, "index.html")) + print("JSON Output: " + os.path.join(outdir, "data.json")) print(outdir) def report_results(args, site): diff --git a/relval/testcase_stats.py b/relval/testcase_stats.py index d873468..9eabb6d 100644 --- a/relval/testcase_stats.py +++ b/relval/testcase_stats.py @@ -452,11 +452,7 @@ def get_results_data(allcomposes, tests): for the JSON formatted output.""" data = {} for (name, testcase, section), test in tests.items(): - # Sanitize inputs, Bobby - name = name - testcase = testcase - section = section - + # Look ma, no hands! data.setdefault(section, list()) if testcase != name: dispname = ' - ' + name