def test_command_with_one_pipeline(self): self.assertEqual(shlex_split_and_group_by_commands("cat | python"), [ { cmd: ['cat'], out: subprocess.PIPE, err: None }, { cmd: ['python'], out: None, err: None }, ]) self.assertEqual(shlex_split_and_group_by_commands("cat &| python"), [ { cmd: ['cat'], out: subprocess.PIPE, err: subprocess.STDOUT }, { cmd: ['python'], out: None, err: None }, ])
def test_one_command(self): self.assertEqual( shlex_split_and_group_by_commands("cat"), [ {cmd: ['cat'], out: None, err: None}, ]) self.assertEqual( shlex_split_and_group_by_commands("cat qwer aaa"), [ {cmd: ['cat', 'qwer', 'aaa'], out: None, err: None}, ])
def test_command_with_one_pipeline(self): self.assertEqual( shlex_split_and_group_by_commands("cat | python"), [ {cmd: ['cat'], out: subprocess.PIPE, err: None}, {cmd: ['python'], out: None, err: None}, ]) self.assertEqual( shlex_split_and_group_by_commands("cat &| python"), [ {cmd: ['cat'], out: subprocess.PIPE, err: subprocess.STDOUT}, {cmd: ['python'], out: None, err: None}, ])
def test_one_command(self): self.assertEqual(shlex_split_and_group_by_commands("cat"), [ { cmd: ['cat'], out: None, err: None }, ]) self.assertEqual(shlex_split_and_group_by_commands("cat qwer aaa"), [ { cmd: ['cat', 'qwer', 'aaa'], out: None, err: None }, ])
def test_two_pipelines(self): self.assertEqual( shlex_split_and_group_by_commands("cat | py |& hall"), [ {cmd: ['cat'], out: subprocess.PIPE, err: None}, {cmd: ['py'], out: subprocess.PIPE, err: subprocess.STDOUT}, {cmd: ['hall'], out: None, err: None}])
def test_redirect_stderr_and_pipline_stdout(self): self.assertEqual( shlex_split_and_group_by_commands("cat 2> err.log | py"), [ {cmd: ['cat'], err: {file: 'err.log', mode: 'wb'}, out: subprocess.PIPE}, {cmd: ['py'], err: None, out: None}, ])
def test_command_without_pipeline_and_redirection(self): COMMAND = "echo test" SPITED_RESULT = [ {cmd: ['echo', 'test'], out: None, err: None}, ] result = shlex_split_and_group_by_commands(COMMAND) self.assertEqual(result, SPITED_RESULT)
def test_stdout_redirection(self): self.assertEqual(shlex_split_and_group_by_commands("cat > aaa"), [ { cmd: ['cat'], out: { file: 'aaa', mode: 'wb' }, err: None }, ])
def test_command_without_pipeline_and_redirection(self): COMMAND = "echo test" SPITED_RESULT = [ { cmd: ['echo', 'test'], out: None, err: None }, ] result = shlex_split_and_group_by_commands(COMMAND) self.assertEqual(result, SPITED_RESULT)
def test_two_pipelines(self): self.assertEqual(shlex_split_and_group_by_commands("cat | py |& hall"), [{ cmd: ['cat'], out: subprocess.PIPE, err: None }, { cmd: ['py'], out: subprocess.PIPE, err: subprocess.STDOUT }, { cmd: ['hall'], out: None, err: None }])
def test_redirect_stderr_and_pipline_stdout(self): self.assertEqual( shlex_split_and_group_by_commands("cat 2> err.log | py"), [ { cmd: ['cat'], err: { file: 'err.log', mode: 'wb' }, out: subprocess.PIPE }, { cmd: ['py'], err: None, out: None }, ])
def test_command_with_or_condition_without_pipeline_and_redirection(self): COMMAND = "exit || echo problem" with self.assertRaises(ExecuteCommandParseError): shlex_split_and_group_by_commands(COMMAND)
def test_stdout_and_stderr_redirection(self): self.assertEqual( shlex_split_and_group_by_commands("cat > aaa 2> bbb"), [ {cmd: ['cat'], out: {file: 'aaa', mode: 'wb'}, err: {file: 'bbb', mode: 'wb'}}, ])
def test_command_with_or_condition_without_pipeline_and_redirection(self): COMMAND = "exit || echo problem" with self.assertRaises(ExecuteCommandParseError): shlex_split_and_group_by_commands(COMMAND)
def test_command_with_and_condition_without_pipeline_and_redirection(self): COMMAND = "cd test && ls" with self.assertRaises(ExecuteCommandParseError): shlex_split_and_group_by_commands(COMMAND)
def test_exception_if_redirect_stdout_and_pipline_with_stderr(self): with self.assertRaises(ExecuteCommandParseError) as cm: shlex_split_and_group_by_commands("cat > aaa |& qwe") self.assertIn("Override redirection by pipeline", str(cm.exception))
def test_command_with_and_condition_without_pipeline_and_redirection(self): COMMAND = "cd test && ls" with self.assertRaises(ExecuteCommandParseError): shlex_split_and_group_by_commands(COMMAND)
def test_exception_if_redirect_stdout_and_pipline_with_stderr(self): with self.assertRaises(ExecuteCommandParseError) as cm: shlex_split_and_group_by_commands("cat > aaa |& qwe") self.assertIn("Override redirection by pipeline", str(cm.exception))