diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2018-01-27 16:16:37 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2018-01-27 16:16:37 (GMT) |
commit | 4defba3b95ec0f52ce75b8466831d30fb5d333f3 (patch) | |
tree | afd798704c96cc3f12a1ae38ede0863ffef56938 /Lib/test/test_posix.py | |
parent | 60da99b8e2f7bf497569ae4d6c218866575729bf (diff) | |
download | cpython-4defba3b95ec0f52ce75b8466831d30fb5d333f3.zip cpython-4defba3b95ec0f52ce75b8466831d30fb5d333f3.tar.gz cpython-4defba3b95ec0f52ce75b8466831d30fb5d333f3.tar.bz2 |
bpo-31368: Expose preadv and pwritev in the os module (#5239)
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r-- | Lib/test/test_posix.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 6c50406..a7f3d34 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -272,6 +272,28 @@ class PosixTester(unittest.TestCase): finally: os.close(fd) + @unittest.skipUnless(hasattr(posix, 'preadv'), "test needs posix.preadv()") + def test_preadv(self): + fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) + try: + os.write(fd, b'test1tt2t3t5t6t6t8') + buf = [bytearray(i) for i in [5, 3, 2]] + self.assertEqual(posix.preadv(fd, buf, 3), 10) + self.assertEqual([b't1tt2', b't3t', b'5t'], list(buf)) + finally: + os.close(fd) + + @unittest.skipUnless(hasattr(posix, 'RWF_HIPRI'), "test needs posix.RWF_HIPRI") + def test_preadv_flags(self): + fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) + try: + os.write(fd, b'test1tt2t3t5t6t6t8') + buf = [bytearray(i) for i in [5, 3, 2]] + self.assertEqual(posix.preadv(fd, buf, 3, os.RWF_HIPRI), 10) + self.assertEqual([b't1tt2', b't3t', b'5t'], list(buf)) + finally: + os.close(fd) + @unittest.skipUnless(hasattr(posix, 'pwrite'), "test needs posix.pwrite()") def test_pwrite(self): fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) @@ -283,6 +305,34 @@ class PosixTester(unittest.TestCase): finally: os.close(fd) + @unittest.skipUnless(hasattr(posix, 'pwritev'), "test needs posix.pwritev()") + def test_pwritev(self): + fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) + try: + os.write(fd, b"xx") + os.lseek(fd, 0, os.SEEK_SET) + n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2) + self.assertEqual(n, 10) + + os.lseek(fd, 0, os.SEEK_SET) + self.assertEqual(b'xxtest1tt2t3', posix.read(fd, 100)) + finally: + os.close(fd) + + @unittest.skipUnless(hasattr(posix, 'os.RWF_SYNC'), "test needs os.RWF_SYNC") + def test_pwritev_flags(self): + fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) + try: + os.write(fd,b"xx") + os.lseek(fd, 0, os.SEEK_SET) + n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2, os.RWF_SYNC) + self.assertEqual(n, 10) + + os.lseek(fd, 0, os.SEEK_SET) + self.assertEqual(b'xxtest1tt2', posix.read(fd, 100)) + finally: + os.close(fd) + @unittest.skipUnless(hasattr(posix, 'posix_fallocate'), "test needs posix.posix_fallocate()") def test_posix_fallocate(self): |