1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-06-11 02:18:40 -04:00

Added unit tests

This commit is contained in:
2025-12-09 17:20:23 -05:00
parent 2b2dbb114b
commit d0dfaa42e6
35 changed files with 5426 additions and 48 deletions
+47
View File
@@ -0,0 +1,47 @@
import unittest
from aprsd import exception
class TestExceptions(unittest.TestCase):
"""Unit tests for custom exception classes."""
def test_missing_config_option_exception(self):
"""Test MissingConfigOptionException."""
exc = exception.MissingConfigOptionException('test.option')
self.assertIsInstance(exc, Exception)
self.assertIn('test.option', exc.message)
self.assertIn("Option 'test.option' was not in config file", exc.message)
def test_config_option_bogus_default_exception(self):
"""Test ConfigOptionBogusDefaultException."""
exc = exception.ConfigOptionBogusDefaultException(
'test.option', 'default_value'
)
self.assertIsInstance(exc, Exception)
self.assertIn('test.option', exc.message)
self.assertIn('default_value', exc.message)
self.assertIn('needs to be changed', exc.message)
def test_aprs_client_not_configured_exception(self):
"""Test APRSClientNotConfiguredException."""
exc = exception.APRSClientNotConfiguredException()
self.assertIsInstance(exc, Exception)
self.assertEqual(exc.message, 'APRS client is not configured.')
def test_exception_inheritance(self):
"""Test that exceptions inherit from Exception."""
exc1 = exception.MissingConfigOptionException('test')
exc2 = exception.ConfigOptionBogusDefaultException('test', 'default')
exc3 = exception.APRSClientNotConfiguredException()
self.assertIsInstance(exc1, Exception)
self.assertIsInstance(exc2, Exception)
self.assertIsInstance(exc3, Exception)
def test_exception_raising(self):
"""Test that exceptions can be raised and caught."""
with self.assertRaises(exception.MissingConfigOptionException) as context:
raise exception.MissingConfigOptionException('test.option')
self.assertIn('test.option', str(context.exception))