##// END OF EJS Templates
Add test utility for parsing test output from stdout/stderr
Fernando Perez -
Show More
@@ -21,13 +21,12 b' import sys'
21 21 import nose.tools as nt
22 22
23 23 from IPython.testing import decorators as dec
24 from IPython.testing.tools import full_path
24 from IPython.testing.tools import full_path, parse_test_output
25 25
26 26 #-----------------------------------------------------------------------------
27 27 # Tests
28 28 #-----------------------------------------------------------------------------
29 29
30
31 30 @dec.skip_win32
32 31 def test_full_path_posix():
33 32 spath = '/foo/bar.py'
@@ -49,4 +48,14 b' def test_full_path_win32():'
49 48 result = full_path(spath,['a.txt','b.txt'])
50 49 nt.assert_equal(result, ['c:\\a.txt', 'c:\\b.txt'])
51 50 result = full_path(spath,'a.txt')
52 nt.assert_equal(result, ['c:\\a.txt']) No newline at end of file
51 nt.assert_equal(result, ['c:\\a.txt'])
52
53
54 def test_parser():
55 err = ("FAILED (errors=1)", 1, 0)
56 fail = ("FAILED (failures=1)", 0, 1)
57 both = ("FAILED (errors=1, failures=1)", 1, 1)
58 for txt, nerr, nfail in [err, fail, both]:
59 nerr1, nfail1 = parse_test_output(txt)
60 yield (nt.assert_equal, nerr, nerr1)
61 yield (nt.assert_equal, nfail, nfail1)
@@ -27,6 +27,7 b' Authors'
27 27 #-----------------------------------------------------------------------------
28 28
29 29 import os
30 import re
30 31 import sys
31 32
32 33 import nose.tools as nt
@@ -87,3 +88,46 b' def full_path(startPath,files):'
87 88 files = utils.list_strings(files)
88 89 base = os.path.split(startPath)[0]
89 90 return [ os.path.join(base,f) for f in files ]
91
92
93 def parse_test_output(txt):
94 """Parse the output of a test run and return errors, failures.
95
96 Parameters
97 ----------
98 txt : str
99 Text output of a test run, assumed to contain a line of one of the
100 following forms::
101 'FAILED (errors=1)'
102 'FAILED (failures=1)'
103 'FAILED (errors=1, failures=1)'
104
105 Returns
106 -------
107 nerr, nfail: number of errors and failures.
108 """
109
110 err_m = re.search(r'^FAILED \(errors=(\d+)\)', txt, re.MULTILINE)
111 if err_m:
112 nerr = int(err_m.group(1))
113 nfail = 0
114 return nerr, nfail
115
116 fail_m = re.search(r'^FAILED \(failures=(\d+)\)', txt, re.MULTILINE)
117 if fail_m:
118 nerr = 0
119 nfail = int(fail_m.group(1))
120 return nerr, nfail
121
122 both_m = re.search(r'^FAILED \(errors=(\d+), failures=(\d+)\)', txt,
123 re.MULTILINE)
124 if both_m:
125 nerr = int(both_m.group(1))
126 nfail = int(both_m.group(2))
127 return nerr, nfail
128
129 # If the input didn't match any of these forms, assume no error/failures
130 return 0, 0
131
132 # So nose doesn't think this is a test
133 parse_test_output.__test__ = False
General Comments 0
You need to be logged in to leave comments. Login now