def test_args(self, mock_subprocess): process = Process('foo', 'bar', 'baz') process.run() mock_subprocess.Popen.assert_called_once_with( ('foo', 'bar', 'baz'), stderr=None, stdin=None, stdout=None, )
def test_env(self, mock_subprocess): env = {'foo': 'bar'} process = Process('foo', 'bar', env=env) process.run() mock_subprocess.Popen.assert_called_once_with( ('foo', 'bar'), env=env, stderr=None, stdin=None, stdout=None, )
def test_pipeline_multiple_process_large_stream(self): pipeline = Process('cat', words_file) | Process('sort', '-r') pipeline.run(stdout=self.stdout) self.assertEqual( self.file_length(words_file), self.file_length(self.stdout_path), )
def test_single_process(self): process = Process('md5sum') stdin = self.fd_from_string('fubar') popen_p = process.run(stdin=stdin, stdout=self.stdout) # pipelines do the waiting for us, Process object do not popen_p.wait() self.assertEqual(popen_p.returncode, 0) self.assertEqual(self.get_stdout(), '5185e8b8fd8a71fc80545e144f91faf2 -\n')
def test_returns_popen(self, mock_subprocess): mock_subprocess.Popen.return_value = 'MOCK_POPEN' process = Process('foo', 'bar') returned = process.run() self.assertEqual(returned, 'MOCK_POPEN')
def test_duplicate_kwargs(self, mock_subprocess): process = Process('foo', 'bar', stdin='fail') with self.assertRaises(TypeError): process.run()
def test_cwd(self, mock_subprocess): process = Process('foo', cwd='/foo') process.run() mock_subprocess.Popen.assert_called_with( ('foo',), cwd='/foo', stderr=None, stdin=None, stdout=None )