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