Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solaris 11, python2.6 fixes in ptyprocess.py #15

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
before_script: pip install -rrequirements-testing.txt
# command to run tests
script: py.test

# faster builds on travis-ci
sudo: False
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# built documents.
#
# The short X.Y version.
version = '0.4'
version = '0.5'
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
18 changes: 12 additions & 6 deletions ptyprocess/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ def _make_eof_intr():
# ValueError: I/O operation on closed file
fd = sys.__stdout__.fileno()
intr = ord(termios.tcgetattr(fd)[6][VINTR])
eof = ord(termios.tcgetattr(fd)[6][VEOF])
eof_val = termios.tcgetattr(fd)[6][VEOF]
if _is_solaris and isinstance(eof_val, int):
# very strange, on Solaris 11.2-provided python2.6,
# eof_val is an integer (1), not a string ('\x04').
eof = 4
else:
eof = ord(eof_val)
except (ImportError, OSError, IOError, ValueError, termios.error):
# unless the controlling process is also not a terminal,
# such as cron(1), or when stdin and stdout are both closed.
Expand Down Expand Up @@ -263,7 +269,7 @@ def spawn(
preexec_fn()
except Exception as e:
ename = type(e).__name__
tosend = '{}:0:{}'.format(ename, str(e))
tosend = '{0}:0:{1}'.format(ename, str(e))
if PY3:
tosend = tosend.encode('utf-8')

Expand All @@ -279,7 +285,7 @@ def spawn(
except OSError as err:
# [issue #119] 5. If exec fails, the child writes the error
# code back to the parent using the pipe, then exits.
tosend = 'OSError:{}:{}'.format(err.errno, str(err))
tosend = 'OSError:{0}:{1}'.format(err.errno, str(err))
if PY3:
tosend = tosend.encode('utf-8')
os.write(exec_err_pipe_write, tosend)
Expand Down Expand Up @@ -325,7 +331,7 @@ def spawn(
try:
inst.setwinsize(*dimensions)
except IOError as err:
if err.args[0] not in (errno.EINVAL, errno.ENOTTY):
if err.args[0] not in (errno.EINVAL, errno.ENOTTY, errno.ENXIO):
raise

return inst
Expand All @@ -339,10 +345,10 @@ def __repr__(self):
if self.launch_dir is not None:
args.append("cwd=%r" % self.launch_dir)

return "{}.spawn({})".format(clsname, ", ".join(args))
return "{0}.spawn({1})".format(clsname, ", ".join(args))

else:
return "{}(pid={}, fd={})".format(clsname, self.pid, self.fd)
return "{0}(pid={1}, fd={2})".format(clsname, self.pid, self.fd)

@staticmethod
def _coerce_send_string(s):
Expand Down
3 changes: 3 additions & 0 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# unittest2 is a backport of the new features in Python 2.7 and onwards.
# we use this for python2.6, such as "with self.assertRaises(..)"
unittest2
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
readme = f.read()

setup(name='ptyprocess',
version='0.4',
version='0.5',
description="Run a subprocess in a pseudo terminal",
long_description=readme,
author='Thomas Kluyver',
Expand All @@ -26,4 +26,4 @@
'Programming Language :: Python :: 3',
'Topic :: Terminals',
],
)
)
6 changes: 3 additions & 3 deletions tests/test_invalid_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

'''
import time
import unittest
import unittest, unittest2
from ptyprocess import PtyProcess, PtyProcessUnicode
import errno
import os
import stat
import tempfile

class InvalidBinaryChars(unittest.TestCase):
class InvalidBinaryChars(unittest2.TestCase):

def test_invalid_binary(self):
'''This tests that we correctly handle the case where we attempt to
Expand Down Expand Up @@ -67,8 +67,8 @@ def test_invalid_binary(self):
os.unlink(fullpath)
os.rmdir(dirpath)


if __name__ == '__main__':
unittest.main()

suite = unittest.makeSuite(InvalidBinaryChars,'test')

16 changes: 14 additions & 2 deletions tests/test_preexec_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

'''
import unittest
import unittest, unittest2
import shutil
from ptyprocess import PtyProcess
import os
import tempfile

class PreexecFns(unittest.TestCase):
class PreexecFns(unittest2.TestCase):
def setUp(self):
self.pid = os.getpid()

def tearDown(self):
if self.pid != os.getpid():
sys.stderr.write('\nERROR: Test runner has forked! Exiting!\n')
os._exit(1)

def test_preexec(self):
td = tempfile.mkdtemp()
filepath = os.path.join(td, 'foo')
Expand Down Expand Up @@ -56,3 +64,7 @@ def func():
raise


if __name__ == '__main__':
unittest.main()

suite = unittest.makeSuite(PreexecFns, 'test')
17 changes: 15 additions & 2 deletions tests/test_spawn.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
import os
import time
import unittest
import unittest, unittest2
from ptyprocess import PtyProcess, PtyProcessUnicode

class PtyTestCase(unittest.TestCase):
class PtyTestCase(unittest2.TestCase):
def test_spawn_sh(self):
env = os.environ.copy()
env['FOO'] = 'rebar'
Expand Down Expand Up @@ -35,3 +36,15 @@ def test_spawn_unicode_sh(self):

with self.assertRaises(EOFError):
p.read()

def test_quick_spawn(self):
"""Spawn a very short-lived process."""
# so far only reproducable on Solaris 11, spawning a process
# that exits very quickly raised an exception at 'inst.setwinsize',
# because the pty filedes was quickly lost after exec().
PtyProcess.spawn(['/bin/true'])

if __name__ == '__main__':
unittest.main()

suite = unittest.makeSuite(PtyTestCase, 'test')