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_writer_with_file(self): """LineWriterQueue written file should be correct""" with self.testfile.open('w') as f: q = LineWriterQueue(f) for line in self.lines: q.put(line) q.put(None) with self.testfile.open('r') as f: self.assertEqual( f.readlines(), [x + '\n' for x in self.lines], )
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)), )