Merge trunk.
[third_party/subunit] / filters / subunit-2to1
1 #!/usr/bin/env python
2 #  subunit: extensions to python unittest to get test results from subprocesses.
3 #  Copyright (C) 2013  Robert Collins <robertc@robertcollins.net>
4 #
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.
15 #
16
17 """Convert a version 2 subunit stream to a version 1 stream."""
18
19 from optparse import OptionParser
20 import sys
21
22 from testtools import StreamToExtendedDecorator
23
24 from subunit import ByteStreamToStreamResult, TestProtocolClient
25 from subunit.filters import find_stream, run_tests_from_stream
26
27
28 def make_options(description):
29     parser = OptionParser(description=__doc__)
30     return parser
31
32
33 def main():
34     parser = make_options(__doc__)
35     (options, args) = parser.parse_args()
36     case = ByteStreamToStreamResult(
37         find_stream(sys.stdin, args), non_subunit_name='stdout')
38     result = StreamToExtendedDecorator(TestProtocolClient(sys.stdout))
39     # What about stdout chunks?
40     result.startTestRun()
41     case.run(result)
42     result.stopTestRun()
43     sys.exit(0)
44
45
46 if __name__ == '__main__':
47     main()