|
7 | 7 |
|
8 | 8 | import unittest |
9 | 9 |
|
10 | | -from samps import SerialReadError |
| 10 | +from samps import SerialReadError, SerialWriteError |
11 | 11 |
|
12 | 12 | # ************************************************************************************** |
13 | 13 |
|
@@ -35,3 +35,28 @@ def test_raising_error(self): |
35 | 35 |
|
36 | 36 |
|
37 | 37 | # ************************************************************************************** |
| 38 | + |
| 39 | + |
| 40 | +class TestSerialWriteError(unittest.TestCase): |
| 41 | + def test_inheritance(self): |
| 42 | + """Test that SerialWriteError inherits from the built-in Exception class.""" |
| 43 | + self.assertTrue(issubclass(SerialWriteError, Exception)) |
| 44 | + |
| 45 | + def test_error_message(self): |
| 46 | + """Test that the error message is correctly set and retrieved.""" |
| 47 | + test_message = "This is a test error message." |
| 48 | + error = SerialWriteError(test_message) |
| 49 | + self.assertEqual(str(error), test_message) |
| 50 | + |
| 51 | + def test_raising_error(self): |
| 52 | + """ |
| 53 | + Test that raising SerialWriteError with a specific message |
| 54 | + results in that message being available on the exception. |
| 55 | + """ |
| 56 | + test_message = "An error occurred." |
| 57 | + with self.assertRaises(SerialWriteError) as context: |
| 58 | + raise SerialWriteError(test_message) |
| 59 | + self.assertEqual(str(context.exception), test_message) |
| 60 | + |
| 61 | + |
| 62 | +# ************************************************************************************** |
0 commit comments