Skip to content

Commit 011d674

Browse files
[TESTING] Fixup Part 1 (- WIP PR #175 -)
Changes in file multicast/exceptions.py: - minor changes Changes in file tests/__init__.py: - expanded doctest finder Changes in file tests/test_exceptions.py: - aligned class name with [CEP-9](https://gist.github.com/reactive-firewall/d840ee9990e65f302ce2a8d78ebe73f6) - added more test cases to improve coverage slightly.
1 parent 389c93e commit 011d674

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

multicast/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def exit_on_exception(func):
434434
>>> @exit_on_exception
435435
... def system_exit_func():
436436
... raise SystemExit(64)
437-
>>> system_exit_func() #doctest: +IGNORE_EXCEPTION_DETAIL
437+
>>> system_exit_func() #doctest: +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
438438
Traceback (most recent call last):
439439
SystemExit...64...
440440
@@ -446,7 +446,7 @@ def exit_on_exception(func):
446446
>>> @exit_on_exception
447447
... def error_func():
448448
... raise ValueError("Invalid value")
449-
>>> error_func() #doctest: +IGNORE_EXCEPTION_DETAIL
449+
>>> error_func() #doctest: +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
450450
Traceback (most recent call last):
451451
SystemExit...65...
452452
"""

tests/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145

146146

147147
test_cases = (
148-
test_basic.BasicTestSuite, test_exceptions.TestExceptions, test_deps.TestRequirementsTxt,
148+
test_basic.BasicTestSuite, test_exceptions.ExceptionsTestSuite, test_deps.TestRequirementsTxt,
149149
test_build.TestPEP517Build, test_manifest.TestManifestInclusion,
150150
test_install_requires.TestParseRequirements, test_usage.MulticastTestSuite,
151151
test_usage.BasicIntegrationTestSuite, test_hear_server_activate.McastServerActivateTestSuite,
@@ -185,6 +185,11 @@ def load_tests(loader, tests, pattern):
185185
tests = loader.loadTestsFromTestCase(test_class)
186186
suite.addTests(tests)
187187
suite.addTests(doctest.DocTestSuite(module=multicast, test_finder=finder))
188+
suite.addTests(doctest.DocTestSuite(module=multicast.exceptions, test_finder=finder))
189+
suite.addTests(doctest.DocTestSuite(module=multicast.skt, test_finder=finder))
190+
suite.addTests(doctest.DocTestSuite(module=multicast.recv, test_finder=finder))
191+
suite.addTests(doctest.DocTestSuite(module=multicast.send, test_finder=finder))
192+
suite.addTests(doctest.DocTestSuite(module=multicast.hear, test_finder=finder))
188193
return suite
189194

190195

tests/test_exceptions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
raise ImportError("[CWE-758] Failed to import test context") from _cause
3737

3838

39-
class TestExceptions(BasicUsageTestSuite):
39+
class ExceptionsTestSuite(BasicUsageTestSuite):
4040

4141
__module__ = """tests.test_exceptions"""
4242

43+
__name__ = """tests.test_exceptions.ExceptionsTestSuite"""
44+
4345
def test_command_execution_error_with_args(self):
4446
error = multicast.exceptions.CommandExecutionError("Test error", 42)
4547
self.assertEqual(error.message, "Test error")
@@ -49,6 +51,16 @@ def test_command_execution_error_default_exit_code(self):
4951
error = multicast.exceptions.CommandExecutionError("Test error")
5052
self.assertEqual(error.exit_code, 1)
5153

54+
def test_command_execution_error_with_cause(self):
55+
test_cause = RuntimeError("test")
56+
self.assertIsNotNone(test_cause)
57+
error = multicast.exceptions.CommandExecutionError(test_cause, "Test with cause", 77)
58+
self.assertIsNotNone(error)
59+
self.assertIsNotNone(error.__cause__)
60+
self.assertEqual(error.__cause__, test_cause)
61+
self.assertEqual(error.message, "Test with cause")
62+
self.assertEqual(error.exit_code, 77)
63+
5264

5365
# leave this part
5466
if __name__ == '__main__':

0 commit comments

Comments
 (0)