From d51c7a5d4e3641659695c34e5ed295424c5ae327 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Wed, 11 Dec 2024 20:44:07 -0800 Subject: [PATCH] Add test --- Tests/modules/system_related/test_os.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Tests/modules/system_related/test_os.py b/Tests/modules/system_related/test_os.py index 24784fd4a..d27c6dece 100644 --- a/Tests/modules/system_related/test_os.py +++ b/Tests/modules/system_related/test_os.py @@ -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") @@ -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__)