-# Copyright 2009-2010 Gentoo Foundation
+# Copyright 2009-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
class PtyEofTestCase(TestCase):
- def testPtyEof(self):
+ def testPtyEofFdopenBuffered(self):
# This tests if the following python issue is fixed yet:
# http://bugs.python.org/issue5380
# Since it might not be fixed, mark as todo.
self.assertEqual(_test_pty_eof(), True)
except EnvironmentError:
pass
+
+ def testPtyEofFdopenUnBuffered(self):
+ # New development: It appears that array.fromfile() is usable
+ # with python3 as long as fdopen is called with a bufsize
+ # argument of 0.
+
+ # The result is only valid if openpty does not raise EnvironmentError.
+ if _can_test_pty_eof():
+ try:
+ self.assertEqual(_test_pty_eof(fdopen_buffered=False), True)
+ except EnvironmentError:
+ pass
"""
return platform.system() in ("Linux",)
-def _test_pty_eof():
+def _test_pty_eof(fdopen_buffered=True):
"""
Returns True if this issues is fixed for the currently
running version of python: http://bugs.python.org/issue5380
Raises an EnvironmentError from openpty() if it fails.
+
+ NOTE: This issue is only problematic when array.fromfile()
+ is used, rather than os.read(). However, array.fromfile()
+ is preferred since it is approximatly 10% faster.
+
+ New development: It appears that array.fromfile() is usable
+ with python3 as long as fdopen is called with a bufsize
+ argument of 0.
"""
use_fork = False
if pid is not None:
os.waitpid(pid, 0)
- master_file = os.fdopen(master_fd, 'rb')
+ if fdopen_buffered:
+ master_file = os.fdopen(master_fd, 'rb')
+ else:
+ master_file = os.fdopen(master_fd, 'rb', 0)
eof = False
data = []
iwtd = [master_file]