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

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

Issue 2707593002: Whitelist allowed test names
Patch Set: Comment code. 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
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 os 6 import os
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 import test_env 10 import test_env
11 11
12 from recipe_engine import recipe_test_api 12 from recipe_engine import recipe_test_api
13 13
14 class EXC(Exception): 14 class EXC(Exception):
15 pass 15 pass
16 16
17 class TestExpectedException(unittest.TestCase): 17 class TestExpectedException(unittest.TestCase):
18 def testRecognizeException(self): 18 def testRecognizeException(self):
19 """An expected exception is correctly recognized.""" 19 """An expected exception is correctly recognized."""
20 test_data = recipe_test_api.TestData() 20 test_data = recipe_test_api.TestData("test")
Paweł Hajdan Jr. 2017/02/21 09:53:31 nit: Single quotes ' instead of double " (applies
21 test_data.expect_exception(EXC.__name__) 21 test_data.expect_exception(EXC.__name__)
22 self.assertFalse(test_data.consumed) 22 self.assertFalse(test_data.consumed)
23 23
24 with test_data.should_raise_exception(EXC()) as should_raise: 24 with test_data.should_raise_exception(EXC()) as should_raise:
25 self.assertFalse(should_raise) 25 self.assertFalse(should_raise)
26 26
27 with test_data.should_raise_exception(ValueError()) as should_raise: 27 with test_data.should_raise_exception(ValueError()) as should_raise:
28 self.assertTrue(should_raise) 28 self.assertTrue(should_raise)
29 29
30 self.assertTrue(test_data.consumed) 30 self.assertTrue(test_data.consumed)
31 31
32 def testNewException(self): 32 def testNewException(self):
33 """An unexpected exception results in being told to re-raise .""" 33 """An unexpected exception results in being told to re-raise ."""
34 test_data = recipe_test_api.TestData() 34 test_data = recipe_test_api.TestData("test")
35 self.assertTrue(test_data.consumed) 35 self.assertTrue(test_data.consumed)
36 36
37 with test_data.should_raise_exception(EXC()) as should_raise: 37 with test_data.should_raise_exception(EXC()) as should_raise:
38 self.assertTrue(should_raise) 38 self.assertTrue(should_raise)
39 39
40 self.assertTrue(test_data.consumed) 40 self.assertTrue(test_data.consumed)
41 41
42 def testDisabledTestData(self): 42 def testDisabledTestData(self):
43 """Disabled test data correctly re-raises all exceptions.""" 43 """Disabled test data correctly re-raises all exceptions."""
44 test_data = recipe_test_api.TestData() 44 test_data = recipe_test_api.TestData("test")
45 45
46 with test_data.should_raise_exception(EXC()) as should_raise: 46 with test_data.should_raise_exception(EXC()) as should_raise:
47 self.assertTrue(should_raise) 47 self.assertTrue(should_raise)
48 48
49 def test_invalid_test_names(self):
50 for bad in ('bad name', 'a\////', 'b\\\\', 'c(*#&($'):
51 self.assertFalse(recipe_test_api.is_valid_test_name(bad))
52
53 def test_valid_test_names(self):
54 for good in ('good', 'with_underscores_now', 'and_numbers_1'):
55 self.assertTrue(recipe_test_api.is_valid_test_name(good))
56
49 if __name__ == '__main__': 57 if __name__ == '__main__':
50 unittest.main() 58 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698