Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/samps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# **************************************************************************************

from .errors import SerialReadError
from .errors import SerialReadError, SerialWriteError

# **************************************************************************************

Expand All @@ -19,6 +19,7 @@

__all__: list[str] = [
"SerialReadError",
"SerialWriteError",
]

# **************************************************************************************
12 changes: 12 additions & 0 deletions src/samps/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ def __init__(self, message: str) -> None:


# **************************************************************************************


class SerialWriteError(Exception):
"""
Exception class for serial write errors.
"""

def __init__(self, message: str) -> None:
super().__init__(message)


# **************************************************************************************
27 changes: 26 additions & 1 deletion test/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import unittest

from samps import SerialReadError
from samps import SerialReadError, SerialWriteError

# **************************************************************************************

Expand Down Expand Up @@ -35,3 +35,28 @@ def test_raising_error(self):


# **************************************************************************************


class TestSerialWriteError(unittest.TestCase):
def test_inheritance(self):
"""Test that SerialWriteError inherits from the built-in Exception class."""
self.assertTrue(issubclass(SerialWriteError, Exception))

def test_error_message(self):
"""Test that the error message is correctly set and retrieved."""
test_message = "This is a test error message."
error = SerialWriteError(test_message)
self.assertEqual(str(error), test_message)

def test_raising_error(self):
"""
Test that raising SerialWriteError with a specific message
results in that message being available on the exception.
"""
test_message = "An error occurred."
with self.assertRaises(SerialWriteError) as context:
raise SerialWriteError(test_message)
self.assertEqual(str(context.exception), test_message)


# **************************************************************************************