From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QpQU1-0007Qj-SS for garchives@archives.gentoo.org; Fri, 05 Aug 2011 19:55:02 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6C72921C16A; Fri, 5 Aug 2011 19:54:54 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 2D42821C16A for ; Fri, 5 Aug 2011 19:54:54 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B1EF51B4022 for ; Fri, 5 Aug 2011 19:54:53 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 9938780048 for ; Fri, 5 Aug 2011 19:54:52 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <6c21f8b452e8454fc56a0eda654b54a299f29e9c.mgorny@gentoo> Subject: [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/output/ X-VCS-Repository: proj/pms-test-suite X-VCS-Files: pmstestsuite/output/__init__.py pmstestsuite/output/html.py X-VCS-Directories: pmstestsuite/output/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 6c21f8b452e8454fc56a0eda654b54a299f29e9c Date: Fri, 5 Aug 2011 19:54:52 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: cf140e80f784b26690befcc8ad0d5c4c commit: 6c21f8b452e8454fc56a0eda654b54a299f29e9c Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Fri Aug 5 19:55:12 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Fri Aug 5 19:55:12 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/pms-test-suit= e.git;a=3Dcommit;h=3D6c21f8b4 Add the HTML output module. --- pmstestsuite/output/__init__.py | 3 +- pmstestsuite/output/html.py | 182 +++++++++++++++++++++++++++++++++= ++++++ 2 files changed, 184 insertions(+), 1 deletions(-) diff --git a/pmstestsuite/output/__init__.py b/pmstestsuite/output/__init= __.py index cef7ab8..0c7c8be 100644 --- a/pmstestsuite/output/__init__.py +++ b/pmstestsuite/output/__init__.py @@ -83,5 +83,6 @@ def get_output_modules(): """ =20 from pmstestsuite.output.cli import CLIOutput + from pmstestsuite.output.html import HTMLOutput =20 - return (CLIOutput,) + return (CLIOutput, HTMLOutput) diff --git a/pmstestsuite/output/html.py b/pmstestsuite/output/html.py new file mode 100644 index 0000000..5842eb9 --- /dev/null +++ b/pmstestsuite/output/html.py @@ -0,0 +1,182 @@ +# vim:fileencoding=3Dutf-8 +# (c) 2011 Micha=C5=82 G=C3=B3rny +# Released under the terms of the 2-clause BSD license. + +from collections import defaultdict + +from pmstestsuite.output import OutputModule + +class HTMLOutput(OutputModule): + name =3D 'html' + + def __init__(self, path =3D None): + if path is None: + path =3D 'pms-test-suite-output.html' + self._path =3D path + + _htmlheader =3D ''' + + + PMS Test Suite test results + + + + ''' + + _htmlfooter =3D ''' +
+ +''' + + def __call__(self, allresults, verbose =3D False): + mypms =3D [] + + def _results_by_test(allresults): + ret =3D defaultdict(lambda: defaultdict(lambda: None)) + for pm, results in allresults.items(): + mypms.append(pm) + for t, r in results.items(): + ret[t][pm] =3D r + return ret + + def _results_by_class(reorderedresults): + ret =3D defaultdict(dict) + for t, r in reorderedresults.items(): + ret[t.__class__.__name__][t] =3D r + return ret + + def _sorted_pms(pms): + for pm in sorted(pms, key =3D lambda pm: mypms.index(pm)): + yield (pm, pms[pm]) + + class HTMLElem(object): + _elem =3D 'td' + + def __init__(self, text): + self._attrs =3D [] + self._text =3D text + + def set_rowspan(self, rowspan): + if rowspan !=3D 1: + self._attrs.append('rowspan=3D"%d"' % rowspan) + + def __str__(self): + return '<%s>%s' % (' '.join([self._elem] + self._attrs), + self._text, self._elem) + + class TH(HTMLElem): + _elem =3D 'th' + + def __init__(self, text, colspan =3D 1): + HTMLElem.__init__(self, text) + self._colspan =3D colspan + if colspan !=3D 1: + self._attrs.append('colspan=3D"%d"' % colspan) + + class ValCell(HTMLElem): + _color_class =3D '' + + def __init__(self, text): + HTMLElem.__init__(self, text) + self._attrs.append('class=3D"value %s"' % self._color_class) + + class ColorValCell(ValCell): + def __init__(self, text, cond): + self._color_class =3D 'good' if cond else 'bad' + ValCell.__init__(self, text) + + class BoolCell(ValCell): + def __init__(self, cond): + self._color_class =3D 'good' if cond else 'bad' + ValCell.__init__(self, 'OK' if cond else 'FAIL') + + class NoCell(HTMLElem): + def __init__(self): + pass + + def __str__(self): + return '' + + ret =3D True + results =3D _results_by_test(allresults) + table =3D defaultdict(lambda: defaultdict(lambda: None)) + + table[0][0] =3D TH('Test name') + table[0][1] =3D TH('EAPI') + table[0][2] =3D TH('Assertion') + table[0][3] =3D TH('Expected') + for i, pm in enumerate(mypms): + table[0][4 + i*3] =3D TH(pm.name, colspan =3D 3) + table[0][5 + i*3] =3D NoCell() + table[1][4 + i*3] =3D TH('Actual') + table[1][5 + i*3] =3D TH('Result') + maxcol =3D 6 + i*3 + + row =3D 2 + for cl, tests in _results_by_class(results).items(): + table[row][0] =3D cl + for t, pms in tests.items(): + table[row][1] =3D t.eapi + test_asserts =3D [] + col =3D 4 + for pm, r in _sorted_pms(pms): + table[row][col+1] =3D BoolCell(r) + for a in r.assertions: + if a.name not in test_asserts: + test_asserts.append(a.name) + crow =3D row + test_asserts.index(a.name) + table[crow][2] =3D a.name + table[crow][3] =3D ValCell(a.expected) + else: + crow =3D row + test_asserts.index(a.name) + + table[crow][col] =3D ColorValCell(a.actual, a) + col +=3D 2 + row +=3D len(test_asserts) + + f =3D open(self._path, 'w') + f.write(self._htmlheader) + for y in range(0, row): + f.write('') + for x in range(0, maxcol): + cell =3D table[y][x] + if cell is not None: + rowspan =3D 1 + for y2 in range(y + 1, row): + if table[y2][x] is None: + rowspan +=3D 1 + else: + break + + if not isinstance(cell, HTMLElem): + cell =3D HTMLElem(cell) + cell.set_rowspan(rowspan) + f.write(str(cell)) + f.write('') + f.write(self._htmlfooter) + f.close() + + return ret