Skip to content

Commit d517197

Browse files
[DOCUMENTATION] Add docstrings to global variables from multicast/exceptions.py (- WIP PR #169 -)
1 parent 427aeab commit d517197

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

multicast/exceptions.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,88 @@ def __init__(self, *args, **kwargs):
233233
143: (SystemExit, 'Terminated (SIGTERM)'),
234234
255: (None, 'Exit Status Out of Range'),
235235
}
236+
"""
237+
Provides a mapping between exit codes and their corresponding exception classes and messages.
238+
239+
The `EXIT_CODES` dictionary serves as a centralized mapping for standard exit codes used within
240+
the multicast module. Each key represents an exit code (as an integer), and each value is a tuple
241+
containing the associated exception class (or `None` if not applicable) and a human-readable description of the exit condition.
242+
243+
CEP-8 Compliance:
244+
In accordance with [CEP-8]
245+
guidelines, this mapping facilitates consistent error handling and exit code management
246+
throughout the module. By associating specific exceptions with standard exit codes, the
247+
application adheres to predictable behavior in response to various error conditions, enhancing
248+
maintainability and debugging efficiency.
249+
250+
Specific codes are detailed more in CEP-8.
251+
252+
Usage Example:
253+
```python
254+
from multicast.exceptions import EXIT_CODES
255+
from multicast.exceptions import get_exit_code_from_exception
256+
257+
try:
258+
# Code that may raise an exception
259+
pass
260+
except Exception as e:
261+
exit_code = get_exit_code_from_exception(e)
262+
sys.exit(exit_code)
263+
```
264+
265+
Testing:
266+
267+
Testcase 0: EXIT_CODES should be automatically imported.
268+
269+
>>> import multicast
270+
>>> import multicast.exceptions
271+
>>> multicast.EXIT_CODES != None
272+
True
273+
>>> isInstance(multicast.EXIT_CODES, dict)
274+
True
275+
276+
"""
236277

237278

238279
EXCEPTION_EXIT_CODES = {exc: code for code, (exc, _) in EXIT_CODES.items() if exc}
280+
"""
281+
Dictionary mapping exception classes to their associated exit codes.
282+
283+
Use this dictionary to retrieve the exit code corresponding to a given exception class.
284+
285+
Minimal Acceptance Testing:
286+
287+
First set up test fixtures by importing multicast.exceptions.
288+
289+
>>> import multicast.exceptions as exceptions
290+
>>> exceptions.__name__
291+
'multicast.exceptions'
292+
293+
Testcase 0: EXCEPTION_EXIT_CODES should be initializable.
294+
295+
>>> from multicast.exceptions import EXCEPTION_EXIT_CODES
296+
>>> EXCEPTION_EXIT_CODES is not None
297+
True
298+
299+
Testcase 1: EXCEPTION_EXIT_CODES should map exceptions to exit codes.
300+
A. - check `RuntimeError` is mapped to `1`.
301+
B. - check `FileNotFoundError` is mapped to `66`.
302+
303+
>>> EXCEPTION_EXIT_CODES[RuntimeError]
304+
1
305+
>>> EXCEPTION_EXIT_CODES[FileNotFoundError]
306+
66
307+
308+
Testcase 2: EXCEPTION_EXIT_CODES should not include None entries.
309+
A. - Test reverse map is not none.
310+
B. - Test reverse map contains only non-None.
311+
312+
>>> None is EXCEPTION_EXIT_CODES
313+
False
314+
>>> None in EXCEPTION_EXIT_CODES
315+
False
316+
317+
"""
239318

240319

241320
def get_exit_code_from_exception(exc):

0 commit comments

Comments
 (0)