コード例 #1
0
def test_summarize_bad_report_directory():
    """
    Test the summarizing of cobertura results with a bad report directory.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, _, _ = setup_directories(create_report_directory=False)
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )
    copyfile(
        os.path.join(executor.resource_directory, get_coverage_file_name()),
        cobertura_coverage_file,
    )

    suppplied_arguments = [COBERTURA_COMMAND_LINE_FLAG, cobertura_coverage_file]

    expected_output = ""
    expected_error = """usage: main.py [-h] [--version] [--add-plugin ADD_PLUGIN]
               [--report-dir REPORT_DIR] [--publish-dir PUBLISH_DIR]
               [--cobertura path] [--junit path] [--only-changes] [--publish]
               [--quiet] [--columns DISPLAY_COLUMNS]
main.py: error: argument --report-dir: Path 'report' does not exist."""
    expected_return_code = 2

    # Act
    execute_results = executor.invoke_main(
        arguments=suppplied_arguments, cwd=temporary_work_directory.name
    )

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
コード例 #2
0
def test_summarize_simple_cobertura_report_with_quiet(
    create_publish_directory=False, temporary_work_directory=None
):
    """
    Test the summarizing of a simple cobertura report with no previous summary.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, report_directory, publish_directory = setup_directories(
        create_publish_directory=create_publish_directory,
        temporary_work_directory=temporary_work_directory,
    )
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )
    copyfile(
        os.path.join(executor.resource_directory, get_coverage_file_name()),
        cobertura_coverage_file,
    )
    summary_coverage_file = os.path.join(report_directory, COVERAGE_SUMMARY_FILE_NAME)

    suppplied_arguments = [
        COBERTURA_COMMAND_LINE_FLAG,
        cobertura_coverage_file,
        "--quiet",
    ]

    expected_output = ""
    expected_error = ""
    expected_return_code = 0
    expected_test_coverage_file = compose_coverage_summary_file()

    # Act
    execute_results = executor.invoke_main(
        arguments=suppplied_arguments, cwd=temporary_work_directory.name
    )

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
    execute_results.assert_resultant_file(
        summary_coverage_file, expected_test_coverage_file
    )
    return (
        executor,
        temporary_work_directory,
        publish_directory,
        cobertura_coverage_file,
    )
コード例 #3
0
def test_summarize_bad_test_coverage():
    """
    Test the summarizing of cobertura results with a bad coverage file.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, _, _ = setup_directories()
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )
    copyfile(
        os.path.join(executor.resource_directory, "coverage-bad.txt"),
        cobertura_coverage_file,
    )

    suppplied_arguments = [COBERTURA_COMMAND_LINE_FLAG, cobertura_coverage_file]

    expected_output = f"Project test coverage file '{cobertura_coverage_file}' is not a valid test coverage file.\n"
    expected_error = ""
    expected_return_code = 1

    # Act
    execute_results = executor.invoke_main(
        arguments=suppplied_arguments, cwd=temporary_work_directory.name
    )

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
コード例 #4
0
def test_summarize_cobertura_report_with_source_as_directory():
    """
    Test to make sure that summarizing a test coverage file that is not a file.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, _, _ = setup_directories()
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )

    os.makedirs(cobertura_coverage_file)

    suppplied_arguments = [COBERTURA_COMMAND_LINE_FLAG, cobertura_coverage_file]

    expected_output = (
        f"Project test coverage file '{cobertura_coverage_file}' is not a file.\n"
    )
    expected_error = ""
    expected_return_code = 1

    # Act
    execute_results = executor.invoke_main(
        arguments=suppplied_arguments, cwd=temporary_work_directory.name
    )

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
コード例 #5
0
def test_summarize_simple_cobertura_report_with_error_on_report_write():
    """
    Test a summarize with an error when trying to write the summary report.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, report_directory, _ = setup_directories()
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )
    copyfile(
        os.path.join(executor.resource_directory, get_coverage_file_name()),
        cobertura_coverage_file,
    )
    summary_coverage_file = os.path.join(report_directory, COVERAGE_SUMMARY_FILE_NAME)

    suppplied_arguments = [COBERTURA_COMMAND_LINE_FLAG, cobertura_coverage_file]

    expected_output = (
        f"Project test coverage summary file '{os.path.abspath(summary_coverage_file)}' "
        + "was not written (None).\n"
    )
    expected_error = ""
    expected_return_code = 1

    # Act
    try:
        pbo = PatchBuiltinOpen()
        pbo.register_exception(os.path.abspath(summary_coverage_file), "w")
        pbo.start()

        execute_results = executor.invoke_main(
            arguments=suppplied_arguments, cwd=temporary_work_directory.name
        )
    finally:
        pbo.stop()

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
コード例 #6
0
def test_summarize_invalid_published_summary_file():
    """
    Test the summarizing of cobertura results with a bad report directory.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, _, publish_directory = setup_directories(
        create_publish_directory=True
    )
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )
    copyfile(
        os.path.join(executor.resource_directory, get_coverage_file_name()),
        cobertura_coverage_file,
    )
    summary_coverage_file = os.path.join(publish_directory, COVERAGE_SUMMARY_FILE_NAME)

    with open(summary_coverage_file, "w", encoding="utf-8") as outfile:
        outfile.write("this is not a json file")

    suppplied_arguments = [COBERTURA_COMMAND_LINE_FLAG, cobertura_coverage_file]

    file_name = os.path.join(PUBLISH_DIRECTORY, COVERAGE_SUMMARY_FILE_NAME)
    expected_output = (
        f"Previous coverage summary file '{file_name}' is not "
        + "a valid JSON file (Expecting value: line 1 column 1 (char 0))."
    )
    expected_error = ""
    expected_return_code = 1

    # Act
    execute_results = executor.invoke_main(
        arguments=suppplied_arguments, cwd=temporary_work_directory.name
    )

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
コード例 #7
0
def test_summarize_simple_cobertura_report(
    create_publish_directory=False, temporary_work_directory=None
):
    """
    Test the summarizing of a simple cobertura report with no previous summary.
    """

    # Arrange
    executor = MainlineExecutor()
    temporary_work_directory, report_directory, publish_directory = setup_directories(
        create_publish_directory=create_publish_directory,
        temporary_work_directory=temporary_work_directory,
    )
    cobertura_coverage_file = os.path.join(
        temporary_work_directory.name, get_coverage_file_name()
    )
    copyfile(
        os.path.join(executor.resource_directory, get_coverage_file_name()),
        cobertura_coverage_file,
    )
    summary_coverage_file = os.path.join(report_directory, COVERAGE_SUMMARY_FILE_NAME)

    suppplied_arguments = [COBERTURA_COMMAND_LINE_FLAG, cobertura_coverage_file]

    expected_output = """

Test Coverage Summary
---------------------


  TYPE           COVERED  MEASURED      PERCENTAGE

  Instructions  --        --        -----
  Lines         10 (+10)  15 (+15)  66.67 (+66.67)
  Branches       2 ( +2)   4 ( +4)  50.00 (+50.00)
  Complexity    --        --        -----
  Methods       --        --        -----
  Classes       --        --        -----

"""
    expected_error = ""
    expected_return_code = 0
    expected_test_coverage_file = compose_coverage_summary_file()

    # Act
    execute_results = executor.invoke_main(
        arguments=suppplied_arguments, cwd=temporary_work_directory.name
    )

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
    execute_results.assert_resultant_file(
        summary_coverage_file, expected_test_coverage_file
    )
    return (
        executor,
        temporary_work_directory,
        publish_directory,
        cobertura_coverage_file,
    )