| 1 |
# SPDX-License-Identifier: MPL-2.0 |
| 2 |
|
| 3 |
import unittest |
| 4 |
|
| 5 |
|
| 6 |
from cryptodatahub.common.exception import InvalidValue |
| 7 |
|
| 8 |
from cryptoparser.common.exception import InvalidType, NotEnoughData, TooMuchData |
| 9 |
|
| 10 |
|
| 11 |
class TestException(unittest.TestCase): |
| 12 |
def test_str(self): |
| 13 |
with self.assertRaisesRegex( |
| 14 |
NotEnoughData, 'not enough data received from target; missing_byte_count="10"' |
| 15 |
) as context_manager: |
| 16 |
raise NotEnoughData(10) |
| 17 |
self.assertEqual(context_manager.exception.bytes_needed, 10) |
| 18 |
|
| 19 |
with self.assertRaisesRegex( |
| 20 |
TooMuchData, 'too much data received from target; rest_byte_count="10"' |
| 21 |
) as context_manager: |
| 22 |
raise TooMuchData(10) |
| 23 |
self.assertEqual(context_manager.exception.bytes_needed, 10) |
| 24 |
|
| 25 |
with self.assertRaisesRegex( |
| 26 |
InvalidValue, '0xa is not a valid str member name value' |
| 27 |
) as context_manager: |
| 28 |
raise InvalidValue(10, str, 'member name') |
| 29 |
self.assertEqual(context_manager.exception.value, 10) |
| 30 |
|
| 31 |
with self.assertRaisesRegex(InvalidValue, '0xa is not a valid str') as context_manager: |
| 32 |
raise InvalidValue(10, str) |
| 33 |
self.assertEqual(context_manager.exception.value, 10) |
| 34 |
|
| 35 |
with self.assertRaisesRegex(InvalidType, 'invalid type value received from target') as context_manager: |
| 36 |
raise InvalidType(10) |