File size: 1,106 Bytes
d8d14f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from swarms.utils.try_except_wrapper import try_except_wrapper


def test_try_except_wrapper_with_no_exception():
    @try_except_wrapper
    def add(x, y):
        return x + y

    result = add(1, 2)
    assert (
        result == 3
    ), "The function should return the sum of the arguments"


def test_try_except_wrapper_with_exception():
    @try_except_wrapper
    def divide(x, y):
        return x / y

    result = divide(1, 0)
    assert (
        result is None
    ), "The function should return None when an exception is raised"


def test_try_except_wrapper_with_multiple_arguments():
    @try_except_wrapper
    def concatenate(*args):
        return "".join(args)

    result = concatenate("Hello", " ", "world")
    assert (
        result == "Hello world"
    ), "The function should concatenate the arguments"


def test_try_except_wrapper_with_keyword_arguments():
    @try_except_wrapper
    def greet(name="world"):
        return f"Hello, {name}"

    result = greet(name="Alice")
    assert (
        result == "Hello, Alice"
    ), "The function should use the keyword arguments"