diff --git a/tawazi/_helpers.py b/tawazi/_helpers.py index 43b102a..cf40d3d 100644 --- a/tawazi/_helpers.py +++ b/tawazi/_helpers.py @@ -1,9 +1,10 @@ """Module for helper functions.""" + from typing import Any, Callable, Dict, NoReturn, TypeVar import yaml -from tawazi.errors import TawaziArgumentException +from tawazi.errors import TawaziArgumentError def ordinal(numb: int) -> str: @@ -72,7 +73,7 @@ def make_raise_arg_error(func_name: str, arg_name: str) -> Callable[[], NoReturn # declare a local function that will raise an error in the scheduler if # the user doesn't pass in This ArgExecNode as argument to the Attached LazyExecNode def local_func() -> NoReturn: - raise TawaziArgumentException(func_name, arg_name) + raise TawaziArgumentError(func_name, arg_name) return local_func diff --git a/tawazi/errors.py b/tawazi/errors.py index 81efc19..776d2c3 100644 --- a/tawazi/errors.py +++ b/tawazi/errors.py @@ -1,13 +1,13 @@ """Module for custom errors raised by Tawazi.""" -class TawaziBaseException(Exception): +class TawaziError(Exception): """BaseException of Tawazi from which all other exceptions inherit.""" pass -class TawaziArgumentException(TawaziBaseException): +class TawaziArgumentError(TawaziError): """Raised when using Tawazi (Passing the wrong number/type of arguments etc.).""" def __init__(self, func_name: str, arg_name: str) -> None: @@ -21,19 +21,19 @@ def __init__(self, func_name: str, arg_name: str) -> None: super().__init__(msg) -class TawaziTypeError(TawaziBaseException): +class TawaziTypeError(TawaziError): """Raised when using Tawazi (Passing the wrong type of arguments etc.).""" pass -class TawaziUsageError(TawaziBaseException): +class TawaziUsageError(TawaziError): """Raised when User miss uses Tawazi.""" pass -class InvalidExecNodeCall(TawaziBaseException): +class InvalidExecNodeCallError(TawaziError): """Raised when a ExecNode is called outside DAG definition (this will change in the future).""" pass diff --git a/tawazi/node/node.py b/tawazi/node/node.py index 9107a05..b40cf74 100644 --- a/tawazi/node/node.py +++ b/tawazi/node/node.py @@ -1,4 +1,5 @@ """Module describing ExecNode Class and subclasses (The basic building Block of a DAG.""" + import dataclasses import functools import inspect @@ -31,7 +32,7 @@ TagOrTags, XNOutsideDAGCall, ) -from tawazi.errors import TawaziBaseException, TawaziUsageError +from tawazi.errors import TawaziError, TawaziUsageError from tawazi.node.uxn import UsageExecNode from tawazi.profile import Profile @@ -241,7 +242,7 @@ def execute(self, results: Dict[Identifier, Any], profiles: Dict[Identifier, Pro results[self.id] = self.exec_function(*args, **kwargs) except Exception as e: if self.call_location: - raise TawaziBaseException( + raise TawaziError( f"Error occurred while executing ExecNode {self.id} at {self.call_location}" ) from e @@ -421,7 +422,7 @@ def _validate_dependencies(self) -> None: for dep in self.dependencies: # if ExecNode is not a debug node, all its dependencies must not be debug node if not self.debug and exec_nodes[dep.id].debug: - raise TawaziBaseException(f"Non debug node {self} depends on debug node {dep}") + raise TawaziError(f"Non debug node {self} depends on debug node {dep}") # if ExecNode is a setup node, all its dependencies should be either: # 1. setup nodes @@ -429,7 +430,7 @@ def _validate_dependencies(self) -> None: # 3. Arguments passed directly to the PipeLine (ArgExecNode) accepted_case = exec_nodes[dep.id].setup or isinstance(exec_nodes[dep.id], ArgExecNode) if self.setup and not accepted_case: - raise TawaziBaseException(f"setup node {self} depends on non setup node {dep}") + raise TawaziError(f"setup node {self} depends on non setup node {dep}") @property def _usage_exec_node(self) -> Union[Tuple[UsageExecNode, ...], UsageExecNode]: diff --git a/tests/test_dag_input_output.py b/tests/test_dag_input_output.py index 33ea663..d500df7 100644 --- a/tests/test_dag_input_output.py +++ b/tests/test_dag_input_output.py @@ -2,7 +2,7 @@ import pytest from tawazi import dag, xn -from tawazi.errors import TawaziArgumentException, TawaziBaseException +from tawazi.errors import TawaziArgumentError, TawaziError @xn @@ -29,7 +29,7 @@ def test_pipeline_input_output_skipping_default_params() -> None: def test_pipeline_input_output_missing_argument() -> None: - with pytest.raises(TawaziBaseException): + with pytest.raises(TawaziError): declare_dag_function() # type: ignore[call-arg] @@ -46,7 +46,7 @@ def test_pipeline_args_input_not_provided() -> None: def pipe(in1: int, in2: int, in3: int, in4: int) -> Tuple[int, ...]: return op1(in1), op1(in2), op1(in3), op1(in4) - with pytest.raises(TawaziArgumentException): + with pytest.raises(TawaziArgumentError): pipe() # type: ignore[call-arg] diff --git a/tests/test_debug_nodes.py b/tests/test_debug_nodes.py index c3660c5..e615303 100644 --- a/tests/test_debug_nodes.py +++ b/tests/test_debug_nodes.py @@ -3,7 +3,7 @@ import pytest from tawazi import dag, xn -from tawazi.errors import TawaziBaseException +from tawazi.errors import TawaziError from .common import stub @@ -91,7 +91,7 @@ def pipeline(img: List[Any]) -> List[Any]: def test_wrongly_defined_pipeline() -> None: - with pytest.raises(TawaziBaseException): + with pytest.raises(TawaziError): @dag def pipeline(img: List[Any]) -> int: diff --git a/tests/test_error_location.py b/tests/test_error_location.py index f6c35a3..2a259a1 100644 --- a/tests/test_error_location.py +++ b/tests/test_error_location.py @@ -3,7 +3,7 @@ import pytest from tawazi import dag, xn -from tawazi.errors import TawaziBaseException +from tawazi.errors import TawaziError @xn @@ -25,7 +25,7 @@ def test_raise_error_location() -> None: pipe_lineno = inspect.getsourcelines(pipe)[1] with pytest.raises( - TawaziBaseException, + TawaziError, match=f"Error occurred while executing ExecNode faulty_function at {pipe_path}:{pipe_lineno + 1}", ): dag_pipe() diff --git a/tests/test_setup_nodes.py b/tests/test_setup_nodes.py index 5df5060..4782468 100644 --- a/tests/test_setup_nodes.py +++ b/tests/test_setup_nodes.py @@ -4,7 +4,7 @@ import pytest from tawazi import dag, xn -from tawazi.errors import TawaziBaseException, TawaziUsageError +from tawazi.errors import TawaziError, TawaziUsageError from .common import run_pipeline @@ -62,7 +62,7 @@ def op1() -> bool: def setup_op(non_setup_result: Any) -> bool: return False - with pytest.raises(TawaziBaseException): + with pytest.raises(TawaziError): @dag def bad_pipe() -> None: