Treehugger Robot | f08cd81 | 2018-06-19 01:39:19 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2018 - The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | import unittest |
| 17 | |
| 18 | from acts import error |
| 19 | |
| 20 | |
| 21 | class ActsErrorTest(unittest.TestCase): |
Mark De Ruyter | 8e627fe | 2018-07-11 16:10:20 -0700 | [diff] [blame] | 22 | |
| 23 | def test_assert_key_pulled_from_acts_error_code(self): |
Treehugger Robot | f08cd81 | 2018-06-19 01:39:19 +0000 | [diff] [blame] | 24 | e = error.ActsError() |
| 25 | self.assertEqual(e.error_code, 100) |
Mark De Ruyter | 8e627fe | 2018-07-11 16:10:20 -0700 | [diff] [blame] | 26 | |
| 27 | def test_assert_description_pulled_from_docstring(self): |
| 28 | e = error.ActsError() |
Treehugger Robot | f08cd81 | 2018-06-19 01:39:19 +0000 | [diff] [blame] | 29 | self.assertEqual(e.message, 'Base Acts Error') |
Mark De Ruyter | 8e627fe | 2018-07-11 16:10:20 -0700 | [diff] [blame] | 30 | |
| 31 | def test_error_without_args(self): |
| 32 | e = error.ActsError() |
Mark De Ruyter | 185960b | 2018-07-30 12:50:00 -0700 | [diff] [blame] | 33 | self.assertNotIn('details', e.extra) |
Treehugger Robot | f08cd81 | 2018-06-19 01:39:19 +0000 | [diff] [blame] | 34 | |
| 35 | def test_error_with_args(self): |
Mark De Ruyter | 185960b | 2018-07-30 12:50:00 -0700 | [diff] [blame] | 36 | args = ('hello', ) |
Mark De Ruyter | 8e627fe | 2018-07-11 16:10:20 -0700 | [diff] [blame] | 37 | e = error.ActsError(*args) |
| 38 | self.assertEqual(e.extra['details'], args) |
| 39 | |
| 40 | def test_error_with_kwargs(self): |
| 41 | e = error.ActsError(key='value') |
| 42 | self.assertTrue('key' in e.extra.keys()) |
| 43 | self.assertTrue('value' in e.extra['key']) |
Treehugger Robot | f08cd81 | 2018-06-19 01:39:19 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | unittest.main() |