Skip to content

Commit 7cce1e7

Browse files
committed
add overflow error tests
1 parent 0715ca2 commit 7cce1e7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mypyc/test-data/run-integers.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ class int:
574574
pass
575575

576576
[case testIntToBytes]
577+
from testutil import assertRaises
577578
def to_bytes(n: int, length: int, byteorder: str, signed: bool = False) -> bytes:
578579
return n.to_bytes(length, byteorder, signed=signed)
579580
def test_to_bytes() -> None:
@@ -583,3 +584,12 @@ def test_to_bytes() -> None:
583584
assert to_bytes(0, 1, "big") == b'\x00'
584585
# test with a value that does not fit in 64 bits
585586
assert to_bytes(10**30, 16, "big") == b'\x00\x00\x00\x0c\x9f,\x9c\xd0Ft\xed\xea@\x00\x00\x00'
587+
# unsigned, too large for 1 byte
588+
with assertRaises(OverflowError):
589+
to_bytes(256, 1, "big")
590+
# signed, too small for 1 byte
591+
with assertRaises(OverflowError):
592+
to_bytes(-129, 1, "big", True)
593+
# signed, too large for 1 byte
594+
with assertRaises(OverflowError):
595+
to_bytes(128, 1, "big", True)

0 commit comments

Comments
 (0)