Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: recipe_engine/unittests/recipe_test_api_test.py

Issue 2707593002: Whitelist allowed test names
Patch Set: Use correct regex Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_engine/recipe_test_api.py ('k') | unittests/errors_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The LUCI Authors. All rights reserved. 2 # Copyright 2015 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import unittest 6 import unittest
7 7
8 import test_env 8 import test_env
9 9
10 from recipe_engine import recipe_test_api 10 from recipe_engine import recipe_test_api
11 11
12 class EXC(Exception): 12 class EXC(Exception):
13 pass 13 pass
14 14
15 class TestExpectedException(unittest.TestCase): 15 class TestExpectedException(unittest.TestCase):
16 def testRecognizeException(self): 16 def testRecognizeException(self):
17 """An expected exception is correctly recognized.""" 17 """An expected exception is correctly recognized."""
18 test_data = recipe_test_api.TestData() 18 test_data = recipe_test_api.TestData("test")
19 test_data.expect_exception(EXC.__name__) 19 test_data.expect_exception(EXC.__name__)
20 self.assertFalse(test_data.consumed) 20 self.assertFalse(test_data.consumed)
21 21
22 with test_data.should_raise_exception(EXC()) as should_raise: 22 with test_data.should_raise_exception(EXC()) as should_raise:
23 self.assertFalse(should_raise) 23 self.assertFalse(should_raise)
24 24
25 with test_data.should_raise_exception(ValueError()) as should_raise: 25 with test_data.should_raise_exception(ValueError()) as should_raise:
26 self.assertTrue(should_raise) 26 self.assertTrue(should_raise)
27 27
28 self.assertTrue(test_data.consumed) 28 self.assertTrue(test_data.consumed)
29 29
30 def testNewException(self): 30 def testNewException(self):
31 """An unexpected exception results in being told to re-raise .""" 31 """An unexpected exception results in being told to re-raise ."""
32 test_data = recipe_test_api.TestData() 32 test_data = recipe_test_api.TestData("test")
33 self.assertTrue(test_data.consumed) 33 self.assertTrue(test_data.consumed)
34 34
35 with test_data.should_raise_exception(EXC()) as should_raise: 35 with test_data.should_raise_exception(EXC()) as should_raise:
36 self.assertTrue(should_raise) 36 self.assertTrue(should_raise)
37 37
38 self.assertTrue(test_data.consumed) 38 self.assertTrue(test_data.consumed)
39 39
40 def testDisabledTestData(self): 40 def testDisabledTestData(self):
41 """Disabled test data correctly re-raises all exceptions.""" 41 """Disabled test data correctly re-raises all exceptions."""
42 test_data = recipe_test_api.TestData() 42 test_data = recipe_test_api.TestData("test")
43 43
44 with test_data.should_raise_exception(EXC()) as should_raise: 44 with test_data.should_raise_exception(EXC()) as should_raise:
45 self.assertTrue(should_raise) 45 self.assertTrue(should_raise)
46 46
47 def test_invalid_test_names(self):
48 for bad in ('bad name', 'a\////', 'b\\\\', 'c(*#&($'):
49 self.assertFalse(recipe_test_api.is_valid_test_name(bad))
50
51 def test_valid_test_names(self):
52 for good in ('good', 'with_underscores_now', 'and_numbers_1'):
53 self.assertTrue(recipe_test_api.is_valid_test_name(good))
54
47 if __name__ == '__main__': 55 if __name__ == '__main__':
48 unittest.main() 56 unittest.main()
OLDNEW
« no previous file with comments | « recipe_engine/recipe_test_api.py ('k') | unittests/errors_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698