1# Copyright 2017 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5 6from __future__ import absolute_import 7from __future__ import division 8from __future__ import print_function 9 10import unittest 11 12from six.moves import range # pylint: disable=redefined-builtin 13 14from py_utils import expectations_parser 15 16 17class TestExpectationParserTest(unittest.TestCase): 18 19 def testInitWithGoodData(self): 20 good_data = """ 21# This is a test expectation file. 22# 23# tags: tag1 tag2 tag3 24# tags: tag4 Mac Win Debug 25 26crbug.com/12345 [ Mac ] b1/s1 [ Skip ] 27crbug.com/23456 [ Mac Debug ] b1/s2 [ Skip ] 28""" 29 parser = expectations_parser.TestExpectationParser(good_data) 30 tags = ['tag1', 'tag2', 'tag3', 'tag4', 'Mac', 'Win', 'Debug'] 31 self.assertEqual(parser.tags, tags) 32 expected_outcome = [ 33 expectations_parser.Expectation( 34 'crbug.com/12345', 'b1/s1', ['Mac'], ['Skip']), 35 expectations_parser.Expectation( 36 'crbug.com/23456', 'b1/s2', ['Mac', 'Debug'], ['Skip']) 37 ] 38 for i in range(len(parser.expectations)): 39 self.assertEqual(parser.expectations[i], expected_outcome[i]) 40 41 def testInitWithBadData(self): 42 bad_data = """ 43# This is a test expectation file. 44# 45# tags: tag1 tag2 tag3 46# tags: tag4 47 48crbug.com/12345 [ Mac b1/s1 [ Skip ] 49""" 50 with self.assertRaises(expectations_parser.ParseError): 51 expectations_parser.TestExpectationParser(bad_data) 52 53 def testTagAfterExpectationsStart(self): 54 bad_data = """ 55# This is a test expectation file. 56# 57# tags: tag1 tag2 tag3 58 59crbug.com/12345 [ tag1 ] b1/s1 [ Skip ] 60 61# tags: tag4 62""" 63 with self.assertRaises(expectations_parser.ParseError): 64 expectations_parser.TestExpectationParser(bad_data) 65 66 def testParseExpectationLineEverythingThere(self): 67 raw_data = '# tags: Mac\ncrbug.com/23456 [ Mac ] b1/s2 [ Skip ]' 68 parser = expectations_parser.TestExpectationParser(raw_data) 69 expected_outcome = [ 70 expectations_parser.Expectation( 71 'crbug.com/23456', 'b1/s2', ['Mac'], ['Skip']) 72 ] 73 for i in range(len(parser.expectations)): 74 self.assertEqual(parser.expectations[i], expected_outcome[i]) 75 76 def testParseExpectationLineBadTag(self): 77 raw_data = '# tags: None\ncrbug.com/23456 [ Mac ] b1/s2 [ Skip ]' 78 with self.assertRaises(expectations_parser.ParseError): 79 expectations_parser.TestExpectationParser(raw_data) 80 81 def testParseExpectationLineNoConditions(self): 82 raw_data = '# tags: All\ncrbug.com/12345 b1/s1 [ Skip ]' 83 parser = expectations_parser.TestExpectationParser(raw_data) 84 expected_outcome = [ 85 expectations_parser.Expectation( 86 'crbug.com/12345', 'b1/s1', [], ['Skip']), 87 ] 88 for i in range(len(parser.expectations)): 89 self.assertEqual(parser.expectations[i], expected_outcome[i]) 90 91 def testParseExpectationLineNoBug(self): 92 raw_data = '# tags: All\n[ All ] b1/s1 [ Skip ]' 93 parser = expectations_parser.TestExpectationParser(raw_data) 94 expected_outcome = [ 95 expectations_parser.Expectation( 96 None, 'b1/s1', ['All'], ['Skip']), 97 ] 98 for i in range(len(parser.expectations)): 99 self.assertEqual(parser.expectations[i], expected_outcome[i]) 100 101 def testParseExpectationLineNoBugNoConditions(self): 102 raw_data = '# tags: All\nb1/s1 [ Skip ]' 103 parser = expectations_parser.TestExpectationParser(raw_data) 104 expected_outcome = [ 105 expectations_parser.Expectation( 106 None, 'b1/s1', [], ['Skip']), 107 ] 108 for i in range(len(parser.expectations)): 109 self.assertEqual(parser.expectations[i], expected_outcome[i]) 110 111 def testParseExpectationLineMultipleConditions(self): 112 raw_data = ('# tags:All None Batman\n' 113 'crbug.com/123 [ All None Batman ] b1/s1 [ Skip ]') 114 parser = expectations_parser.TestExpectationParser(raw_data) 115 expected_outcome = [ 116 expectations_parser.Expectation( 117 'crbug.com/123', 'b1/s1', ['All', 'None', 'Batman'], ['Skip']), 118 ] 119 for i in range(len(parser.expectations)): 120 self.assertEqual(parser.expectations[i], expected_outcome[i]) 121 122 def testParseExpectationLineBadConditionBracket(self): 123 raw_data = '# tags: Mac\ncrbug.com/23456 ] Mac ] b1/s2 [ Skip ]' 124 with self.assertRaises(expectations_parser.ParseError): 125 expectations_parser.TestExpectationParser(raw_data) 126 127 def testParseExpectationLineBadResultBracket(self): 128 raw_data = '# tags: Mac\ncrbug.com/23456 ] Mac ] b1/s2 ] Skip ]' 129 with self.assertRaises(expectations_parser.ParseError): 130 expectations_parser.TestExpectationParser(raw_data) 131 132 def testParseExpectationLineBadConditionBracketSpacing(self): 133 raw_data = '# tags: Mac\ncrbug.com/2345 [Mac] b1/s1 [ Skip ]' 134 with self.assertRaises(expectations_parser.ParseError): 135 expectations_parser.TestExpectationParser(raw_data) 136 137 def testParseExpectationLineBadResultBracketSpacing(self): 138 raw_data = '# tags: Mac\ncrbug.com/2345 [ Mac ] b1/s1 [Skip]' 139 with self.assertRaises(expectations_parser.ParseError): 140 expectations_parser.TestExpectationParser(raw_data) 141 142 def testParseExpectationLineNoClosingConditionBracket(self): 143 raw_data = '# tags: Mac\ncrbug.com/2345 [ Mac b1/s1 [ Skip ]' 144 with self.assertRaises(expectations_parser.ParseError): 145 expectations_parser.TestExpectationParser(raw_data) 146 147 def testParseExpectationLineNoClosingResultBracket(self): 148 raw_data = '# tags: Mac\ncrbug.com/2345 [ Mac ] b1/s1 [ Skip' 149 with self.assertRaises(expectations_parser.ParseError): 150 expectations_parser.TestExpectationParser(raw_data) 151 152 def testParseExpectationLineUrlInTestName(self): 153 raw_data = ( 154 '# tags: Mac\ncrbug.com/123 [ Mac ] b.1/http://google.com [ Skip ]') 155 expected_outcomes = [ 156 expectations_parser.Expectation( 157 'crbug.com/123', 'b.1/http://google.com', ['Mac'], ['Skip']) 158 ] 159 parser = expectations_parser.TestExpectationParser(raw_data) 160 for i in range(len(parser.expectations)): 161 self.assertEqual(parser.expectations[i], expected_outcomes[i]) 162 163 def testParseExpectationLineEndingComment(self): 164 raw_data = '# tags: Mac\ncrbug.com/23456 [ Mac ] b1/s2 [ Skip ] # abc 123' 165 parser = expectations_parser.TestExpectationParser(raw_data) 166 expected_outcome = [ 167 expectations_parser.Expectation( 168 'crbug.com/23456', 'b1/s2', ['Mac'], ['Skip']) 169 ] 170 for i in range(len(parser.expectations)): 171 self.assertEqual(parser.expectations[i], expected_outcome[i]) 172