We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0715ca2 commit 7cce1e7Copy full SHA for 7cce1e7
mypyc/test-data/run-integers.test
@@ -574,6 +574,7 @@ class int:
574
pass
575
576
[case testIntToBytes]
577
+from testutil import assertRaises
578
def to_bytes(n: int, length: int, byteorder: str, signed: bool = False) -> bytes:
579
return n.to_bytes(length, byteorder, signed=signed)
580
def test_to_bytes() -> None:
@@ -583,3 +584,12 @@ def test_to_bytes() -> None:
583
584
assert to_bytes(0, 1, "big") == b'\x00'
585
# test with a value that does not fit in 64 bits
586
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
592
+ to_bytes(-129, 1, "big", True)
593
+ # signed, too large for 1 byte
594
595
+ to_bytes(128, 1, "big", True)
0 commit comments