From: Peter Pentchev Date: Sat, 18 Mar 2023 20:32:42 +0000 (+0200) Subject: Fix a Python bytes/int mismatch in CLI tests X-Git-Tag: v1.5.5~2^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29b8a3d8f2bdd26d6952d5bdb62708aab591e1ae;p=thirdparty%2Fzstd.git Fix a Python bytes/int mismatch in CLI tests In Python 3.x, a single element of a bytes array is returned as an integer number. Thus, NEWLINE is an int variable, and attempting to add it to the line array will fail with a type mismatch error that may be demonstrated as follows: [roam@straylight ~]$ python3 -c 'b"hello" + b"\n"[0]' Traceback (most recent call last): File "", line 1, in TypeError: can't concat int to bytes [roam@straylight ~]$ --- diff --git a/tests/cli-tests/run.py b/tests/cli-tests/run.py index a2e1c1f86..108f71019 100755 --- a/tests/cli-tests/run.py +++ b/tests/cli-tests/run.py @@ -109,7 +109,7 @@ def pop_line(data: bytes) -> typing.Tuple[typing.Optional[bytes], bytes]: the first line always ends in a :\n:, even if it is the last line and :data: doesn't end in :\n:. """ - NEWLINE = b"\n"[0] + NEWLINE = b"\n" if data == b'': return (None, data) @@ -124,7 +124,7 @@ def pop_line(data: bytes) -> typing.Tuple[typing.Optional[bytes], bytes]: data = data[end_idx:] assert len(line) != 0 - if line[-1] != NEWLINE: + if not line.endswith(NEWLINE): line += NEWLINE return (line, data)