Kevin Marshall | ab4f810 | 2022-01-31 20:18:43 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 2 | # Copyright 2022 The Chromium Authors |
Kevin Marshall | ab4f810 | 2022-01-31 20:18:43 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import unittest |
| 7 | |
James Lee | 77f3c7ff | 2023-04-13 15:06:26 | [diff] [blame] | 8 | from make_gtest_filter import PascalCaseSplit, CompressWithWildcards, GetFiltersForTests |
Kevin Marshall | ab4f810 | 2022-01-31 20:18:43 | [diff] [blame] | 9 | |
| 10 | |
| 11 | class Foo(unittest.TestCase): |
| 12 | def testSplit(self): |
| 13 | self.assertEqual(list(PascalCaseSplit('testTerm')), ['test', 'Term']) |
| 14 | self.assertEqual(list(PascalCaseSplit('TestTerm')), ['Test', 'Term']) |
| 15 | self.assertEqual(list(PascalCaseSplit('TestTerm80')), |
| 16 | ['Test', 'Term', '80']) |
| 17 | self.assertEqual(list(PascalCaseSplit('TestTerm80Foo')), |
| 18 | ['Test', 'Term', '80', 'Foo']) |
| 19 | self.assertEqual(list(PascalCaseSplit('TestTerm80/Foo')), |
| 20 | ['Test', 'Term', '80', '/', 'Foo']) |
| 21 | |
| 22 | def testDepth(self): |
| 23 | melons = ['A.DoomMelonFooBar', 'A.DoomMelonFooBaz'] |
| 24 | self.assertEqual(list(CompressWithWildcards(melons, 1, 0)), ['A.Doom*']) |
| 25 | self.assertEqual(list(CompressWithWildcards(melons, 2, 0)), |
| 26 | ['A.DoomMelon*']) |
| 27 | self.assertEqual(list(CompressWithWildcards(melons, 3, 0)), |
| 28 | ['A.DoomMelonFoo*']) |
| 29 | self.assertEqual(list(CompressWithWildcards(melons, 4, 0)), |
| 30 | ['A.DoomMelonFooBar', 'A.DoomMelonFooBaz']) |
| 31 | |
| 32 | def testDontWildcardAcrossSuites(self): |
| 33 | self.assertEqual(list(CompressWithWildcards(['A.X', 'B.X'], 1, 0)), |
| 34 | ['A.X', 'B.X']) |
| 35 | |
| 36 | def testCaseNumBoundaryBeforeWildcard(self): |
| 37 | fruit = ['A.DoomMelonFooBar', 'A.DoomMelonFooBaz', 'A.DoomBanana'] |
| 38 | self.assertEqual(list(CompressWithWildcards(fruit, 2, 0)), |
| 39 | ['A.DoomBanana', 'A.DoomMelon*']) |
| 40 | self.assertEqual(list(CompressWithWildcards(fruit, 2, 1)), |
| 41 | ['A.DoomBanana', 'A.DoomMelon*']) |
| 42 | self.assertEqual(list(CompressWithWildcards(fruit, 2, 2)), |
| 43 | ['A.DoomBanana', 'A.DoomMelonFooBar', 'A.DoomMelonFooBaz']) |
| 44 | |
James Lee | 77f3c7ff | 2023-04-13 15:06:26 | [diff] [blame] | 45 | def testGetFiltersForTests(self): |
Tomasz Jurkiewicz | 0c853c7 | 2023-07-27 08:11:17 | [diff] [blame] | 46 | tests = ['TestSuite.TestName'] |
| 47 | self.assertEqual(list(GetFiltersForTests(tests, class_only=True)), [ |
| 48 | 'TestSuite.*', '*/TestSuite.*/*', '*/TestSuite/*.*', 'TestSuite.*/*', |
| 49 | 'TestSuite/*.*' |
| 50 | ]) |
James Lee | 77f3c7ff | 2023-04-13 15:06:26 | [diff] [blame] | 51 | self.assertEqual(list(GetFiltersForTests(tests, class_only=False)), [ |
Tomasz Jurkiewicz | 0c853c7 | 2023-07-27 08:11:17 | [diff] [blame] | 52 | 'TestSuite.TestName', '*/TestSuite.TestName/*', 'TestSuite.TestName/*', |
| 53 | 'TestSuite/*.TestName' |
James Lee | 77f3c7ff | 2023-04-13 15:06:26 | [diff] [blame] | 54 | ]) |
| 55 | |
Kevin Marshall | ab4f810 | 2022-01-31 20:18:43 | [diff] [blame] | 56 | |
| 57 | if __name__ == '__main__': |
| 58 | unittest.main() |