diff options
| author | Robert Collins <robertc@robertcollins.net> | 2006-04-17 14:48:50 +1000 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2006-04-17 14:48:50 +1000 |
| commit | a34205a76214eccedc6b95b67421d6c51f0be9de (patch) | |
| tree | a0d44b31e83bafda748aa7a519a875b52731ab42 /python | |
| parent | 4ff83274f7a9c20297c3484e994ba584c1771b31 (diff) | |
| download | subunit-git-a34205a76214eccedc6b95b67421d6c51f0be9de.tar.gz | |
Simplify test running, combine shell and python tests into one pyunit suite.
Diffstat (limited to 'python')
| -rw-r--r-- | python/SConscript | 4 | ||||
| -rwxr-xr-x | python/test_python.py | 127 |
2 files changed, 0 insertions, 131 deletions
diff --git a/python/SConscript b/python/SConscript index 416ff9f..d537e3e 100644 --- a/python/SConscript +++ b/python/SConscript @@ -18,7 +18,3 @@ python_suffix = distutils.sysconfig.get_python_lib()[len(prefix):] # install path for python is then in DESTDIR + python_suffix python_installdir = DESTDIR + python_suffix + '/subunit' env.Alias('install', [Install(python_installdir, 'subunit/__init__.py')]) -# tests -tests = [] -tests.append(env.TestPython('check_python', 'test_python.py', PYTHONPATH='python')) -env.Alias('check', tests) diff --git a/python/test_python.py b/python/test_python.py deleted file mode 100755 index 399d27f..0000000 --- a/python/test_python.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: python -*- -# -# Copyright (C) 2004 Canonical.com -# Author: Robert Collins <robert.collins@canonical.com> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -import unittest -from subunit.tests.TestUtil import TestVisitor, TestSuite -import subunit -import sys -import os -import shutil -import logging - -class ParameterisableTextTestRunner(unittest.TextTestRunner): - """I am a TextTestRunner whose result class is - parameterisable without further subclassing""" - def __init__(self, **args): - unittest.TextTestRunner.__init__(self, **args) - self._resultFactory=None - def resultFactory(self, *args): - """set or retrieve the result factory""" - if args: - self._resultFactory=args[0] - return self - if self._resultFactory is None: - self._resultFactory=unittest._TextTestResult - return self._resultFactory - - def _makeResult(self): - return self.resultFactory()(self.stream, self.descriptions, self.verbosity) - - -class EarlyStoppingTextTestResult(unittest._TextTestResult): - """I am a TextTestResult that can optionally stop at the first failure - or error""" - - def addError(self, test, err): - unittest._TextTestResult.addError(self, test, err) - if self.stopOnError(): - self.stop() - - def addFailure(self, test, err): - unittest._TextTestResult.addError(self, test, err) - if self.stopOnFailure(): - self.stop() - - def stopOnError(self, *args): - """should this result indicate an abort when an error occurs? - TODO parameterise this""" - return True - - def stopOnFailure(self, *args): - """should this result indicate an abort when a failure error occurs? - TODO parameterise this""" - return True - - -def earlyStopFactory(*args, **kwargs): - """return a an early stopping text test result""" - result=EarlyStoppingTextTestResult(*args, **kwargs) - return result - - -def test_suite(): - result = TestSuite() - result.addTest(subunit.test_suite()) - return result - - -class filteringVisitor(TestVisitor): - """I accruse all the testCases I visit that pass a regexp filter on id - into my suite - """ - - def __init__(self, filter): - import re - TestVisitor.__init__(self) - self._suite=None - self.filter=re.compile(filter) - - def suite(self): - """answer the suite we are building""" - if self._suite is None: - self._suite=TestSuite() - return self._suite - - def visitCase(self, aCase): - if self.filter.match(aCase.id()): - self.suite().addTest(aCase) - - -def main(argv): - """To parameterise what tests are run, run this script like so: - python test_all.py REGEX - i.e. - python test_all.py .*Protocol.* - to run all tests with Protocol in their id.""" - if len(argv) > 1: - pattern = argv[1] - else: - pattern = ".*" - visitor = filteringVisitor(pattern) - test_suite().visit(visitor) - runner = ParameterisableTextTestRunner(verbosity=2) - runner.resultFactory(earlyStopFactory) - if not runner.run(visitor.suite()).wasSuccessful(): - return 1 - return 0 - -if __name__ == '__main__': - sys.exit(main(sys.argv)) |
