diff options
| author | Collin Richards <collin.richards@ni.com> | 2016-06-28 17:54:01 -0500 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2016-07-04 00:26:56 -0400 |
| commit | 887f2154c5aaeaff6de2efb65cc1118cfb5eb904 (patch) | |
| tree | 52e0d9f7ef48a1acc7d4ac33c8cd4a9eb9dcdd5d /meta-openstack/recipes-devtools/python/python-salttesting | |
| parent | a896c8ee774ff56dccd58040f72f4a09e1b9fe9c (diff) | |
| download | meta-cloud-services-887f2154c5aaeaff6de2efb65cc1118cfb5eb904.tar.gz | |
python-salttesting: Add ptest output format patch
Add a patch that allows the output of running the salt test suite to be
in ptest format.
Signed-off-by: Collin Richards <collin.richards@ni.com>
Natinst-ReviewBoard-ID: 143279
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'meta-openstack/recipes-devtools/python/python-salttesting')
| -rw-r--r-- | meta-openstack/recipes-devtools/python/python-salttesting/0001-Add-ptest-output-option-to-test-suite.patch | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/meta-openstack/recipes-devtools/python/python-salttesting/0001-Add-ptest-output-option-to-test-suite.patch b/meta-openstack/recipes-devtools/python/python-salttesting/0001-Add-ptest-output-option-to-test-suite.patch new file mode 100644 index 0000000..c297320 --- /dev/null +++ b/meta-openstack/recipes-devtools/python/python-salttesting/0001-Add-ptest-output-option-to-test-suite.patch | |||
| @@ -0,0 +1,232 @@ | |||
| 1 | From 7e2642530bfd4ac0226b90404e7a4511e44756b6 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Collin Richards <collin.richards@ni.com> | ||
| 3 | Date: Tue, 28 Jun 2016 16:02:22 -0500 | ||
| 4 | Subject: [PATCH] Add ptest output option to test suite | ||
| 5 | |||
| 6 | Extend salttesting to support outputing the results of running the test | ||
| 7 | suite in ptest format. | ||
| 8 | |||
| 9 | Upstream-Status: Inappropriate [OE specific] | ||
| 10 | |||
| 11 | Signed-off-by: Collin Richards <collin.richards@ni.com> | ||
| 12 | Natinst-ReviewBoard-ID: 143279 | ||
| 13 | --- | ||
| 14 | salttesting/parser/__init__.py | 12 +++ | ||
| 15 | salttesting/ptest.py | 168 +++++++++++++++++++++++++++++++++++++++++ | ||
| 16 | 2 files changed, 180 insertions(+) | ||
| 17 | create mode 100644 salttesting/ptest.py | ||
| 18 | |||
| 19 | diff --git a/salttesting/parser/__init__.py b/salttesting/parser/__init__.py | ||
| 20 | index 1e7275b4b65ef29deb89049a70bf6a074e11873d..d8cba0cb1e4814b7065b6896186c25300048ec92 100644 | ||
| 21 | --- a/salttesting/parser/__init__.py | ||
| 22 | +++ b/salttesting/parser/__init__.py | ||
| 23 | @@ -25,6 +25,7 @@ from functools import partial | ||
| 24 | from contextlib import closing | ||
| 25 | |||
| 26 | from salttesting import TestLoader, TextTestRunner | ||
| 27 | +from salttesting.ptest import PTestRunner | ||
| 28 | from salttesting.version import __version_info__ | ||
| 29 | from salttesting.xmlunit import HAS_XMLRUNNER, XMLTestRunner | ||
| 30 | try: | ||
| 31 | @@ -264,6 +265,12 @@ class SaltTestingParser(optparse.OptionParser): | ||
| 32 | action='store_true', | ||
| 33 | help='Do NOT show the overall tests result' | ||
| 34 | ) | ||
| 35 | + self.output_options_group.add_option( | ||
| 36 | + '--ptest-out', | ||
| 37 | + dest='ptest_out', | ||
| 38 | + default=False, | ||
| 39 | + help='Output test results in PTest format' | ||
| 40 | + ) | ||
| 41 | self.add_option_group(self.output_options_group) | ||
| 42 | |||
| 43 | self.fs_cleanup_options_group = optparse.OptionGroup( | ||
| 44 | @@ -491,6 +498,11 @@ class SaltTestingParser(optparse.OptionParser): | ||
| 45 | verbosity=self.options.verbosity | ||
| 46 | ).run(tests) | ||
| 47 | self.testsuite_results.append((header, runner)) | ||
| 48 | + elif self.options.ptest_out: | ||
| 49 | + runner = PTestRunner( | ||
| 50 | + stream=sys.stdout, | ||
| 51 | + verbosity=self.options.verbosity).run(tests) | ||
| 52 | + self.testsuite_results.append((header, runner)) | ||
| 53 | else: | ||
| 54 | runner = TextTestRunner( | ||
| 55 | stream=sys.stdout, | ||
| 56 | diff --git a/salttesting/ptest.py b/salttesting/ptest.py | ||
| 57 | new file mode 100644 | ||
| 58 | index 0000000000000000000000000000000000000000..9780886bc8f9d400aab2e96a33b14af980e64315 | ||
| 59 | --- /dev/null | ||
| 60 | +++ b/salttesting/ptest.py | ||
| 61 | @@ -0,0 +1,168 @@ | ||
| 62 | +# -*- coding: utf-8 -*- | ||
| 63 | + | ||
| 64 | +""" | ||
| 65 | +Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, | ||
| 66 | +2011, 2012, 2013, 2014, 2015, 2016 Python Software Foundation; All Rights | ||
| 67 | +Reserved | ||
| 68 | + | ||
| 69 | +PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 | ||
| 70 | +-------------------------------------------- | ||
| 71 | + | ||
| 72 | +1. This LICENSE AGREEMENT is between the Python Software Foundation | ||
| 73 | +("PSF"), and the Individual or Organization ("Licensee") accessing and | ||
| 74 | +otherwise using this software ("Python") in source or binary form and | ||
| 75 | +its associated documentation. | ||
| 76 | + | ||
| 77 | +2. Subject to the terms and conditions of this License Agreement, PSF hereby | ||
| 78 | +grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, | ||
| 79 | +analyze, test, perform and/or display publicly, prepare derivative works, | ||
| 80 | +distribute, and otherwise use Python alone or in any derivative version, | ||
| 81 | +provided, however, that PSF's License Agreement and PSF's notice of copyright, | ||
| 82 | +i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, | ||
| 83 | +2011, 2012, 2013, 2014, 2015, 2016 Python Software Foundation; All Rights | ||
| 84 | +Reserved" are retained in Python alone or in any derivative version prepared by | ||
| 85 | +Licensee. | ||
| 86 | + | ||
| 87 | +3. In the event Licensee prepares a derivative work that is based on | ||
| 88 | +or incorporates Python or any part thereof, and wants to make | ||
| 89 | +the derivative work available to others as provided herein, then | ||
| 90 | +Licensee hereby agrees to include in any such work a brief summary of | ||
| 91 | +the changes made to Python. | ||
| 92 | + | ||
| 93 | +4. PSF is making Python available to Licensee on an "AS IS" | ||
| 94 | +basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR | ||
| 95 | +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND | ||
| 96 | +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS | ||
| 97 | +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT | ||
| 98 | +INFRINGE ANY THIRD PARTY RIGHTS. | ||
| 99 | + | ||
| 100 | +5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON | ||
| 101 | +FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS | ||
| 102 | +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, | ||
| 103 | +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. | ||
| 104 | + | ||
| 105 | +6. This License Agreement will automatically terminate upon a material | ||
| 106 | +breach of its terms and conditions. | ||
| 107 | + | ||
| 108 | +7. Nothing in this License Agreement shall be deemed to create any | ||
| 109 | +relationship of agency, partnership, or joint venture between PSF and | ||
| 110 | +Licensee. This License Agreement does not grant permission to use PSF | ||
| 111 | +trademarks or trade name in a trademark sense to endorse or promote | ||
| 112 | +products or services of Licensee, or any third party. | ||
| 113 | + | ||
| 114 | +8. By copying, installing or otherwise using Python, Licensee | ||
| 115 | +agrees to be bound by the terms and conditions of this License | ||
| 116 | +Agreement. | ||
| 117 | + | ||
| 118 | +Modified Version of Python's TextTestRunner | ||
| 119 | +""" | ||
| 120 | + | ||
| 121 | +import time | ||
| 122 | +import sys | ||
| 123 | +import string | ||
| 124 | + | ||
| 125 | +import unittest | ||
| 126 | +TestResult = unittest.TestResult | ||
| 127 | + | ||
| 128 | + | ||
| 129 | +class _WritelnDecorator(object): | ||
| 130 | + """Used to decorate file-like objects with a handy 'writeln' method""" | ||
| 131 | + def __init__(self, stream): | ||
| 132 | + self.stream = stream | ||
| 133 | + | ||
| 134 | + def __getattr__(self, attr): | ||
| 135 | + if attr in ('stream', '__getstate__'): | ||
| 136 | + raise AttributeError(attr) | ||
| 137 | + return getattr(self.stream, attr) | ||
| 138 | + | ||
| 139 | + def writeln(self, arg=None): | ||
| 140 | + if arg: | ||
| 141 | + self.write(arg) | ||
| 142 | + self.write('\n') # text-mode streams translate to \r\n if needed | ||
| 143 | + | ||
| 144 | + | ||
| 145 | +class _PTestResult(TestResult): | ||
| 146 | + """A test result class that can print formatted text results to a stream. | ||
| 147 | + | ||
| 148 | + Used by PTestRunner. | ||
| 149 | + """ | ||
| 150 | + separator1 = '=' * 70 | ||
| 151 | + separator2 = '-' * 70 | ||
| 152 | + | ||
| 153 | + def __init__(self, stream, descriptions, verbosity): | ||
| 154 | + TestResult.__init__(self) | ||
| 155 | + self.stream = stream | ||
| 156 | + self.showAll = verbosity > 1 | ||
| 157 | + self.dots = verbosity == 1 | ||
| 158 | + self.descriptions = descriptions | ||
| 159 | + | ||
| 160 | + def getDescription(self, test): | ||
| 161 | + if self.descriptions: | ||
| 162 | + return test.shortDescription() or str(test) | ||
| 163 | + else: | ||
| 164 | + return str(test) | ||
| 165 | + | ||
| 166 | + def startTest(self, test): | ||
| 167 | + TestResult.startTest(self, test) | ||
| 168 | + | ||
| 169 | + def addSuccess(self, test): | ||
| 170 | + TestResult.addSuccess(self, test) | ||
| 171 | + if self.showAll: | ||
| 172 | + self.stream.writeln("PASS: {0}".format(self.getDescription(test))) | ||
| 173 | + elif self.dots: | ||
| 174 | + self.stream.write('.') | ||
| 175 | + | ||
| 176 | + def addError(self, test, err): | ||
| 177 | + TestResult.addError(self, test, err) | ||
| 178 | + if self.showAll: | ||
| 179 | + self.stream.writeln("FAIL: ERROR {0}".format(self.getDescription(test))) | ||
| 180 | + elif self.dots: | ||
| 181 | + self.stream.write('E') | ||
| 182 | + | ||
| 183 | + def addFailure(self, test, err): | ||
| 184 | + TestResult.addFailure(self, test, err) | ||
| 185 | + if self.showAll: | ||
| 186 | + self.stream.writeln("FAIL: {0}".format(self.getDescription(test))) | ||
| 187 | + elif self.dots: | ||
| 188 | + self.stream.write('F') | ||
| 189 | + | ||
| 190 | + def printErrors(self): | ||
| 191 | + if self.dots or self.showAll: | ||
| 192 | + self.stream.writeln() | ||
| 193 | + self.printErrorList('ERROR', self.errors) | ||
| 194 | + self.printErrorList('FAIL', self.failures) | ||
| 195 | + | ||
| 196 | + def printErrorList(self, flavour, errors): | ||
| 197 | + for test, err in errors: | ||
| 198 | + self.stream.writeln(self.separator1) | ||
| 199 | + self.stream.writeln("{0}: {0}".format(flavour, self.getDescription(test))) | ||
| 200 | + self.stream.writeln(self.separator2) | ||
| 201 | + self.stream.writeln("{0}".format(err)) | ||
| 202 | + | ||
| 203 | + | ||
| 204 | +class PTestRunner: | ||
| 205 | + """A test runner class that displays results in PTest format. | ||
| 206 | + | ||
| 207 | + """ | ||
| 208 | + def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1): | ||
| 209 | + self.stream = _WritelnDecorator(stream) | ||
| 210 | + self.descriptions = descriptions | ||
| 211 | + self.verbosity = 2 | ||
| 212 | + | ||
| 213 | + def _makeResult(self): | ||
| 214 | + return _PTestResult(self.stream, self.descriptions, self.verbosity) | ||
| 215 | + | ||
| 216 | + def run(self, test): | ||
| 217 | + "Run the given test case or test suite." | ||
| 218 | + result = self._makeResult() | ||
| 219 | + startTime = time.time() | ||
| 220 | + test(result) | ||
| 221 | + stopTime = time.time() | ||
| 222 | + timeTaken = float(stopTime - startTime) | ||
| 223 | + result.printErrors() | ||
| 224 | + run = result.testsRun | ||
| 225 | + self.stream.writeln("Ran %d test%s in %.3fs" % | ||
| 226 | + (run, run == 1 and "" or "s", timeTaken)) | ||
| 227 | + self.stream.writeln(result.separator2) | ||
| 228 | + self.stream.writeln() | ||
| 229 | + return result | ||
| 230 | -- | ||
| 231 | 1.9.1 | ||
| 232 | |||
