예제 #1
0
    def test_execute_raises_exception_with_subprocess_called_process_error_exception(self):
        """Test that execute raises an process error exception."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command)

        self.check_call_mock.side_effect = CalledProcessError("Error", "process_name")

        # Act
        # Assert
        with raises(ProcessError):
            process.execute()
예제 #2
0
    def test_execute_raises_exception_with_subprocess_timeout_expired_exception(self):
        """Test that execute raises and process timeout expired exception."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command)

        self.check_call_mock.side_effect = TimeoutExpired("Error", "timout_value")

        # Act
        # Assert
        with raises(ProcessError):
            process.execute()
예제 #3
0
def measure_lines_of_code(input_dir, report_file, measure_filter):
    """Measure the lines of code using a filter."""

    measure_language_size_command = [
        "cloc",
        "--csv",
        "--csv-delimiter=,",
        "--hide-rate",
        f"--report-file={report_file}",
        measure_filter,
        input_dir,
    ]

    process = Subprocess(measure_language_size_command, verbose=1)
    process.execute()
예제 #4
0
def measure_function_metrics(input_dir, output_dir):
    """Measure the function metrics."""

    function_metrics_file = os.path.join(output_dir, "function_metrics.csv")

    measure_function_size_command = [
        "lizard",
        "--csv",
        f"-o{function_metrics_file}",
        input_dir,
    ]

    process = Subprocess(measure_function_size_command, verbose=3)
    process.execute()

    return function_metrics_file
예제 #5
0
    def test_standard_streams_are_modified_when_overridden(self):
        """Test that standard streams are modified when overridden."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command, stdout="stdout_stream", stderr="stderr_stream")

        # Act
        process.execute()

        # Assert
        self.check_call_mock.assert_called_once_with(
            ["/test_path/test_command", "test_arguments"],
            stdout="stdout_stream",
            stderr="stderr_stream",
            shell=False,
            timeout=None,
        )
예제 #6
0
    def test_execute_is_successful_with_correct_command_parameters(self):
        """Test that execute is successful with correct command parameters."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command)

        # Act
        process.execute()

        # Assert
        self.check_call_mock.assert_called_once_with(
            ["/test_path/test_command", "test_arguments"],
            stdout=DEVNULL,
            stderr=DEVNULL,
            shell=False,
            timeout=None,
        )
예제 #7
0
    def test_execute_runs_subprocess_with_correct_timeout_value_with_timeout_set(self):
        """Test that execute runs subprocess times out at specified moment."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command, timeout=180)

        # Act
        process.execute()

        # Assert
        self.check_call_mock.assert_called_once_with(
            ["/test_path/test_command", "test_arguments"],
            stdout=DEVNULL,
            stderr=DEVNULL,
            shell=False,
            timeout=180,
        )
예제 #8
0
    def test_execute_runs_subprocess_with_stdout_redirect_with_defined_stdout_stream_and_verbose_greater_than_3(self):
        """Test that execute run subprocess with stdout redirected to stream output with verbose level > 3."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command, stdout="stdout_stream", stderr="stderr_stream", verbose=8)

        # Act
        process.execute()

        # Assert
        self.check_call_mock.assert_called_once_with(
            ["/test_path/test_command", "test_arguments"],
            stdout=None,
            stderr=None,
            shell=False,
            timeout=None,
        )
예제 #9
0
    def test_execute_runs_subprocess_with_stderr_output_with_verbose_is_2(self):
        """Test that execute run subprocess with stderr output with verbose level 2."""

        # Arrange
        command = ["test_command", "test_arguments"]
        process = Subprocess(command, stdout="stdout_stream", stderr="stderr_stream", verbose=2)

        # Act
        process.execute()

        # Assert
        self.check_call_mock.assert_called_once_with(
            ["/test_path/test_command", "test_arguments"],
            stdout="stdout_stream",
            stderr=None,
            shell=False,
            timeout=None,
        )