def test_queues_with_rev(self): """Line queues should work with rev stdin/stdout""" if not shutil.which('rev'): return self.skipTest('"rev" binary not found') with subprocess.Popen( ['rev'], cwd=str(self.tempdir), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, bufsize=1, ) as proc: stdin = LineWriterQueue(proc.stdin) stdout = LineReaderQueue(proc.stdout) for line in self.lines: stdin.put(line) stdin.put(None) self.assertEqual( self.lines, [x[::-1] for x in iter(stdout.get, None)], )
def test_queue_reader_with_file(self): """LineReaderQueue should read lines correctly""" with self.testfile.open('w') as f: f.writelines(x + '\n' for x in self.lines) with self.testfile.open('r') as f: q = LineReaderQueue(f) self.assertEqual( self.lines, list(iter(q.get, None)), )
def test_queues_with_cat(self): """Line queues should work with cat stdin/stdout""" with subprocess.Popen( ['cat'], cwd=str(self.tempdir), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, bufsize=1, ) as proc: stdin = LineWriterQueue(proc.stdin) stdout = LineReaderQueue(proc.stdout) for line in self.lines: stdin.put(line) stdin.put(None) self.assertEqual( self.lines, list(iter(stdout.get, None)), )