s3:param: add a utility function lp_idmap_range() to get the configured range for...
[Samba/gebeck_regimport.git] / lib / subunit / filters / subunit2pyunit
blob83a23d14d13930d323eb0f299e4b0f7cf35ecfc7
1 #!/usr/bin/env python
2 # subunit: extensions to python unittest to get test results from subprocesses.
3 # Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
5 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
6 # license at the users choice. A copy of both licenses are available in the
7 # project source as Apache-2.0 and BSD. You may not use this file except in
8 # compliance with one of these two licences.
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # license you chose for the specific language governing permissions and
14 # limitations under that license.
17 """Display a subunit stream through python's unittest test runner."""
19 from optparse import OptionParser
20 import sys
21 import unittest
23 from subunit import DiscardStream, ProtocolTestCase, TestProtocolServer
25 parser = OptionParser(description=__doc__)
26 parser.add_option("--no-passthrough", action="store_true",
27 help="Hide all non subunit input.", default=False, dest="no_passthrough")
28 parser.add_option("--progress", action="store_true",
29 help="Use bzrlib's test reporter (requires bzrlib)",
30 default=False)
31 (options, args) = parser.parse_args()
32 if options.no_passthrough:
33 passthrough_stream = DiscardStream()
34 else:
35 passthrough_stream = None
36 test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
37 if options.progress:
38 from bzrlib.tests import TextTestRunner
39 from bzrlib import ui
40 ui.ui_factory = ui.make_ui_for_terminal(None, sys.stdout, sys.stderr)
41 runner = TextTestRunner()
42 else:
43 runner = unittest.TextTestRunner(verbosity=2)
44 if runner.run(test).wasSuccessful():
45 exit_code = 0
46 else:
47 exit_code = 1
48 sys.exit(exit_code)