|
| 1 | + |
| 2 | + |
| 3 | +import pytest |
| 4 | +from py_spring.core.utils import checking_type_hints_for_callable, TypeHintsNotProvidedError |
| 5 | + |
| 6 | + |
| 7 | +class TestFrameworkUtils: |
| 8 | + |
| 9 | + def test_function_with_argument_type_hints_but_no_return_type(self): |
| 10 | + def test_func(a: int, b: str): |
| 11 | + pass # No return type hint |
| 12 | + with pytest.raises(TypeHintsNotProvidedError, match="Type hints for 'return type' not provided for the function"): |
| 13 | + checking_type_hints_for_callable(test_func) |
| 14 | + |
| 15 | + def test_function_with_no_arguments(self): |
| 16 | + def test_func() -> None: |
| 17 | + pass |
| 18 | + # No exception should be raised for a function with no arguments |
| 19 | + checking_type_hints_for_callable(test_func) |
| 20 | + |
| 21 | + def test_function_with_correct_type_hints(self): |
| 22 | + def test_func(a: int, b: str) -> None: |
| 23 | + pass |
| 24 | + # No exception should be raised |
| 25 | + checking_type_hints_for_callable(test_func) |
| 26 | + |
| 27 | + def test_function_with_no_type_hints(self): |
| 28 | + def test_func(a, b) -> None: |
| 29 | + pass |
| 30 | + with pytest.raises(TypeHintsNotProvidedError, match="Number of type hints does not match the number of arguments"): |
| 31 | + checking_type_hints_for_callable(test_func) |
| 32 | + |
| 33 | + def test_function_with_mismatched_type_hints(self): |
| 34 | + def test_func(a: int, b, c) -> None: |
| 35 | + pass |
| 36 | + # Intentionally using only one type hint |
| 37 | + |
| 38 | + with pytest.raises(TypeHintsNotProvidedError, match="Number of type hints does not match the number of arguments in the function"): |
| 39 | + checking_type_hints_for_callable(test_func) |
| 40 | + |
0 commit comments