Files
mongo/test/3rdparty/python-subunit-0.0.16/python/subunit/run.py
Michael Cahill fa69e2a994 Update test/3rdparty with the packages required to run the test suite in parallel mode. Change the short command line flag to "-j", matching make.
--HG--
rename : test/3rdparty/testscenarios-0.2/.bzrignore => test/3rdparty/testscenarios-0.4/.bzrignore
rename : test/3rdparty/testscenarios-0.2/Apache-2.0 => test/3rdparty/testscenarios-0.4/Apache-2.0
rename : test/3rdparty/testscenarios-0.2/BSD => test/3rdparty/testscenarios-0.4/BSD
rename : test/3rdparty/testscenarios-0.2/COPYING => test/3rdparty/testscenarios-0.4/COPYING
rename : test/3rdparty/testscenarios-0.2/GOALS => test/3rdparty/testscenarios-0.4/GOALS
rename : test/3rdparty/testscenarios-0.2/HACKING => test/3rdparty/testscenarios-0.4/HACKING
rename : test/3rdparty/testscenarios-0.2/MANIFEST.in => test/3rdparty/testscenarios-0.4/MANIFEST.in
rename : test/3rdparty/testscenarios-0.2/Makefile => test/3rdparty/testscenarios-0.4/Makefile
rename : test/3rdparty/testscenarios-0.2/doc/__init__.py => test/3rdparty/testscenarios-0.4/doc/__init__.py
rename : test/3rdparty/testscenarios-0.2/doc/example.py => test/3rdparty/testscenarios-0.4/doc/example.py
rename : test/3rdparty/testscenarios-0.2/doc/test_sample.py => test/3rdparty/testscenarios-0.4/doc/test_sample.py
rename : test/3rdparty/testtools-0.9.12/doc/conf.py => test/3rdparty/testtools-0.9.34/doc/conf.py
rename : test/3rdparty/testtools-0.9.12/doc/make.bat => test/3rdparty/testtools-0.9.34/doc/make.bat
rename : test/3rdparty/testtools-0.9.12/testtools/_compat2x.py => test/3rdparty/testtools-0.9.34/testtools/_compat2x.py
rename : test/3rdparty/testtools-0.9.12/testtools/_spinner.py => test/3rdparty/testtools-0.9.34/testtools/_spinner.py
rename : test/3rdparty/testtools-0.9.12/testtools/distutilscmd.py => test/3rdparty/testtools-0.9.34/testtools/distutilscmd.py
rename : test/3rdparty/testtools-0.9.12/testtools/monkey.py => test/3rdparty/testtools-0.9.34/testtools/monkey.py
rename : test/3rdparty/testtools-0.9.12/testtools/tests/test_monkey.py => test/3rdparty/testtools-0.9.34/testtools/tests/test_monkey.py
rename : test/3rdparty/testtools-0.9.12/testtools/tests/test_runtest.py => test/3rdparty/testtools-0.9.34/testtools/tests/test_runtest.py
rename : test/3rdparty/testtools-0.9.12/testtools/utils.py => test/3rdparty/testtools-0.9.34/testtools/utils.py
2013-12-20 10:27:28 +11:00

132 lines
4.1 KiB
Python
Executable File

#!/usr/bin/python
#
# Simple subunit testrunner for python
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
#
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
# license at the users choice. A copy of both licenses are available in the
# project source as Apache-2.0 and BSD. You may not use this file except in
# compliance with one of these two licences.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# license you chose for the specific language governing permissions and
# limitations under that license.
#
"""Run a unittest testcase reporting results as Subunit.
$ python -m subunit.run mylib.tests.test_suite
"""
import io
import os
import sys
from testtools import ExtendedToStreamDecorator
from testtools.testsuite import iterate_tests
from subunit import StreamResultToBytes, get_default_formatter
from subunit.test_results import AutoTimingTestResultDecorator
from testtools.run import (
BUFFEROUTPUT,
CATCHBREAK,
FAILFAST,
list_test,
TestProgram,
USAGE_AS_MAIN,
)
class SubunitTestRunner(object):
def __init__(self, verbosity=None, failfast=None, buffer=None, stream=None):
"""Create a TestToolsTestRunner.
:param verbosity: Ignored.
:param failfast: Stop running tests at the first failure.
:param buffer: Ignored.
"""
self.failfast = failfast
self.stream = stream or sys.stdout
def run(self, test):
"Run the given test case or test suite."
result, _ = self._list(test)
result = ExtendedToStreamDecorator(result)
result = AutoTimingTestResultDecorator(result)
if self.failfast is not None:
result.failfast = self.failfast
result.startTestRun()
try:
test(result)
finally:
result.stopTestRun()
return result
def list(self, test):
"List the test."
result, errors = self._list(test)
if errors:
failed_descr = '\n'.join(errors).encode('utf8')
result.status(file_name="import errors", runnable=False,
file_bytes=failed_descr, mime_type="text/plain;charset=utf8")
sys.exit(2)
def _list(self, test):
test_ids, errors = list_test(test)
try:
fileno = self.stream.fileno()
except:
fileno = None
if fileno is not None:
stream = os.fdopen(fileno, 'wb', 0)
else:
stream = self.stream
result = StreamResultToBytes(stream)
for test_id in test_ids:
result.status(test_id=test_id, test_status='exists')
return result, errors
class SubunitTestProgram(TestProgram):
USAGE = USAGE_AS_MAIN
def usageExit(self, msg=None):
if msg:
print (msg)
usage = {'progName': self.progName, 'catchbreak': '', 'failfast': '',
'buffer': ''}
if self.failfast != False:
usage['failfast'] = FAILFAST
if self.catchbreak != False:
usage['catchbreak'] = CATCHBREAK
if self.buffer != False:
usage['buffer'] = BUFFEROUTPUT
usage_text = self.USAGE % usage
usage_lines = usage_text.split('\n')
usage_lines.insert(2, "Run a test suite with a subunit reporter.")
usage_lines.insert(3, "")
print('\n'.join(usage_lines))
sys.exit(2)
def main():
# Disable the default buffering, for Python 2.x where pdb doesn't do it
# on non-ttys.
stream = get_default_formatter()
runner = SubunitTestRunner
# Patch stdout to be unbuffered, so that pdb works well on 2.6/2.7.
binstdout = io.open(sys.stdout.fileno(), 'wb', 0)
if sys.version_info[0] > 2:
sys.stdout = io.TextIOWrapper(binstdout, encoding=sys.stdout.encoding)
else:
sys.stdout = binstdout
SubunitTestProgram(module=None, argv=sys.argv, testRunner=runner,
stdout=sys.stdout)
if __name__ == '__main__':
main()