summaryrefslogtreecommitdiff
path: root/Lib/test/test_posix.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-05-29 20:07:40 +0200
committerCharles-François Natali <neologix@free.fr>2011-05-29 20:07:40 +0200
commitdaafdd5bea1edb0fa980727cf8c52bfe7928d6b8 (patch)
tree9a508518d3a596ce11436bff47ada935011c177b /Lib/test/test_posix.py
parent04a90b4611d3a20ac593860d7f4156a14723e84a (diff)
downloadcpython-git-daafdd5bea1edb0fa980727cf8c52bfe7928d6b8.tar.gz
Issue #12196: Add pipe2() to the os module.
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r--Lib/test/test_posix.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 9d9802bb7e..e9103cd880 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -478,6 +478,31 @@ class PosixTester(unittest.TestCase):
os.close(reader)
os.close(writer)
+ @unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
+ def test_pipe2(self):
+ self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
+ self.assertRaises(TypeError, os.pipe2, 0, 0)
+
+ # try calling without flag, like os.pipe()
+ r, w = os.pipe2()
+ os.close(r)
+ os.close(w)
+
+ # test flags
+ r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
+ self.addCleanup(os.close, r)
+ self.addCleanup(os.close, w)
+ self.assertTrue(fcntl.fcntl(r, fcntl.F_GETFD) & fcntl.FD_CLOEXEC)
+ self.assertTrue(fcntl.fcntl(w, fcntl.F_GETFD) & fcntl.FD_CLOEXEC)
+ # try reading from an empty pipe: this should fail, not block
+ self.assertRaises(OSError, os.read, r, 1)
+ # try a write big enough to fill-up the pipe: this should either
+ # fail or perform a partial write, not block
+ try:
+ os.write(w, b'x' * support.PIPE_MAX_SIZE)
+ except OSError:
+ pass
+
def test_utime(self):
if hasattr(posix, 'utime'):
now = time.time()