Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Dec 12, 2024
1 parent a1e894e commit d51c7a5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Tests/modules/system_related/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from iptest import IronPythonTestCase, is_osx, is_linux, is_windows, run_test

class OsTest(IronPythonTestCase):
def setUp(self):
super(OsTest, self).setUp()
self.temp_file = os.path.join(self.temporary_dir, "temp_OSTest_%d.dat" % os.getpid())

def tearDown(self):
self.delete_files(self.temp_file)
return super().tearDown()

def test_strerror(self):
if is_windows:
self.assertEqual(os.strerror(0), "No error")
Expand All @@ -29,4 +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.close()
finally:
os.close(fd)

run_test(__name__)

0 comments on commit d51c7a5

Please sign in to comment.