bpo-39689: Do not test undefined casts to _Bool (GH-18964) (#18965)

- When casting to _Bool, arrays should only contain zeros or ones.
(cherry picked from commit 1ae9cde4b2)

Co-authored-by: Stefan Krah <skrah@bytereef.org>
This commit is contained in:
Miss Islington (bot) 2020-03-12 11:55:36 -07:00 committed by GitHub
parent feaf0c3789
commit 636eecbbbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -2730,6 +2730,10 @@ class TestBufferProtocol(unittest.TestCase):
# be 1D, at least one format must be 'c', 'b' or 'B'.
for _tshape in gencastshapes():
for char in fmtdict['@']:
# Casts to _Bool are undefined if the source contains values
# other than 0 or 1.
if char == "?":
continue
tfmt = ('', '@')[randrange(2)] + char
tsize = struct.calcsize(tfmt)
n = prod(_tshape) * tsize