Skip to content

Commit 810133d

Browse files
committed
tests/basics: Add tests for int.from_bytes when src has trailing zeros.
The trailing zeros should be truncated from the converted value.
1 parent c7aa86c commit 810133d

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

tests/basics/int_bytes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little"))
55
print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little"))
66
print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little"))
7+
8+
# check that extra zero bytes don't change the internal int value
9+
print(int.from_bytes(bytes(20), "little") == 0)
10+
print(int.from_bytes(b"\x01" + bytes(20), "little") == 1)

tests/basics/int_bytes_intbig.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
print(il)
88
print(ib)
99
print(il.to_bytes(20, "little"))
10+
11+
# check that extra zero bytes don't change the internal int value
12+
print(int.from_bytes(b + bytes(10), "little") == int.from_bytes(b, "little"))

0 commit comments

Comments
 (0)