Lines Matching refs:self

29   def tryParse(self, string):  argument
33 def assertParses(self, string): argument
34 checkFile = self.tryParse(string)
35 self.assertEqual(len(checkFile.testCases), 1)
36 self.assertNotEqual(len(checkFile.testCases[0].assertions), 0)
38 def assertIgnored(self, string): argument
39 checkFile = self.tryParse(string)
40 self.assertEqual(len(checkFile.testCases), 1)
41 self.assertEqual(len(checkFile.testCases[0].assertions), 0)
43 def assertInvalid(self, string): argument
44 with self.assertRaises(CheckerException):
45 self.tryParse(string)
47 def test_ValidFormat(self): argument
48 self.assertParses("///CHECK:foo")
49 self.assertParses("##CHECK:bar")
51 def test_InvalidFormat(self): argument
52 self.assertIgnored("CHECK")
53 self.assertIgnored(":CHECK")
54 self.assertIgnored("CHECK:")
55 self.assertIgnored("//CHECK")
56 self.assertIgnored("#CHECK")
57 self.assertInvalid("///CHECK")
58 self.assertInvalid("##CHECK")
60 def test_InvalidPrefix(self): argument
61 self.assertInvalid("///ACHECK:foo")
62 self.assertInvalid("##ACHECK:foo")
64 def test_NotFirstOnTheLine(self): argument
65 self.assertIgnored("A/// CHECK: foo")
66 self.assertIgnored("A # CHECK: foo")
67 self.assertInvalid("/// /// CHECK: foo")
68 self.assertInvalid("## ## CHECK: foo")
70 def test_WhitespaceAgnostic(self): argument
71 self.assertParses(" ///CHECK: foo")
72 self.assertParses("/// CHECK: foo")
73 self.assertParses(" ///CHECK: foo")
74 self.assertParses("/// CHECK: foo")
78 def parseAssertion(self, string, variant=""): argument
82 self.assertEqual(len(checkerFile.testCases), 1)
84 self.assertEqual(len(testCase.assertions), 1)
87 def parseExpression(self, string): argument
88 line = self.parseAssertion(string)
89 self.assertEqual(1, len(line.expressions))
92 def assertEqualsRegex(self, string, expected): argument
93 self.assertEqual(expected, self.parseAssertion(string).toRegex())
95 def assertEqualsText(self, string, text): argument
96 self.assertEqual(self.parseExpression(string), TestExpression.createPatternFromPlainText(text))
98 def assertEqualsPattern(self, string, pattern): argument
99 self.assertEqual(self.parseExpression(string), TestExpression.createPattern(pattern))
101 def assertEqualsVarRef(self, string, name): argument
102 self.assertEqual(self.parseExpression(string), TestExpression.createVariableReference(name))
104 def assertEqualsVarDef(self, string, name, pattern): argument
105 self.assertEqual(self.parseExpression(string),
108 def assertVariantNotEqual(self, string, variant): argument
109 self.assertNotEqual(variant, self.parseExpression(string).variant)
113 def test_TextOnly(self): argument
114 self.assertEqualsText("foo", "foo")
115 self.assertEqualsText(" foo ", "foo")
116 self.assertEqualsRegex("f$o^o", "(f\$o\^o)")
118 def test_PatternOnly(self): argument
119 self.assertEqualsPattern("{{a?b.c}}", "a?b.c")
121 def test_VarRefOnly(self): argument
122 self.assertEqualsVarRef("<<ABC>>", "ABC")
124 def test_VarDefOnly(self): argument
125 self.assertEqualsVarDef("<<ABC:a?b.c>>", "ABC", "a?b.c")
127 def test_TextWithWhitespace(self): argument
128 self.assertEqualsRegex("foo bar", "(foo), (bar)")
129 self.assertEqualsRegex("foo bar", "(foo), (bar)")
131 def test_TextWithRegex(self): argument
132 self.assertEqualsRegex("foo{{abc}}bar", "(foo)(abc)(bar)")
134 def test_TextWithVar(self): argument
135 self.assertEqualsRegex("foo<<ABC:abc>>bar", "(foo)(abc)(bar)")
137 def test_PlainWithRegexAndWhitespaces(self): argument
138 self.assertEqualsRegex("foo {{abc}}bar", "(foo), (abc)(bar)")
139 self.assertEqualsRegex("foo{{abc}} bar", "(foo)(abc), (bar)")
140 self.assertEqualsRegex("foo {{abc}} bar", "(foo), (abc), (bar)")
142 def test_PlainWithVarAndWhitespaces(self): argument
143 self.assertEqualsRegex("foo <<ABC:abc>>bar", "(foo), (abc)(bar)")
144 self.assertEqualsRegex("foo<<ABC:abc>> bar", "(foo)(abc), (bar)")
145 self.assertEqualsRegex("foo <<ABC:abc>> bar", "(foo), (abc), (bar)")
147 def test_AllKinds(self): argument
148 self.assertEqualsRegex("foo <<ABC:abc>>{{def}}bar", "(foo), (abc)(def)(bar)")
149 self.assertEqualsRegex("foo<<ABC:abc>> {{def}}bar", "(foo)(abc), (def)(bar)")
150 self.assertEqualsRegex("foo <<ABC:abc>> {{def}} bar", "(foo), (abc), (def), (bar)")
154 def test_ValidPattern(self): argument
155 self.assertEqualsPattern("{{abc}}", "abc")
156 self.assertEqualsPattern("{{a[b]c}}", "a[b]c")
157 self.assertEqualsPattern("{{(a{bc})}}", "(a{bc})")
159 def test_ValidRef(self): argument
160 self.assertEqualsVarRef("<<ABC>>", "ABC")
161 self.assertEqualsVarRef("<<A1BC2>>", "A1BC2")
163 def test_ValidDef(self): argument
164 self.assertEqualsVarDef("<<ABC:abc>>", "ABC", "abc")
165 self.assertEqualsVarDef("<<ABC:ab:c>>", "ABC", "ab:c")
166 self.assertEqualsVarDef("<<ABC:a[b]c>>", "ABC", "a[b]c")
167 self.assertEqualsVarDef("<<ABC:(a[bc])>>", "ABC", "(a[bc])")
169 def test_Empty(self): argument
170 self.assertEqualsText("{{}}", "{{}}")
171 self.assertVariantNotEqual("<<>>", TestExpression.Variant.VarRef)
172 self.assertVariantNotEqual("<<:>>", TestExpression.Variant.VarDef)
174 def test_InvalidVarName(self): argument
175 self.assertVariantNotEqual("<<0ABC>>", TestExpression.Variant.VarRef)
176 self.assertVariantNotEqual("<<AB=C>>", TestExpression.Variant.VarRef)
177 self.assertVariantNotEqual("<<ABC=>>", TestExpression.Variant.VarRef)
178 self.assertVariantNotEqual("<<0ABC:abc>>", TestExpression.Variant.VarDef)
179 self.assertVariantNotEqual("<<AB=C:abc>>", TestExpression.Variant.VarDef)
180 self.assertVariantNotEqual("<<ABC=:abc>>", TestExpression.Variant.VarDef)
182 def test_BodyMatchNotGreedy(self): argument
183 self.assertEqualsRegex("{{abc}}{{def}}", "(abc)(def)")
184 self.assertEqualsRegex("<<ABC:abc>><<DEF:def>>", "(abc)(def)")
186 def test_NoVarDefsInNotChecks(self): argument
187 with self.assertRaises(CheckerException):
188 self.parseAssertion("<<ABC:abc>>", "-NOT")
195 def createFile(self, caseList): argument
208 def assertParsesTo(self, checkerText, expectedData): argument
209 expectedFile = self.createFile(expectedData)
210 actualFile = self.parse(checkerText)
211 return self.assertEqual(expectedFile, actualFile)
213 def parse(self, checkerText): argument
216 def test_EmptyFile(self): argument
217 self.assertParsesTo("", [])
219 def test_SingleGroup(self): argument
220 self.assertParsesTo(
229 def test_MultipleGroups(self): argument
230 self.assertParsesTo(
244 def test_AssertionVariants(self): argument
245 self.assertParsesTo(
264 def test_MisplacedNext(self): argument
265 with self.assertRaises(CheckerException):
266 self.parse(
272 with self.assertRaises(CheckerException):
273 self.parse(
279 with self.assertRaises(CheckerException):
280 self.parse(
286 with self.assertRaises(CheckerException):
287 self.parse(
311 def parse(self, checkerText): argument
314 def test_NonArchTests(self): argument
316 checkerFile = self.parse(self.noarch_block)
317 self.assertEqual(len(checkerFile.testCases), 1)
318 self.assertEqual(len(checkerFile.testCases[0].assertions), 4)
320 def test_IgnoreNonTargetArch(self): argument
323 checkerText = self.arch_block.format(test_arch = testArch)
324 checkerFile = self.parse(checkerText)
325 self.assertEqual(len(checkerFile.testCases), 1)
326 self.assertEqual(len(checkerFile.testCasesForArch(testArch)), 1)
327 self.assertEqual(len(checkerFile.testCasesForArch(targetArch)), 0)
329 def test_Arch(self): argument
331 checkerText = self.arch_block.format(test_arch = arch)
332 checkerFile = self.parse(checkerText)
333 self.assertEqual(len(checkerFile.testCases), 1)
334 self.assertEqual(len(checkerFile.testCasesForArch(arch)), 1)
335 self.assertEqual(len(checkerFile.testCases[0].assertions), 4)
337 def test_NoDebugAndArch(self): argument
338 testCase = self.parse("""
342 self.assertFalse(testCase.forDebuggable)
343 self.assertEqual(testCase.testArch, None)
345 def test_SetDebugNoArch(self): argument
346 testCase = self.parse("""
350 self.assertTrue(testCase.forDebuggable)
351 self.assertEqual(testCase.testArch, None)
353 def test_NoDebugSetArch(self): argument
354 testCase = self.parse("""
358 self.assertFalse(testCase.forDebuggable)
359 self.assertEqual(testCase.testArch, "ARM")
361 def test_SetDebugAndArch(self): argument
362 testCase = self.parse("""
366 self.assertTrue(testCase.forDebuggable)
367 self.assertEqual(testCase.testArch, "ARM")
370 def parseTestCase(self, string): argument
373 self.assertEqual(len(checkerFile.testCases), 1)
376 def parseExpressions(self, string): argument
377 testCase = self.parseTestCase("/// CHECK-EVAL: " + string)
378 self.assertEqual(len(testCase.assertions), 1)
380 self.assertEqual(assertion.variant, TestAssertion.Variant.Eval)
381 self.assertEqual(assertion.originalText, string)
384 def assertParsesToPlainText(self, text): argument
385 testCase = self.parseTestCase("/// CHECK-EVAL: " + text)
386 self.assertEqual(len(testCase.assertions), 1)
388 self.assertEqual(assertion.variant, TestAssertion.Variant.Eval)
389 self.assertEqual(assertion.originalText, text)
390 self.assertEqual(len(assertion.expressions), 1)
392 self.assertEqual(expression.variant, TestExpression.Variant.PlainText)
393 self.assertEqual(expression.text, text)
395 def test_PlainText(self): argument
396 self.assertParsesToPlainText("XYZ")
397 self.assertParsesToPlainText("True")
398 self.assertParsesToPlainText("{{abc}}")
399 self.assertParsesToPlainText("<<ABC:abc>>")
400 self.assertParsesToPlainText("<<ABC=>>")
402 def test_VariableReference(self): argument
403 self.assertEqual(self.parseExpressions("<<ABC>>"),
405 self.assertEqual(self.parseExpressions("123<<ABC>>"),
408 self.assertEqual(self.parseExpressions("123 <<ABC>>"),
411 self.assertEqual(self.parseExpressions("<<ABC>>XYZ"),
414 self.assertEqual(self.parseExpressions("<<ABC>> XYZ"),
417 self.assertEqual(self.parseExpressions("123<<ABC>>XYZ"),
421 self.assertEqual(self.parseExpressions("123 <<ABC>> XYZ"),