PipeReaderTestCase: use PopenProcess
authorZac Medico <zmedico@gentoo.org>
Mon, 2 Sep 2013 22:18:21 +0000 (15:18 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 2 Sep 2013 22:18:21 +0000 (15:18 -0700)
pym/portage/tests/process/test_poll.py

index 3772d797fc507c004fc3828ab033a5b35ae5d032..8c57c237aeb3b235f26658f3370125ae310ebb8c 100644 (file)
@@ -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)