From c3a1ace347c2f0b078a3c69343e32a65c853f883 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 2 Sep 2013 15:18:21 -0700 Subject: [PATCH] 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 3772d797f..8c57c237a 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) -- 2.26.2