0001 import unittest 0002 from test_support import TestSkipped, run_unittest 0003 import os, struct 0004 try: 0005 import fcntl, termios 0006 except ImportError: 0007 raise TestSkipped("No fcntl or termios module") 0008 if not hasattr(termios,'TIOCGPGRP'): 0009 raise TestSkipped("termios module doesn't have TIOCGPGRP") 0010 0011 try: 0012 tty = open("/dev/tty", "r") 0013 tty.close() 0014 except IOError: 0015 raise TestSkipped("Unable to open /dev/tty") 0016 0017 class IoctlTests(unittest.TestCase): 0018 def test_ioctl(self): 0019 pgrp = os.getpgrp() 0020 tty = open("/dev/tty", "r") 0021 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") 0022 self.assertEquals(pgrp, struct.unpack("i", r)[0]) 0023 0024 def test_ioctl_mutate(self): 0025 import array 0026 buf = array.array('i', [0]) 0027 pgrp = os.getpgrp() 0028 tty = open("/dev/tty", "r") 0029 r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) 0030 self.assertEquals(r, 0) 0031 self.assertEquals(pgrp, buf[0]) 0032 0033 def test_main(): 0034 run_unittest(IoctlTests) 0035 0036 if __name__ == "__main__": 0037 test_main() 0038
Generated by PyXR 0.9.4