Skip to content

Commit 906bd71

Browse files
committed
Test arg checking when calling via wrapper functions
1 parent 2492712 commit 906bd71

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

mypyc/test-data/run-classes.test

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,53 @@ def test_buffer_primitive_types() -> None:
27632763
with assertRaises(TypeError):
27642764
r2: ReadBuffer = a4
27652765

2766+
def test_type_check_args_in_write_functions() -> None:
2767+
# Test calling wrapper functions with invalid arg types
2768+
from librt import internal
2769+
alias: Any = internal
2770+
w = WriteBuffer()
2771+
with assertRaises(TypeError):
2772+
alias.write_str(None, "foo")
2773+
with assertRaises(TypeError):
2774+
alias.write_str(w, None)
2775+
with assertRaises(TypeError):
2776+
alias.write_bool(None, True)
2777+
with assertRaises(TypeError):
2778+
alias.write_bool(w, None)
2779+
with assertRaises(TypeError):
2780+
alias.write_bytes(None, b"foo")
2781+
with assertRaises(TypeError):
2782+
alias.write_bytes(w, None)
2783+
with assertRaises(TypeError):
2784+
alias.write_float(None, 1.5)
2785+
with assertRaises(TypeError):
2786+
alias.write_float(w, None)
2787+
with assertRaises(TypeError):
2788+
alias.write_int(None, 15)
2789+
with assertRaises(TypeError):
2790+
alias.write_int(w, None)
2791+
with assertRaises(TypeError):
2792+
alias.write_tag(None, 15)
2793+
with assertRaises(TypeError):
2794+
alias.write_tag(w, None)
2795+
2796+
def test_type_check_buffer_in_read_functions() -> None:
2797+
# Test calling wrapper functions with invalid arg types
2798+
from librt import internal
2799+
alias: Any = internal
2800+
with assertRaises(TypeError):
2801+
alias.read_str(None)
2802+
with assertRaises(TypeError):
2803+
alias.read_bool(None)
2804+
with assertRaises(TypeError):
2805+
alias.read_bytes(None)
2806+
with assertRaises(TypeError):
2807+
alias.read_float(None)
2808+
with assertRaises(TypeError):
2809+
alias.read_int(None)
2810+
with assertRaises(TypeError):
2811+
alias.read_tag(None)
2812+
27662813
def test_buffer_roundtrip() -> None:
27672814
b: WriteBuffer | ReadBuffer
27682815
b = WriteBuffer()

0 commit comments

Comments
 (0)