Improve the VFS Makefile so that it is easier for use out of tree but still works...
[Samba/gebeck_regimport.git] / lib / subunit / filters / subunit-notify
blob758e7fc8fff196d53ca1c26df75acd146d249b76
1 #!/usr/bin/env python
2 # subunit: extensions to python unittest to get test results from subprocesses.
3 # Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
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 """Notify the user of a finished test run."""
19 from optparse import OptionParser
20 import sys
22 import pygtk
23 pygtk.require('2.0')
24 import pynotify
26 from subunit import DiscardStream, ProtocolTestCase, TestResultStats
28 if not pynotify.init("Subunit-notify"):
29 sys.exit(1)
31 parser = OptionParser(description=__doc__)
32 parser.add_option("--no-passthrough", action="store_true",
33 help="Hide all non subunit input.", default=False, dest="no_passthrough")
34 parser.add_option("-f", "--forward", action="store_true", default=False,
35 help="Forward subunit stream on stdout.")
36 (options, args) = parser.parse_args()
37 result = TestResultStats(sys.stdout)
38 if options.no_passthrough:
39 passthrough_stream = DiscardStream()
40 else:
41 passthrough_stream = None
42 if options.forward:
43 forward_stream = sys.stdout
44 else:
45 forward_stream = None
46 test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream,
47 forward=forward_stream)
48 test.run(result)
49 if result.failed_tests > 0:
50 summary = "Test run failed"
51 else:
52 summary = "Test run successful"
53 body = "Total tests: %d; Passed: %d; Failed: %d" % (
54 result.total_tests,
55 result.passed_tests,
56 result.failed_tests,
58 nw = pynotify.Notification(summary, body)
59 nw.show()
61 if result.wasSuccessful():
62 exit_code = 0
63 else:
64 exit_code = 1
65 sys.exit(exit_code)