Exemplo n.º 1
0
 def test_get_env__pass_env_false(self):
     task_config = TaskConfig(
         {"options": {
             "pass_env": "False",
             "command": "ls"
         }})
     task = Command(self.project_config, task_config)
     self.assertEqual({}, task._get_env())
Exemplo n.º 2
0
    def test_functional_mock_command(self):
        """ Functional test that runs a command with mocked
        popen results and checks the log.
        """

        self.task_config.config["options"] = {"command": "ls -la"}

        self.Popen.set_command("ls -la", stdout=b"testing testing 123", stderr=b"e")

        task = Command(self.project_config, self.task_config)
        task()

        self.assertTrue(any("testing testing" in s for s in self.task_log["info"]))
Exemplo n.º 3
0
    def test_run_task(self, sarge):
        p = mock.Mock()
        p.returncode = 0
        p.stdout = Capture()
        p.stdout.add_stream(BytesIO(b"testing testing 123"))
        p.stderr = Capture()
        p.stderr.add_stream(BytesIO(b"e"))
        sarge.Command.return_value = p

        self.task_config.config["options"] = {"command": "ls -la"}
        task = Command(self.project_config, self.task_config)
        task()

        assert any("testing testing" in s for s in self.task_log["info"])
Exemplo n.º 4
0
    def test_functional_mock_command(self):
        """ Functional test that runs a command with mocked
        popen results and checks the log.
        """

        self.task_config.config['options'] = {
            'command': 'ls -la',
        }

        self.Popen.set_command('ls -la',
                               stdout=b'testing testing 123',
                               stderr=b'e')

        task = Command(self.project_config, self.task_config)
        task()

        self.assertTrue(
            any("testing testing" in s for s in self.task_log['info']))
Exemplo n.º 5
0
    def test_functional_run_ls(self):
        """ Functional test that actually subprocesses and runs command.

        Checks that command either ran successfully or failed as expected
        so that it can be run on any platform. Other tests will mock
        the subprocess interaction.
        """

        self.task_config.config["options"] = {"command": "ls -la"}

        task = Command(self.project_config, self.task_config)

        # try to run the command and handle the command Exception
        # if no exception, confirm that we logged
        # if exception, confirm exception matches expectations
        try:
            task()
        except CommandException:
            self.assertTrue(any("Return code" in s for s in self.task_log["error"]))

        self.assertTrue(any("total" in s for s in self.task_log["info"]))
Exemplo n.º 6
0
 def test_handle_returncode(self):
     task_config = TaskConfig({"options": {"command": "ls"}})
     task = Command(self.project_config, task_config)
     with self.assertRaises(CommandException):
         task._handle_returncode(1, BytesIO(b"err"))
Exemplo n.º 7
0
 def test_init__dict_env(self):
     task_config = TaskConfig({"options": {"env": {}, "command": "ls"}})
     task = Command(self.project_config, task_config)
     self.assertEqual({}, task.options["env"])
 def test_handle_returncode(self):
     task_config = TaskConfig({"options": {"command": "ls"}})
     task = Command(self.project_config, task_config)
     with self.assertRaises(CommandException):
         task._handle_returncode(1, BytesIO(b"err"))
 def test_get_env__pass_env_false(self):
     task_config = TaskConfig({"options": {"pass_env": "False", "command": "ls"}})
     task = Command(self.project_config, task_config)
     self.assertEqual({}, task._get_env())