aboutsummaryrefslogtreecommitdiff
path: root/catapult/common/py_utils/py_utils/expectations_parser_unittest.py
blob: 82debc5dc0a4146026aadd13d85ea018613bde2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import unittest

from six.moves import range # pylint: disable=redefined-builtin

from py_utils import expectations_parser


class TestExpectationParserTest(unittest.TestCase):

  def testInitWithGoodData(self):
    good_data = """
# This is a test expectation file.
#
# tags: tag1 tag2 tag3
# tags: tag4 Mac Win Debug

crbug.com/12345 [ Mac ] b1/s1 [ Skip ]
crbug.com/23456 [ Mac Debug ] b1/s2 [ Skip ]
"""
    parser = expectations_parser.TestExpectationParser(good_data)
    tags = ['tag1', 'tag2', 'tag3', 'tag4', 'Mac', 'Win', 'Debug']
    self.assertEqual(parser.tags, tags)
    expected_outcome = [
        expectations_parser.Expectation(
            'crbug.com/12345', 'b1/s1', ['Mac'], ['Skip']),
        expectations_parser.Expectation(
            'crbug.com/23456', 'b1/s2', ['Mac', 'Debug'], ['Skip'])
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])

  def testInitWithBadData(self):
    bad_data = """
# This is a test expectation file.
#
# tags: tag1 tag2 tag3
# tags: tag4

crbug.com/12345 [ Mac b1/s1 [ Skip ]
"""
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(bad_data)

  def testTagAfterExpectationsStart(self):
    bad_data = """
# This is a test expectation file.
#
# tags: tag1 tag2 tag3

crbug.com/12345 [ tag1 ] b1/s1 [ Skip ]

# tags: tag4
"""
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(bad_data)

  def testParseExpectationLineEverythingThere(self):
    raw_data = '# tags: Mac\ncrbug.com/23456 [ Mac ] b1/s2 [ Skip ]'
    parser = expectations_parser.TestExpectationParser(raw_data)
    expected_outcome = [
        expectations_parser.Expectation(
            'crbug.com/23456', 'b1/s2', ['Mac'], ['Skip'])
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])

  def testParseExpectationLineBadTag(self):
    raw_data = '# tags: None\ncrbug.com/23456 [ Mac ] b1/s2 [ Skip ]'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineNoConditions(self):
    raw_data = '# tags: All\ncrbug.com/12345 b1/s1 [ Skip ]'
    parser = expectations_parser.TestExpectationParser(raw_data)
    expected_outcome = [
        expectations_parser.Expectation(
            'crbug.com/12345', 'b1/s1', [], ['Skip']),
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])

  def testParseExpectationLineNoBug(self):
    raw_data = '# tags: All\n[ All ] b1/s1 [ Skip ]'
    parser = expectations_parser.TestExpectationParser(raw_data)
    expected_outcome = [
        expectations_parser.Expectation(
            None, 'b1/s1', ['All'], ['Skip']),
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])

  def testParseExpectationLineNoBugNoConditions(self):
    raw_data = '# tags: All\nb1/s1 [ Skip ]'
    parser = expectations_parser.TestExpectationParser(raw_data)
    expected_outcome = [
        expectations_parser.Expectation(
            None, 'b1/s1', [], ['Skip']),
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])

  def testParseExpectationLineMultipleConditions(self):
    raw_data = ('# tags:All None Batman\n'
                'crbug.com/123 [ All None Batman ] b1/s1 [ Skip ]')
    parser = expectations_parser.TestExpectationParser(raw_data)
    expected_outcome = [
        expectations_parser.Expectation(
            'crbug.com/123', 'b1/s1', ['All', 'None', 'Batman'], ['Skip']),
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])

  def testParseExpectationLineBadConditionBracket(self):
    raw_data = '# tags: Mac\ncrbug.com/23456 ] Mac ] b1/s2 [ Skip ]'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineBadResultBracket(self):
    raw_data = '# tags: Mac\ncrbug.com/23456 ] Mac ] b1/s2 ] Skip ]'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineBadConditionBracketSpacing(self):
    raw_data = '# tags: Mac\ncrbug.com/2345 [Mac] b1/s1 [ Skip ]'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineBadResultBracketSpacing(self):
    raw_data = '# tags: Mac\ncrbug.com/2345 [ Mac ] b1/s1 [Skip]'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineNoClosingConditionBracket(self):
    raw_data = '# tags: Mac\ncrbug.com/2345 [ Mac b1/s1 [ Skip ]'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineNoClosingResultBracket(self):
    raw_data = '# tags: Mac\ncrbug.com/2345 [ Mac ] b1/s1 [ Skip'
    with self.assertRaises(expectations_parser.ParseError):
      expectations_parser.TestExpectationParser(raw_data)

  def testParseExpectationLineUrlInTestName(self):
    raw_data = (
        '# tags: Mac\ncrbug.com/123 [ Mac ] b.1/http://google.com [ Skip ]')
    expected_outcomes = [
        expectations_parser.Expectation(
            'crbug.com/123', 'b.1/http://google.com', ['Mac'], ['Skip'])
    ]
    parser = expectations_parser.TestExpectationParser(raw_data)
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcomes[i])

  def testParseExpectationLineEndingComment(self):
    raw_data = '# tags: Mac\ncrbug.com/23456 [ Mac ] b1/s2 [ Skip ] # abc 123'
    parser = expectations_parser.TestExpectationParser(raw_data)
    expected_outcome = [
        expectations_parser.Expectation(
            'crbug.com/23456', 'b1/s2', ['Mac'], ['Skip'])
    ]
    for i in range(len(parser.expectations)):
      self.assertEqual(parser.expectations[i], expected_outcome[i])