Skip to content

Commit 27c99da

Browse files
committed
gh-143378: reduce duplication in unit tests per review
1 parent 5997e90 commit 27c99da

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Lib/test/test_io/test_memoryio.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,29 +861,25 @@ def test_write_concurrent_mutation(self):
861861
# Prevent crashes when buf.write() concurrently mutates 'buf'.
862862
# See: https://github.com/python/cpython/issues/143378.
863863

864-
class TBuf:
865-
def __init__(self, bio):
866-
self.bio = bio
864+
class B:
867865
def __buffer__(self, flags):
868-
self.bio.close()
866+
memio.close()
869867
return memoryview(b"A")
870868

871869
memio = self.ioclass()
872-
self.assertRaises(BufferError, memio.write, TBuf(memio))
870+
self.assertRaises(BufferError, memio.write, B())
873871

874872
@support.cpython_only
875873
def test_writelines_concurrent_mutation(self):
876874
# Prevent crashes when buf.writelines() concurrently mutates 'buf'.
877875
# See: https://github.com/python/cpython/issues/143378.
878-
class TBuf:
879-
def __init__(self, bio):
880-
self.bio = bio
876+
class B:
881877
def __buffer__(self, flags):
882-
self.bio.close()
878+
memio.close()
883879
return memoryview(b"A")
884880

885881
memio = self.ioclass()
886-
self.assertRaises(BufferError, memio.writelines, [TBuf(memio)])
882+
self.assertRaises(BufferError, memio.writelines, [B()])
887883

888884

889885
class CStringIOTest(PyStringIOTest):

0 commit comments

Comments
 (0)