Esempio n. 1
0
 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
         },
     ])
Esempio n. 2
0
 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}, ])
Esempio n. 3
0
 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}, ])
Esempio n. 4
0
 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
         },
     ])
Esempio n. 5
0
 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}])
Esempio n. 6
0
 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}, ])
Esempio n. 7
0
    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)
Esempio n. 8
0
 def test_stdout_redirection(self):
     self.assertEqual(shlex_split_and_group_by_commands("cat > aaa"), [
         {
             cmd: ['cat'],
             out: {
                 file: 'aaa',
                 mode: 'wb'
             },
             err: None
         },
     ])
Esempio n. 9
0
    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)
Esempio n. 10
0
 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
                      }])
Esempio n. 11
0
 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
             },
         ])
Esempio n. 12
0
    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)
Esempio n. 13
0
 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'}}, ])
Esempio n. 14
0
    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)
Esempio n. 15
0
    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)
Esempio n. 16
0
    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))
Esempio n. 17
0
    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)
Esempio n. 18
0
    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))