Skip to content

Commit

Permalink
Update test_open_abplus (IronLanguages#1851)
Browse files Browse the repository at this point in the history
* Update test_open_abplus

* Skip test_dict.DictTest.test_container_iterator on Mono
  • Loading branch information
BCSharp authored Dec 25, 2024
1 parent 819bccb commit 8aaa27b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 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
6 changes: 4 additions & 2 deletions Tests/test_dict_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def load_tests(loader, standard_tests, pattern):
test.test_dict.DictTest('test_oob_indexing_dictiter_iternextitem'),
test.test_dict.DictTest('test_setdefault_atomic'),
]

skip_tests = []
if is_mono:
failing_tests += [
skip_tests += [
test.test_dict.DictTest('test_container_iterator'), # https://github.com/IronLanguages/ironpython3/issues/544
]

return generate_suite(tests, failing_tests)
return generate_suite(tests, failing_tests, skip_tests)

else:
return tests
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 8aaa27b

Please sign in to comment.