* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2011-08-29 4:00 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2011-08-29 4:00 UTC (permalink / raw
To: gentoo-commits
commit: b76d113b6c23fdcb4dcbf8084e7e3773448d0ff5
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 29 03:59:26 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 29 03:59:26 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=b76d113b
test_poll: fix "ResourceWarning: unclosed file"
---
pym/portage/tests/process/test_poll.py | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index ee6ee0c..c3b50d4 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -34,6 +34,14 @@ class PipeReaderTestCase(TestCase):
scheduler=scheduler)
consumer.start()
- consumer.wait()
+
+ # This will ensure that both tasks have exited, which
+ # is necessary to avoid "ResourceWarning: unclosed file"
+ # warnings since Python 3.2 (and also ensures that we
+ # don't leave any zombie child processes).
+ scheduler.schedule()
+ self.assertEqual(producer.returncode, os.EX_OK)
+ self.assertEqual(consumer.returncode, os.EX_OK)
+
output = consumer.getvalue().decode('ascii', 'replace')
self.assertEqual(test_string, output)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2011-12-16 22:26 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2011-12-16 22:26 UTC (permalink / raw
To: gentoo-commits
commit: 071c65bb4abac3c251f335bde20e13368349c55d
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 16 22:26:01 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Dec 16 22:26:01 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=071c65bb
test_poll: add note about unbuffered fdopen
---
pym/portage/tests/process/test_poll.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index f1ddcb3..30816db 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -25,6 +25,9 @@ class PipeReaderTestCase(TestCase):
else:
got_pty = False
master_fd, slave_fd = os.pipe()
+
+ # WARNING: It is very important to use unbuffered mode here,
+ # in order to avoid issue 5380 with python3.
master_file = os.fdopen(master_fd, 'rb', 0)
slave_file = os.fdopen(slave_fd, 'wb', 0)
producer = SpawnProcess(
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2011-12-18 21:28 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2011-12-18 21:28 UTC (permalink / raw
To: gentoo-commits
commit: 7e2fa62211bacd0eec259578ff3448ab86384323
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 18 21:28:17 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Dec 18 21:28:36 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7e2fa622
PipeReaderArrayTestCase: sleep for fast computers
Allows reliable triggering of the failure mode on fast computers.
---
pym/portage/tests/process/test_poll.py | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index 30816db..1a0c8ce 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -11,6 +11,7 @@ from _emerge.SpawnProcess import SpawnProcess
class PipeReaderTestCase(TestCase):
_use_array = False
+ _echo_cmd = "echo -n '%s'"
def _testPipeReader(self, test_string, use_pty):
"""
@@ -31,7 +32,7 @@ class PipeReaderTestCase(TestCase):
master_file = os.fdopen(master_fd, 'rb', 0)
slave_file = os.fdopen(slave_fd, 'wb', 0)
producer = SpawnProcess(
- args=["bash", "-c", "echo -n '%s'" % test_string],
+ args=["bash", "-c", self._echo_cmd % test_string],
env=os.environ, fd_pipes={1:slave_fd},
scheduler=scheduler)
producer.start()
@@ -67,6 +68,8 @@ class PipeReaderTestCase(TestCase):
class PipeReaderArrayTestCase(PipeReaderTestCase):
_use_array = True
+ # sleep allows reliable triggering of the failure mode on fast computers
+ _echo_cmd = "sleep 0.1 ; echo -n '%s'"
def __init__(self, *args, **kwargs):
super(PipeReaderArrayTestCase, self).__init__(*args, **kwargs)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2011-12-18 21:47 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2011-12-18 21:47 UTC (permalink / raw
To: gentoo-commits
commit: 33f63675eec4274842e118ed0490bc98dd83fe77
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 18 21:47:07 2011 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Dec 18 21:47:07 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=33f63675
test_poll: separate classes for pipe vs. pty
Also, generate appropriate SKIP message if pty is not acquired.
---
pym/portage/tests/process/test_poll.py | 37 +++++++++++++++++++------------
1 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index 1a0c8ce..22c9c2d 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -11,26 +11,33 @@ from _emerge.SpawnProcess import SpawnProcess
class PipeReaderTestCase(TestCase):
_use_array = False
+ _use_pty = False
_echo_cmd = "echo -n '%s'"
- def _testPipeReader(self, test_string, use_pty):
+ def _testPipeReader(self, test_string):
"""
Use a poll loop to read data from a pipe and assert that
the data written to the pipe is identical to the data
read from the pipe.
"""
- scheduler = PollScheduler().sched_iface
- if use_pty:
+ if self._use_pty:
got_pty, master_fd, slave_fd = _create_pty_or_pipe()
+ if not got_pty:
+ os.close(slave_fd)
+ os.close(master_fd)
+ skip_reason = "pty not acquired"
+ self.portage_skip = skip_reason
+ self.fail(skip_reason)
+ return
else:
- got_pty = False
master_fd, slave_fd = os.pipe()
# WARNING: It is very important to use unbuffered mode here,
# in order to avoid issue 5380 with python3.
master_file = os.fdopen(master_fd, 'rb', 0)
slave_file = os.fdopen(slave_fd, 'wb', 0)
+ scheduler = PollScheduler().sched_iface
producer = SpawnProcess(
args=["bash", "-c", self._echo_cmd % test_string],
env=os.environ, fd_pipes={1:slave_fd},
@@ -52,18 +59,17 @@ class PipeReaderTestCase(TestCase):
self.assertEqual(producer.returncode, os.EX_OK)
self.assertEqual(consumer.returncode, os.EX_OK)
- output = consumer.getvalue().decode('ascii', 'replace')
- return (output, got_pty)
+ return consumer.getvalue().decode('ascii', 'replace')
def testPipeReader(self):
- for use_pty in (False, True):
- for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14):
- test_string = x * "a"
- output, got_pty = self._testPipeReader(test_string, use_pty)
- self.assertEqual(test_string, output,
- "x = %s, len(output) = %s, "
- "use_pty = %s, got_pty = %s" %
- (x, len(output), use_pty, got_pty))
+ for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14):
+ test_string = x * "a"
+ output = self._testPipeReader(test_string)
+ self.assertEqual(test_string, output,
+ "x = %s, len(output) = %s" % (x, len(output)))
+
+class PipeReaderPtyTestCase(PipeReaderTestCase):
+ _use_pty = True
class PipeReaderArrayTestCase(PipeReaderTestCase):
@@ -76,3 +82,6 @@ class PipeReaderArrayTestCase(PipeReaderTestCase):
# http://bugs.python.org/issue5380
# https://bugs.pypy.org/issue956
self.todo = True
+
+class PipeReaderPtyArrayTestCase(PipeReaderArrayTestCase):
+ _use_pty = True
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2012-02-09 3:51 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2012-02-09 3:51 UTC (permalink / raw
To: gentoo-commits
commit: c2538626bf1267d2c4fe968ec252d3a7e3d58f9f
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 9 03:51:24 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Feb 9 03:51:24 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c2538626
test_poll: use TaskScheduler
---
pym/portage/tests/process/test_poll.py | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index 8f5d738..d6667b4 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -4,7 +4,7 @@
from portage import os
from portage.tests import TestCase
from portage.util._pty import _create_pty_or_pipe
-from _emerge.PollScheduler import PollScheduler
+from _emerge.TaskScheduler import TaskScheduler
from _emerge.PipeReader import PipeReader
from _emerge.SpawnProcess import SpawnProcess
@@ -37,25 +37,25 @@ class PipeReaderTestCase(TestCase):
# in order to avoid issue 5380 with python3.
master_file = os.fdopen(master_fd, 'rb', 0)
slave_file = os.fdopen(slave_fd, 'wb', 0)
- scheduler = PollScheduler().sched_iface
+ task_scheduler = TaskScheduler(max_jobs=2)
producer = SpawnProcess(
args=["bash", "-c", self._echo_cmd % test_string],
env=os.environ, fd_pipes={1:slave_fd},
- scheduler=scheduler)
- producer.start()
+ scheduler=task_scheduler.sched_iface)
+ task_scheduler.add(producer)
slave_file.close()
consumer = PipeReader(
input_files={"producer" : master_file},
- scheduler=scheduler, _use_array=self._use_array)
+ scheduler=task_scheduler.sched_iface, _use_array=self._use_array)
- consumer.start()
+ task_scheduler.add(consumer)
# This will ensure that both tasks have exited, which
# is necessary to avoid "ResourceWarning: unclosed file"
# warnings since Python 3.2 (and also ensures that we
# don't leave any zombie child processes).
- scheduler.run()
+ task_scheduler.run()
self.assertEqual(producer.returncode, os.EX_OK)
self.assertEqual(consumer.returncode, os.EX_OK)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2012-10-16 19:41 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2012-10-16 19:41 UTC (permalink / raw
To: gentoo-commits
commit: 1ace23869fd296b391f1ad4df1310ef0c1c2ec7c
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 16 19:41:00 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Oct 16 19:41:00 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1ace2386
Test PopenProcess.
---
pym/portage/tests/process/test_PopenProcess.py | 48 ++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/pym/portage/tests/process/test_PopenProcess.py b/pym/portage/tests/process/test_PopenProcess.py
new file mode 100644
index 0000000..e7654fc
--- /dev/null
+++ b/pym/portage/tests/process/test_PopenProcess.py
@@ -0,0 +1,48 @@
+# Copyright 2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+
+from portage import os
+from portage.tests import TestCase
+from portage.util._async.PopenProcess import PopenProcess
+from portage.util._eventloop.global_event_loop import global_event_loop
+from _emerge.PipeReader import PipeReader
+
+class PopenPipeReaderTestCase(TestCase):
+ """
+ Test PopenProcess, which can be useful for Jython support, since it
+ uses the subprocess.Popen instead of os.fork().
+ """
+
+ _echo_cmd = "echo -n '%s'"
+
+ def _testPipeReader(self, test_string):
+ """
+ Use a poll loop to read data from a pipe and assert that
+ the data written to the pipe is identical to the data
+ read from the pipe.
+ """
+
+ producer = PopenProcess(proc=subprocess.Popen(
+ ["bash", "-c", self._echo_cmd % test_string],
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT),
+ pipe_reader=PipeReader(), scheduler=global_event_loop())
+
+ consumer = producer.pipe_reader
+ consumer.input_files = {"producer" : producer.proc.stdout}
+
+ producer.start()
+ producer.wait()
+
+ self.assertEqual(producer.returncode, os.EX_OK)
+ self.assertEqual(consumer.returncode, os.EX_OK)
+
+ return consumer.getvalue().decode('ascii', 'replace')
+
+ def testPipeReader(self):
+ for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14):
+ test_string = x * "a"
+ output = self._testPipeReader(test_string)
+ self.assertEqual(test_string, output,
+ "x = %s, len(output) = %s" % (x, len(output)))
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2012-10-19 2:18 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2012-10-19 2:18 UTC (permalink / raw
To: gentoo-commits
commit: 19c9cc88c3a3569e57eac5b846340141a42e991e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 19 02:18:14 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Oct 19 02:18:14 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=19c9cc88
Test PopenProcess + PipeLogger.
---
pym/portage/tests/process/test_PopenProcess.py | 44 ++++++++++++++++++++++-
1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/pym/portage/tests/process/test_PopenProcess.py b/pym/portage/tests/process/test_PopenProcess.py
index e7654fc..5ede164 100644
--- a/pym/portage/tests/process/test_PopenProcess.py
+++ b/pym/portage/tests/process/test_PopenProcess.py
@@ -2,14 +2,16 @@
# Distributed under the terms of the GNU General Public License v2
import subprocess
+import tempfile
from portage import os
from portage.tests import TestCase
+from portage.util._async.PipeLogger import PipeLogger
from portage.util._async.PopenProcess import PopenProcess
from portage.util._eventloop.global_event_loop import global_event_loop
from _emerge.PipeReader import PipeReader
-class PopenPipeReaderTestCase(TestCase):
+class PopenPipeTestCase(TestCase):
"""
Test PopenProcess, which can be useful for Jython support, since it
uses the subprocess.Popen instead of os.fork().
@@ -40,9 +42,47 @@ class PopenPipeReaderTestCase(TestCase):
return consumer.getvalue().decode('ascii', 'replace')
- def testPipeReader(self):
+ def _testPipeLogger(self, test_string):
+
+ producer = PopenProcess(proc=subprocess.Popen(
+ ["bash", "-c", self._echo_cmd % test_string],
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT),
+ scheduler=global_event_loop())
+
+ fd, log_file_path = tempfile.mkstemp()
+ try:
+
+ consumer = PipeLogger(background=True,
+ input_fd=os.dup(producer.proc.stdout.fileno()),
+ log_file_path=log_file_path)
+
+ # Close the stdout pipe, since we duplicated it, and it
+ # must be closed in order to avoid a ResourceWarning.
+ producer.proc.stdout.close()
+ producer.pipe_reader = consumer
+
+ producer.start()
+ producer.wait()
+
+ self.assertEqual(producer.returncode, os.EX_OK)
+ self.assertEqual(consumer.returncode, os.EX_OK)
+
+ with open(log_file_path, 'rb') as f:
+ content = f.read()
+
+ finally:
+ os.close(fd)
+ os.unlink(log_file_path)
+
+ return content.decode('ascii', 'replace')
+
+ def testPopenPipe(self):
for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14):
test_string = x * "a"
output = self._testPipeReader(test_string)
self.assertEqual(test_string, output,
"x = %s, len(output) = %s" % (x, len(output)))
+
+ output = self._testPipeLogger(test_string)
+ self.assertEqual(test_string, output,
+ "x = %s, len(output) = %s" % (x, len(output)))
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2013-09-02 22:18 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2013-09-02 22:18 UTC (permalink / raw
To: gentoo-commits
commit: c3a1ace347c2f0b078a3c69343e32a65c853f883
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Sep 2 22:18:21 2013 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Sep 2 22:18:21 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c3a1ace3
PipeReaderTestCase: use PopenProcess
---
pym/portage/tests/process/test_poll.py | 36 +++++++++++++++++-----------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index 3772d79..8c57c23 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -1,12 +1,14 @@
-# Copyright 1998-2011 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import subprocess
+
from portage import os
from portage.tests import TestCase
from portage.util._pty import _create_pty_or_pipe
-from portage.util._async.TaskScheduler import TaskScheduler
+from portage.util._async.PopenProcess import PopenProcess
+from portage.util._eventloop.global_event_loop import global_event_loop
from _emerge.PipeReader import PipeReader
-from _emerge.SpawnProcess import SpawnProcess
class PipeReaderTestCase(TestCase):
@@ -36,24 +38,22 @@ class PipeReaderTestCase(TestCase):
# WARNING: It is very important to use unbuffered mode here,
# in order to avoid issue 5380 with python3.
master_file = os.fdopen(master_fd, 'rb', 0)
- slave_file = os.fdopen(slave_fd, 'wb', 0)
- producer = SpawnProcess(
- args=["bash", "-c", self._echo_cmd % test_string],
- env=os.environ, fd_pipes={1:slave_fd})
+ scheduler = global_event_loop()
consumer = PipeReader(
input_files={"producer" : master_file},
- _use_array=self._use_array)
-
- task_scheduler = TaskScheduler(iter([producer, consumer]), max_jobs=2)
-
- # This will ensure that both tasks have exited, which
- # is necessary to avoid "ResourceWarning: unclosed file"
- # warnings since Python 3.2 (and also ensures that we
- # don't leave any zombie child processes).
- task_scheduler.start()
- slave_file.close()
- task_scheduler.wait()
+ _use_array=self._use_array,
+ scheduler=scheduler)
+
+ producer = PopenProcess(
+ pipe_reader=consumer,
+ proc=subprocess.Popen(["bash", "-c", self._echo_cmd % test_string],
+ stdout=slave_fd),
+ scheduler=scheduler)
+
+ producer.start()
+ os.close(slave_fd)
+ producer.wait()
self.assertEqual(producer.returncode, os.EX_OK)
self.assertEqual(consumer.returncode, os.EX_OK)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2018-05-26 10:47 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2018-05-26 10:47 UTC (permalink / raw
To: gentoo-commits
commit: 3b0c52b9ef364dc8e69208ec5341255ac94d41d8
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat May 26 10:44:38 2018 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat May 26 10:44:38 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3b0c52b9
PipeReaderTestCase: cover sockets and named pipes
pym/portage/tests/process/test_poll.py | 74 ++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 25 deletions(-)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index 596ea3088..d71c9b59c 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -1,11 +1,16 @@
-# Copyright 1998-2013 Gentoo Foundation
+# Copyright 1998-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import functools
+import pty
+import shutil
+import socket
+import sys
import subprocess
+import tempfile
from portage import os
from portage.tests import TestCase
-from portage.util._pty import _create_pty_or_pipe
from portage.util._async.PopenProcess import PopenProcess
from portage.util._eventloop.global_event_loop import global_event_loop
from _emerge.PipeReader import PipeReader
@@ -13,28 +18,47 @@ from _emerge.PipeReader import PipeReader
class PipeReaderTestCase(TestCase):
_use_array = False
- _use_pty = False
_echo_cmd = "echo -n '%s'"
- def _testPipeReader(self, test_string):
+ def test_pipe(self):
+ def make_pipes():
+ return os.pipe(), None
+ self._do_test(make_pipes)
+
+ def test_pty_device(self):
+ def make_pipes():
+ try:
+ return pty.openpty(), None
+ except EnvironmentError:
+ self.skipTest('pty not available')
+ self._do_test(make_pipes)
+
+ def test_domain_socket(self):
+ def make_pipes():
+ if sys.version_info >= (3, 2):
+ read_end, write_end = socket.socketpair()
+ return (read_end.detach(), write_end.detach()), None
+ else:
+ self.skipTest('socket detach not supported')
+ self._do_test(make_pipes)
+
+ def test_named_pipe(self):
+ def make_pipes():
+ tempdir = tempfile.mkdtemp()
+ fifo_path = os.path.join(tempdir, 'fifo')
+ os.mkfifo(fifo_path)
+ return ((os.open(fifo_path, os.O_NONBLOCK|os.O_RDONLY),
+ os.open(fifo_path, os.O_NONBLOCK|os.O_WRONLY)),
+ functools.partial(shutil.rmtree, tempdir))
+ self._do_test(make_pipes)
+
+ def _testPipeReader(self, master_fd, slave_fd, test_string):
"""
Use a poll loop to read data from a pipe and assert that
the data written to the pipe is identical to the data
read from the pipe.
"""
- if self._use_pty:
- got_pty, master_fd, slave_fd = _create_pty_or_pipe()
- if not got_pty:
- os.close(slave_fd)
- os.close(master_fd)
- skip_reason = "pty not acquired"
- self.portage_skip = skip_reason
- self.fail(skip_reason)
- return
- else:
- master_fd, slave_fd = os.pipe()
-
# WARNING: It is very important to use unbuffered mode here,
# in order to avoid issue 5380 with python3.
master_file = os.fdopen(master_fd, 'rb', 0)
@@ -60,15 +84,18 @@ class PipeReaderTestCase(TestCase):
return consumer.getvalue().decode('ascii', 'replace')
- def testPipeReader(self):
+ def _do_test(self, make_pipes):
for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14):
test_string = x * "a"
- output = self._testPipeReader(test_string)
- self.assertEqual(test_string, output,
- "x = %s, len(output) = %s" % (x, len(output)))
+ (read_end, write_end), cleanup = make_pipes()
+ try:
+ output = self._testPipeReader(read_end, write_end, test_string)
+ self.assertEqual(test_string, output,
+ "x = %s, len(output) = %s" % (x, len(output)))
+ finally:
+ if cleanup is not None:
+ cleanup()
-class PipeReaderPtyTestCase(PipeReaderTestCase):
- _use_pty = True
class PipeReaderArrayTestCase(PipeReaderTestCase):
@@ -81,6 +108,3 @@ class PipeReaderArrayTestCase(PipeReaderTestCase):
# https://bugs.python.org/issue5380
# https://bugs.pypy.org/issue956
self.todo = True
-
-class PipeReaderPtyArrayTestCase(PipeReaderArrayTestCase):
- _use_pty = True
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/
@ 2018-05-26 22:41 Zac Medico
0 siblings, 0 replies; 10+ messages in thread
From: Zac Medico @ 2018-05-26 22:41 UTC (permalink / raw
To: gentoo-commits
commit: ac5b48b253add3007034f9fdad02779cd3972281
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat May 26 22:38:58 2018 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat May 26 22:38:58 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ac5b48b2
PipeReaderTestCase: wait for consumer
pym/portage/tests/process/test_poll.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index d71c9b59c..f700a5585 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -78,6 +78,7 @@ class PipeReaderTestCase(TestCase):
producer.start()
os.close(slave_fd)
producer.wait()
+ consumer.wait()
self.assertEqual(producer.returncode, os.EX_OK)
self.assertEqual(consumer.returncode, os.EX_OK)
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-05-26 22:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-26 10:47 [gentoo-commits] proj/portage:master commit in: pym/portage/tests/process/ Zac Medico
-- strict thread matches above, loose matches on Subject: below --
2018-05-26 22:41 Zac Medico
2013-09-02 22:18 Zac Medico
2012-10-19 2:18 Zac Medico
2012-10-16 19:41 Zac Medico
2012-02-09 3:51 Zac Medico
2011-12-18 21:47 Zac Medico
2011-12-18 21:28 Zac Medico
2011-12-16 22:26 Zac Medico
2011-08-29 4:00 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox