diff options
Diffstat (limited to 'anta/tools/misc.py')
-rw-r--r-- | anta/tools/misc.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/anta/tools/misc.py b/anta/tools/misc.py new file mode 100644 index 0000000..c01f7f4 --- /dev/null +++ b/anta/tools/misc.py @@ -0,0 +1,26 @@ +# Copyright (c) 2023-2024 Arista Networks, Inc. +# Use of this source code is governed by the Apache License 2.0 +# that can be found in the LICENSE file. +""" +Toolkit for ANTA. +""" +from __future__ import annotations + +import logging +import traceback + +logger = logging.getLogger(__name__) + + +def exc_to_str(exception: BaseException) -> str: + """ + Helper function that returns a human readable string from an BaseException object + """ + return f"{type(exception).__name__}{f' ({exception})' if str(exception) else ''}" + + +def tb_to_str(exception: BaseException) -> str: + """ + Helper function that returns a traceback string from an BaseException object + """ + return "Traceback (most recent call last):\n" + "".join(traceback.format_tb(exception.__traceback__)) |