mirror of
https://github.com/python/cpython.git
synced 2025-08-07 10:28:42 +00:00

svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83212 | florent.xicluna | 2010-07-28 18:39:41 +0200 (mer., 28 juil. 2010) | 2 lines Syntax cleanup. ........ r83829 | florent.xicluna | 2010-08-08 18:16:07 +0200 (dim., 08 août 2010) | 2 lines Use unittest specific methods for some urllib test cases. And replace urllib2 with urllib.request in comments. ........ r83833 | florent.xicluna | 2010-08-08 18:25:27 +0200 (dim., 08 août 2010) | 2 lines Add test case for the HTTPResponse being an iterable. Follow-up of issue #4608. ........ r83838 | florent.xicluna | 2010-08-08 20:03:44 +0200 (dim., 08 août 2010) | 2 lines Typo. ........ r83839 | florent.xicluna | 2010-08-08 20:06:13 +0200 (dim., 08 août 2010) | 2 lines Issue #7564: Skip test_ioctl if another process is attached to /dev/tty. ........ r83878 | florent.xicluna | 2010-08-09 10:29:08 +0200 (lun., 09 août 2010) | 1 line Merge the 2to3 script from /sandbox/trunk/2to3/2to3, revision 72867 (latest). ........ r84019 | florent.xicluna | 2010-08-14 17:56:42 +0200 (sam., 14 août 2010) | 11 lines Merged manually from 2.7 branch to 3.x trunk. ------------------------------------------------------------------------ r79925 | nick.coghlan | 2010-04-10 16:24:36 +0200 (sam. 10 avril 2010) Try to turn some buildbots green by allowing test_multiprocessing to pass even if it hits the sys.exc_clear code in the threading module, and improve the test coverage by making the ctypes dependencies a bit more granular (two of the cited ctypes objects don't exist on my system) ------------------------------------------------------------------------ ........ r84025 | florent.xicluna | 2010-08-14 18:56:27 +0200 (sam., 14 août 2010) | 1 line List Misc/python-config.in in Misc/README. Fix few typos. ........ r84028 | florent.xicluna | 2010-08-14 19:02:49 +0200 (sam., 14 août 2010) | 1 line Fix order. ........ r84032 | florent.xicluna | 2010-08-14 19:15:31 +0200 (sam., 14 août 2010) | 1 line Convert to spaces. ........ r84036 | florent.xicluna | 2010-08-14 20:03:19 +0200 (sam., 14 août 2010) | 1 line Remove bad merge (from svnmerge r82301) ........
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
import unittest
|
|
from test.support import run_unittest, import_module, get_attribute
|
|
import os, struct
|
|
fcntl = import_module('fcntl')
|
|
termios = import_module('termios')
|
|
get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
|
|
|
|
try:
|
|
tty = open("/dev/tty", "r")
|
|
except IOError:
|
|
raise unittest.SkipTest("Unable to open /dev/tty")
|
|
else:
|
|
# Skip if another process is in foreground
|
|
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
|
|
tty.close()
|
|
rpgrp = struct.unpack("i", r)[0]
|
|
if rpgrp not in (os.getpgrp(), os.getsid(0)):
|
|
raise unittest.SkipTest("Neither the process group nor the session "
|
|
"are attached to /dev/tty")
|
|
del tty, r, rpgrp
|
|
|
|
try:
|
|
import pty
|
|
except ImportError:
|
|
pty = None
|
|
|
|
class IoctlTests(unittest.TestCase):
|
|
def test_ioctl(self):
|
|
# If this process has been put into the background, TIOCGPGRP returns
|
|
# the session ID instead of the process group id.
|
|
ids = (os.getpgrp(), os.getsid(0))
|
|
tty = open("/dev/tty", "r")
|
|
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
|
|
rpgrp = struct.unpack("i", r)[0]
|
|
self.assertTrue(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
|
|
|
|
def test_ioctl_mutate(self):
|
|
import array
|
|
buf = array.array('i', [0])
|
|
ids = (os.getpgrp(), os.getsid(0))
|
|
tty = open("/dev/tty", "r")
|
|
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
|
|
rpgrp = buf[0]
|
|
self.assertEquals(r, 0)
|
|
self.assertTrue(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
|
|
|
|
def test_ioctl_signed_unsigned_code_param(self):
|
|
if not pty:
|
|
raise unittest.SkipTest('pty module required')
|
|
mfd, sfd = pty.openpty()
|
|
try:
|
|
if termios.TIOCSWINSZ < 0:
|
|
set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
|
|
set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffff
|
|
else:
|
|
set_winsz_opcode_pos = termios.TIOCSWINSZ
|
|
set_winsz_opcode_maybe_neg, = struct.unpack("i",
|
|
struct.pack("I", termios.TIOCSWINSZ))
|
|
|
|
our_winsz = struct.pack("HHHH",80,25,0,0)
|
|
# test both with a positive and potentially negative ioctl code
|
|
new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
|
|
new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
|
|
finally:
|
|
os.close(mfd)
|
|
os.close(sfd)
|
|
|
|
def test_main():
|
|
run_unittest(IoctlTests)
|
|
|
|
if __name__ == "__main__":
|
|
test_main()
|