2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
7 """Unit tests for instrumentation.InstrumentationParser."""
11 from pylib
.instrumentation
import instrumentation_parser
14 class InstrumentationParserTest(unittest
.TestCase
):
16 def testInstrumentationParser_nothing(self
):
17 parser
= instrumentation_parser
.InstrumentationParser([''])
18 statuses
= list(parser
.IterStatus())
19 code
, bundle
= parser
.GetResult()
20 self
.assertEqual(None, code
)
21 self
.assertEqual({}, bundle
)
22 self
.assertEqual([], statuses
)
24 def testInstrumentationParser_noMatchingStarts(self
):
27 'this.is.a.test.package.TestClass:.',
34 parser
= instrumentation_parser
.InstrumentationParser(raw_output
)
35 statuses
= list(parser
.IterStatus())
36 code
, bundle
= parser
.GetResult()
37 self
.assertEqual(None, code
)
38 self
.assertEqual({}, bundle
)
39 self
.assertEqual([], statuses
)
41 def testInstrumentationParser_resultAndCode(self
):
43 'INSTRUMENTATION_RESULT: shortMsg=foo bar',
44 'INSTRUMENTATION_RESULT: longMsg=a foo',
47 'INSTRUMENTATION_CODE: -1',
50 parser
= instrumentation_parser
.InstrumentationParser(raw_output
)
51 statuses
= list(parser
.IterStatus())
52 code
, bundle
= parser
.GetResult()
53 self
.assertEqual(-1, code
)
55 {'shortMsg': 'foo bar', 'longMsg': 'a foo\nwalked into\na bar'}, bundle
)
56 self
.assertEqual([], statuses
)
58 def testInstrumentationParser_oneStatus(self
):
60 'INSTRUMENTATION_STATUS: foo=1',
61 'INSTRUMENTATION_STATUS: bar=hello',
62 'INSTRUMENTATION_STATUS: world=false',
63 'INSTRUMENTATION_STATUS: class=this.is.a.test.package.TestClass',
64 'INSTRUMENTATION_STATUS: test=testMethod',
65 'INSTRUMENTATION_STATUS_CODE: 0',
68 parser
= instrumentation_parser
.InstrumentationParser(raw_output
)
69 statuses
= list(parser
.IterStatus())
76 'class': 'this.is.a.test.package.TestClass',
80 self
.assertEqual(expected
, statuses
)
82 def testInstrumentationParser_multiStatus(self
):
84 'INSTRUMENTATION_STATUS: class=foo',
85 'INSTRUMENTATION_STATUS: test=bar',
86 'INSTRUMENTATION_STATUS_CODE: 1',
87 'INSTRUMENTATION_STATUS: test_skipped=true',
88 'INSTRUMENTATION_STATUS_CODE: 0',
89 'INSTRUMENTATION_STATUS: class=hello',
90 'INSTRUMENTATION_STATUS: test=world',
91 'INSTRUMENTATION_STATUS: stack=',
93 'hello/world.py (42)',
95 'INSTRUMENTATION_STATUS_CODE: -1',
98 parser
= instrumentation_parser
.InstrumentationParser(raw_output
)
99 statuses
= list(parser
.IterStatus())
102 (1, {'class': 'foo', 'test': 'bar',}),
103 (0, {'test_skipped': 'true'}),
107 'stack': '\nfoo/bar.py (27)\nhello/world.py (42)\ntest/file.py (1)',
110 self
.assertEqual(expected
, statuses
)
112 def testInstrumentationParser_statusResultAndCode(self
):
114 'INSTRUMENTATION_STATUS: class=foo',
115 'INSTRUMENTATION_STATUS: test=bar',
116 'INSTRUMENTATION_STATUS_CODE: 1',
117 'INSTRUMENTATION_RESULT: result=hello',
121 'INSTRUMENTATION_CODE: 0',
124 parser
= instrumentation_parser
.InstrumentationParser(raw_output
)
125 statuses
= list(parser
.IterStatus())
126 code
, bundle
= parser
.GetResult()
128 self
.assertEqual(0, code
)
129 self
.assertEqual({'result': 'hello\nworld\n\n'}, bundle
)
130 self
.assertEqual([(1, {'class': 'foo', 'test': 'bar'})], statuses
)
133 if __name__
== '__main__':
134 unittest
.main(verbosity
=2)