Skip to content

Commit

Permalink
Update test_open_abplus
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Dec 24, 2024
1 parent 819bccb commit c6834fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 9 additions & 7 deletions Tests/modules/system_related/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ def test_strerror(self):
elif is_osx:
self.assertEqual(os.strerror(40), "Message too long")


def test_open_abplus(self):
# equivalent to open(self.temp_file, "ab+"), see also test_file.test_open_abplus
fd = os.open(self.temp_file, os.O_APPEND | os.O_CREAT | os.O_RDWR)
try:
f = open(fd, mode="ab+", closefd=False)
f.write(b"abc")
f.seek(0)
self.assertEqual(f.read(2), b"ab")
f.write(b"def")
self.assertEqual(f.read(2), b"")
f.seek(0)
self.assertEqual(f.read(6), b"abcdef")
f.raw.write(b"abcxxxx")
f.raw.seek(0)
self.assertEqual(f.raw.read(2), b"ab")
f.raw.seek(0, 2)
f.raw.write(b"def")
self.assertEqual(f.raw.read(2), b"")
f.raw.seek(0)
self.assertEqual(f.raw.read(), b"abcxxxxdef")
f.close()
finally:
os.close(fd)
Expand Down
15 changes: 8 additions & 7 deletions Tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,14 +845,15 @@ def test_open_wbplus(self):
f.seek(0)
self.assertEqual(f.read(), b"abdez")


def test_open_abplus(self):
with open(self.temp_file, "ab+") as f:
f.write(b"abc")
f.seek(0)
self.assertEqual(f.read(2), b"ab")
f.write(b"def")
self.assertEqual(f.read(2), b"")
f.seek(0)
self.assertEqual(f.read(6), b"abcdef")
f.raw.write(b"abc")
f.raw.seek(0)
self.assertEqual(f.raw.read(2), b"ab")
f.raw.write(b"def")
self.assertEqual(f.raw.read(2), b"")
f.raw.seek(0)
self.assertEqual(f.raw.read(6), b"abcdef")

run_test(__name__)

0 comments on commit c6834fb

Please sign in to comment.