def test_pipeline_single_process_large_stream(self): with open(words_file) as fd: pipeline = Pipeline() pipeline.add(Process('cat', words_file)) pipeline.run(stdin=fd, stdout=self.stdout) self.assertEqual( self.file_length(words_file), self.file_length(self.stdout_path) )
def test_pipeline_single_process(self): process = Process('md5sum') pipeline = Pipeline([process]) stdin = self.fd_from_string('fubar') popen_p, = pipeline.run(stdin=stdin, stdout=self.stdout) self.assertEqual(popen_p.returncode, 0) self.assertEqual(self.get_stdout(), '5185e8b8fd8a71fc80545e144f91faf2 -\n')
def test_run_single(self): mock_process = mock.Mock() pipeline = Pipeline([mock_process]) processes = pipeline.run('in', 'out') self.assertEqual(len(processes), 1) mock_process.run.assert_called_once_with(stdin='in', stdout='out') # communicate and wait called on only process processes[0].communicate.assert_called_once_with() processes[0].wait.assert_called_once_with()
def test_run_two(self): mock_process_1 = mock.Mock() mock_process_2 = mock.Mock() pipeline = Pipeline([mock_process_1, mock_process_2]) processes = pipeline.run('in', 'out') self.assertEqual(len(processes), 2) # wait called on first processes[0].wait.assert_called_once_with() processes[0].communicate.assert_not_called() # communicate called on last processes[1].wait.assert_not_called() processes[1].communicate.assert_called_once_with()