pypy/module/fcntl/test/test_fcntl.py::AppTestFcntl::()::test_ioctl
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0xf4fc1a4c>
def test_ioctl(self):
import fcntl
import array
import os
import pty
import time
try:
from termios import TIOCGPGRP
except ImportError:
skip("don't know how to test ioctl() on this platform")
raises(TypeError, fcntl.ioctl, "foo")
raises(TypeError, fcntl.ioctl, 0, "foo")
#raises(TypeError, fcntl.ioctl, 0, TIOCGPGRP, float(0))
raises(TypeError, fcntl.ioctl, 0, TIOCGPGRP, 1, "foo")
child_pid, mfd = pty.fork()
if child_pid == 0:
# We're the child
time.sleep(1)
os._exit(0)
try:
# We're the parent, we want TIOCGPGRP calls after child started but before it dies
time.sleep(0.5)
buf = array.array('i', [0])
res = fcntl.ioctl(mfd, TIOCGPGRP, buf, True)
assert res == 0
assert buf[0] != 0
expected = buf.tostring()
buf = array.array('i', [0])
res = fcntl.ioctl(mfd, TIOCGPGRP, buf)
assert res == 0
assert buf.tostring() == expected
buf = array.array('i', [0])
res = fcntl.ioctl(mfd, TIOCGPGRP, buffer(buf))
assert res == expected
assert buf.tostring() == '\x00' * 4
exc = raises(TypeError, fcntl.ioctl, mfd, TIOCGPGRP, memoryview('abc'))
assert 'integer' in str(exc.value)
exc = raises(TypeError, fcntl.ioctl, mfd, TIOCGPGRP, buffer(buf), False)
assert str(exc.value) == "ioctl requires a file or file descriptor, an integer and optionally an integer or buffer argument"
exc = raises(TypeError, fcntl.ioctl, mfd, TIOCGPGRP, memoryview('abc'), False)
assert str(exc.value) == "ioctl requires a file or file descriptor, an integer and optionally an integer or buffer argument"
res = fcntl.ioctl(mfd, TIOCGPGRP, buf, False)
assert res == expected
raises(TypeError, fcntl.ioctl, mfd, TIOCGPGRP, "\x00\x00", True)
res = fcntl.ioctl(mfd, TIOCGPGRP, "\x00\x00\x00\x00")
> assert res == expected
E (application-level) AssertionError: assert '\x00\x00\x00\x00' == 'n\xd8\x0b\x00'
[/build_dir/own-linux-x86-32/build/pypy/module/fcntl/test/test_fcntl.py:196]:56: AssertionError
builder: own-linux-x86-32 build #9378+
test: pypy/module/fcntl/test/test_fcntl.py::AppTestFcntl::()::test_ioctl