Skip to content

Commit ac5bf09

Browse files
committed
refactor: refactor test_search_methods_reentrancy_raises_buffererror make it more readable
1 parent b816ac7 commit ac5bf09

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Lib/test/test_bytes.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,21 +2062,21 @@ def __index__(self):
20622062

20632063
def test_search_methods_reentrancy_raises_buffererror(self):
20642064
# gh-142560: Raise BufferError if buffer mutates during search arg conversion.
2065-
ba = bytearray(b"A")
20662065
class Evil:
2066+
def __init__(self, ba):
2067+
self.ba = ba
20672068
def __index__(self):
2068-
ba.clear()
2069-
return 65 # ord('A')
2070-
with self.assertRaises(BufferError):
2071-
ba.find(Evil())
2072-
with self.assertRaises(BufferError):
2073-
ba.count(Evil())
2074-
with self.assertRaises(BufferError):
2075-
ba.index(Evil())
2076-
with self.assertRaises(BufferError):
2077-
ba.rindex(Evil())
2078-
with self.assertRaises(BufferError):
2079-
ba.rfind(Evil())
2069+
self.ba.clear()
2070+
return 65
2071+
2072+
def make_case():
2073+
ba = bytearray(b"A")
2074+
return ba, Evil(ba)
2075+
2076+
for name in ("find", "count", "index", "rindex", "rfind"):
2077+
ba, evil = make_case()
2078+
with self.assertRaises(BufferError):
2079+
getattr(ba, name)(evil)
20802080

20812081

20822082
class AssortedBytesTest(unittest.TestCase):

0 commit comments

Comments
 (0)