summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-09-05 04:54:48 -0700
committerZac Medico <zmedico@gentoo.org>2010-09-05 04:55:32 -0700
commit93ef99895d96000d8f09c1c698a8bab66821778a (patch)
tree0d15044bb1ac0be5aa59f8fb0a73033d572c2d14
parent52dce90afa4a67726df729512f3b5d7aa3e22137 (diff)
downloadportage-93ef99895d96000d8f09c1c698a8bab66821778a.tar.gz
portage-93ef99895d96000d8f09c1c698a8bab66821778a.tar.bz2
portage-93ef99895d96000d8f09c1c698a8bab66821778a.zip
Clean up and simplify PipeReaderTestCase.
-rw-r--r--pym/portage/tests/process/test_poll.py41
1 files changed, 12 insertions, 29 deletions
diff --git a/pym/portage/tests/process/test_poll.py b/pym/portage/tests/process/test_poll.py
index 19cc05710..579acf907 100644
--- a/pym/portage/tests/process/test_poll.py
+++ b/pym/portage/tests/process/test_poll.py
@@ -1,7 +1,6 @@
-# Copyright 1998-2008 Gentoo Foundation
+# Copyright 1998-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import sys
from portage import os
from portage.tests import TestCase
from _emerge.TaskScheduler import TaskScheduler
@@ -10,12 +9,6 @@ from _emerge.SpawnProcess import SpawnProcess
class PipeReaderTestCase(TestCase):
- def _create_pipe(self):
- return os.pipe()
-
- def _assertEqual(self, test_string, consumer_value):
- self.assertEqual(test_string, consumer_value)
-
def testPipeReader(self):
"""
Use a poll loop to read data from a pipe and assert that
@@ -25,32 +18,22 @@ class PipeReaderTestCase(TestCase):
test_string = 2 * "blah blah blah\n"
- master_fd, slave_fd = self._create_pipe()
+ task_scheduler = TaskScheduler()
+ master_fd, slave_fd = os.pipe()
master_file = os.fdopen(master_fd, 'rb')
-
- task_scheduler = TaskScheduler(max_jobs=2)
- scheduler = task_scheduler.sched_iface
-
- class Producer(SpawnProcess):
- def _spawn(self, args, **kwargs):
- rval = SpawnProcess._spawn(self, args, **kwargs)
- os.close(kwargs['fd_pipes'][1])
- return rval
-
- producer = Producer(
+ slave_file = os.fdopen(slave_fd, 'wb')
+ producer = SpawnProcess(
args=["bash", "-c", "echo -n '%s'" % test_string],
- fd_pipes={1:slave_fd}, scheduler=scheduler)
+ env=os.environ, fd_pipes={1:slave_fd},
+ scheduler=task_scheduler.sched_iface)
+ producer.start()
+ slave_file.close()
consumer = PipeReader(
input_files={"producer" : master_file},
- scheduler=scheduler)
+ scheduler=task_scheduler.sched_iface)
- task_scheduler.add(producer)
task_scheduler.add(consumer)
-
task_scheduler.run()
-
- if sys.hexversion >= 0x3000000:
- test_string = test_string.encode()
-
- self._assertEqual(test_string, consumer.getvalue())
+ output = consumer.getvalue().decode('ascii', 'replace')
+ self.assertEqual(test_string, output)