Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for helper function json._check_type #716

Merged
merged 14 commits into from
Dec 10, 2024
Prev Previous commit
Next Next commit
add test for callable
DanielYang59 committed Oct 21, 2024
commit 49d46b24b9684af812334a6dc5a1a8b71d9e6ed6
27 changes: 27 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
@@ -1096,6 +1096,33 @@ class B(A):
assert _check_type(b, class_name_A)
assert isinstance(b, A)

def test_callable(self):
# Test function
def my_function():
pass

callable_class_name = (
f"{type(my_function).__module__}.{type(my_function).__qualname__}"
)

assert _check_type(my_function, callable_class_name), callable_class_name
assert isinstance(my_function, type(my_function))

# Test callable class
class MyCallableClass:
def __call__(self):
pass

callable_instance = MyCallableClass()
assert callable(callable_instance)

callable_class_instance_name = f"{type(callable_instance).__module__}.{type(callable_instance).__qualname__}"

assert _check_type(
callable_instance, callable_class_instance_name
), callable_class_instance_name
assert isinstance(callable_instance, MyCallableClass)

DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
def test_numpy(self):
# Test NumPy array
arr = np.array([1, 2, 3])