Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: Lib/test/test_ioctl.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_imp.py ('k') | Lib/test/test_io.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import array 1 import array
2 import unittest 2 import unittest
3 from test.support import run_unittest, import_module, get_attribute 3 from test.support import run_unittest, import_module, get_attribute
4 import os, struct 4 import os, struct
5 fcntl = import_module('fcntl') 5 fcntl = import_module('fcntl')
6 termios = import_module('termios') 6 termios = import_module('termios')
7 get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature 7 get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
8 8
9 try: 9 try:
10 tty = open("/dev/tty", "rb") 10 tty = open("/dev/tty", "r")
11 except IOError: 11 except IOError:
12 raise unittest.SkipTest("Unable to open /dev/tty") 12 raise unittest.SkipTest("Unable to open /dev/tty")
13 else: 13 else:
14 # Skip if another process is in foreground 14 # Skip if another process is in foreground
15 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") 15 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
16 tty.close() 16 tty.close()
17 rpgrp = struct.unpack("i", r)[0] 17 rpgrp = struct.unpack("i", r)[0]
18 if rpgrp not in (os.getpgrp(), os.getsid(0)): 18 if rpgrp not in (os.getpgrp(), os.getsid(0)):
19 raise unittest.SkipTest("Neither the process group nor the session " 19 raise unittest.SkipTest("Neither the process group nor the session "
20 "are attached to /dev/tty") 20 "are attached to /dev/tty")
21 del tty, r, rpgrp 21 del tty, r, rpgrp
22 22
23 try: 23 try:
24 import pty 24 import pty
25 except ImportError: 25 except ImportError:
26 pty = None 26 pty = None
27 27
28 class IoctlTests(unittest.TestCase): 28 class IoctlTests(unittest.TestCase):
29 def test_ioctl(self): 29 def test_ioctl(self):
30 # If this process has been put into the background, TIOCGPGRP returns 30 # If this process has been put into the background, TIOCGPGRP returns
31 # the session ID instead of the process group id. 31 # the session ID instead of the process group id.
32 ids = (os.getpgrp(), os.getsid(0)) 32 ids = (os.getpgrp(), os.getsid(0))
33 with open("/dev/tty", "rb") as tty: 33 with open("/dev/tty", "r") as tty:
34 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") 34 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
35 rpgrp = struct.unpack("i", r)[0] 35 rpgrp = struct.unpack("i", r)[0]
36 self.assertIn(rpgrp, ids) 36 self.assertIn(rpgrp, ids)
37 37
38 def _check_ioctl_mutate_len(self, nbytes=None): 38 def _check_ioctl_mutate_len(self, nbytes=None):
39 buf = array.array('i') 39 buf = array.array('i')
40 intsize = buf.itemsize 40 intsize = buf.itemsize
41 ids = (os.getpgrp(), os.getsid(0)) 41 ids = (os.getpgrp(), os.getsid(0))
42 # A fill value unlikely to be in `ids` 42 # A fill value unlikely to be in `ids`
43 fill = -12345 43 fill = -12345
44 if nbytes is not None: 44 if nbytes is not None:
45 # Extend the buffer so that it is exactly `nbytes` bytes long 45 # Extend the buffer so that it is exactly `nbytes` bytes long
46 buf.extend([fill] * (nbytes // intsize)) 46 buf.extend([fill] * (nbytes // intsize))
47 self.assertEqual(len(buf) * intsize, nbytes) # sanity check 47 self.assertEqual(len(buf) * intsize, nbytes) # sanity check
48 else: 48 else:
49 buf.append(fill) 49 buf.append(fill)
50 with open("/dev/tty", "rb") as tty: 50 with open("/dev/tty", "r") as tty:
51 r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) 51 r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
52 rpgrp = buf[0] 52 rpgrp = buf[0]
53 self.assertEqual(r, 0) 53 self.assertEqual(r, 0)
54 self.assertIn(rpgrp, ids) 54 self.assertIn(rpgrp, ids)
55 55
56 def test_ioctl_mutate(self): 56 def test_ioctl_mutate(self):
57 self._check_ioctl_mutate_len() 57 self._check_ioctl_mutate_len()
58 58
59 def test_ioctl_mutate_1024(self): 59 def test_ioctl_mutate_1024(self):
60 # Issue #9758: a mutable buffer of exactly 1024 bytes wouldn't be 60 # Issue #9758: a mutable buffer of exactly 1024 bytes wouldn't be
(...skipping 23 matching lines...) Expand all
84 new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz) 84 new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
85 finally: 85 finally:
86 os.close(mfd) 86 os.close(mfd)
87 os.close(sfd) 87 os.close(sfd)
88 88
89 def test_main(): 89 def test_main():
90 run_unittest(IoctlTests) 90 run_unittest(IoctlTests)
91 91
92 if __name__ == "__main__": 92 if __name__ == "__main__":
93 test_main() 93 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_imp.py ('k') | Lib/test/test_io.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+