| OLD | NEW |
| 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() |
| OLD | NEW |