Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
test: fix test_decorator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidMolareza committed Mar 31, 2023
1 parent 98f9101 commit f1c4508
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import unittest

from def_result.decorator import def_result
from def_result.Result import Result
from tests.helpers import assert_result, assert_result_detail


def test_divide_numbers(a: int, b: int):
def divide_numbers(a: int, b: int):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
Expand All @@ -14,17 +13,17 @@ def test_divide_numbers(a: int, b: int):
class TestDefResultDecorator(unittest.TestCase):
def test_def_result_decorator_ok(self):
# Test that the decorator returns a Result object with ok status when the function runs successfully
decorated_function = def_result(test_divide_numbers)
decorated_function = def_result(divide_numbers)
result = decorated_function(10, 2)

assert_result(test_class=self, result=result, success=True, value=5)

def test_def_result_decorator_error(self):
# Test that the decorator returns a Result object with error status and ExceptionError detail when
# the function raises an exception
self.assertRaises(ValueError, test_divide_numbers, 10, 0)
self.assertRaises(ValueError, divide_numbers, 10, 0)

decorated_function = def_result(test_divide_numbers)
decorated_function = def_result(divide_numbers)
result = decorated_function(10, 0)

assert_result(test_class=self, result=result, success=False, detail=result.detail)
Expand Down

0 comments on commit f1c4508

Please sign in to comment.