Ejemplo n.º 1
0
    def test_execute_pipe_when_verbose_is_greater_than_3_then_stdout_is_printed_to_terminal(self):
        """Test that stdout is printed to terminal when verbose level > 3."""

        # Arrange
        command = ["test_command", "test_arguments"]

        # Act
        process = Subprocess(command, verbose=8)
        process.execute_pipe("test_directory", "filename")

        # Assert
        self.print_mock.assert_called_once_with("standard_output")
Ejemplo n.º 2
0
    def test_execute_pipe_when_verbose_is_less_than_3_then_stdout_is_not_printed_to_terminal(self):
        """Test that stdout is not printed to terminal when verbose level < 3."""

        # Arrange
        command = ["test_command", "test_arguments"]

        # Act
        process = Subprocess(command, verbose=2)
        process.execute_pipe("test_directory", "filename")

        # Assert
        self.print_mock.assert_not_called()
Ejemplo n.º 3
0
    def test_execute_pipe_when_command_is_executed_then_stdout_is_saved_to_file(self):
        """Test that execute pipe saves sdtout to file."""

        # Arrange
        command = ["test_command", "test_arguments"]

        # Act
        process = Subprocess(command)
        process.execute_pipe("test_directory", "filename")

        # Assert
        self.open_mock.assert_called_once_with(join("test_directory", "filename_yyyymmdd-hhmmss.log"), "wb")
        self.open_mock.has_calls([call().__enter__().write("standard_output")])
Ejemplo n.º 4
0
    def test_execute_pipe_when_non_zero_return_code_then_stdout_is_saved_to_file(self):
        """Test that stdout is saved to file when non zero is returned."""

        # Arrange
        command = ["test_command", "test_arguments"]
        self.run_mock.return_value = SimpleNamespace(stdout=b"standard_out", returncode=1)

        # Act
        process = Subprocess(command)
        with raises(ProcessError):
            process.execute_pipe("test_directory", "filename")

        # Assert
        self.open_mock.assert_called_once_with(join("test_directory", "filename_yyyymmdd-hhmmss.log"), "wb")
        self.open_mock.has_calls([call().__enter__().write("standard_output")])
Ejemplo n.º 5
0
    def test_execute_pipe_when_unable_to_open_logfile_then_subprocess_runtime_error_is_raised(self):
        """Test that execute pipe raises runtime error when unable to open logfile."""

        # Arrange
        command = ["test_command", "test_arguments"]
        self.open_mock.side_effect = FileNotFoundError(None, None, "filename")

        # Act
        process = Subprocess(command)
        with raises(SubprocessRuntimeError) as exception:
            process.execute_pipe("test_directory", "filename")

        # Assert
        assert (
            str(exception.value) == "Unable to open ('filename') and write results.\n"
            "Please use preconditions to enforce: ['OutputDirectoryExists', 'OutputDirectoryIsEmpty']."
        )
Ejemplo n.º 6
0
    def test_execute_pipe_when_command_is_executed_successful_then_stdout_is_returned():
        """Test that execute pipe returns stdout when successful."""

        # Arrange
        command = ["test_command", "test_arguments"]

        # Act
        process = Subprocess(command)
        output = process.execute_pipe("test_directory", "filename")

        # Assert
        assert output.stdout == b"standard_output"
Ejemplo n.º 7
0
def measure_lines_of_code(settings):
    """Measure the lines of code using cloc."""

    report_dir = create_report_directory(settings["report_directory"])
    report_file = os.path.join(report_dir, "code_duplication")

    command = [
        "cloc",
        "--csv",
        "--hide-rate",
        "--quiet",
        "--exclude-dir=test,tst",
        settings["analysis_directory"],
    ]

    process = Subprocess(command, verbose=1)
    output = process.execute_pipe(report_dir, report_file, check_return_code=False)

    return output.stdout.decode("utf-8")
Ejemplo n.º 8
0
def measure_code_duplication(settings):
    """Measure the amount of code duplication."""

    report_dir = create_report_directory(settings["report_directory"])
    report_file = os.path.join(report_dir, "code_duplication")

    measure_function_size_command = [
        "cpd",
        "--language",
        settings["language"],
        "--minimum-tokens",
        settings["tokens"],
        "--format",
        "csv",
        "--files",
        settings["analysis_directory"],
    ]

    process = Subprocess(measure_function_size_command, verbose=1)
    output = process.execute_pipe(report_dir, report_file, check_return_code=False)

    return output.stdout.decode("utf-8")