예제 #1
0
def test_coverage_totals_not_equal():
    """
    Test to make sure the coverage totals is not equal to another total of almost the same amount.
    """

    # Arrange
    first_line_coverage_measured = 20
    second_line_coverage_measured = 21

    first_total = CoverageTotals(project_name="?", report_source="pytest")
    first_total.branch_level = CoverageMeasurement(total_covered=5, total_measured=10)
    first_total.line_level = CoverageMeasurement(
        total_covered=15, total_measured=first_line_coverage_measured
    )

    second_total = CoverageTotals(project_name="?", report_source="pytest")
    second_total.branch_level = CoverageMeasurement(total_covered=5, total_measured=10)
    second_total.line_level = CoverageMeasurement(
        total_covered=15, total_measured=second_line_coverage_measured
    )

    # Act
    actual_result = first_total == second_total

    # Assert
    assert not actual_result
예제 #2
0
def test_pytest_cobertura_profile():
    """
    Test to make sure the model handles the cobertura profile used by pytest.
    """

    # Arrange
    coverage_profile = CoverageTotals(project_name="?", report_source="pytest")
    coverage_profile.branch_level = CoverageMeasurement(total_covered=5,
                                                        total_measured=10)
    coverage_profile.line_level = CoverageMeasurement(total_covered=15,
                                                      total_measured=20)

    g_branch = {"totalCovered": 5, "totalMeasured": 10}
    g_line = {"totalCovered": 15, "totalMeasured": 20}
    expected_dictionary = {
        "projectName": "?",
        "reportSource": "pytest",
        "branchLevel": g_branch,
        "lineLevel": g_line,
    }

    # Act
    coverage_profile_as_dictionary = coverage_profile.to_dict()
    back_from_dictionary = CoverageTotals.from_dict(
        coverage_profile_as_dictionary)

    # Assert
    assert coverage_profile_as_dictionary == expected_dictionary
    assert back_from_dictionary == coverage_profile
예제 #3
0
    def __compose_summary_from_cobertura_document(
            self, cobertura_document: Any,
            coverage_provider_name: str) -> CoverageTotals:
        """
        Compose a CoverageTotals instance from the Cobetura based document.
        """

        project_name = cobertura_document.find("./sources/source").text
        project_name = os.path.basename(project_name)
        coverage_totals = CoverageTotals(project_name=project_name,
                                         report_source=coverage_provider_name)

        measured_lines, covered_lines, measured_branches, covered_branches = 0, 0, 0, 0
        for next_package in cobertura_document.findall("./packages/package"):
            for next_class in next_package.findall("./classes/class"):
                for next_line in next_class.findall("./lines/line"):
                    (
                        covered_line_delta,
                        line_branch_coverage,
                        line_branch_measured,
                    ) = self.__process_line_node(next_line)
                    measured_lines += 1
                    covered_lines += covered_line_delta
                    covered_branches += line_branch_coverage
                    measured_branches += line_branch_measured

        coverage_totals.line_level = CoverageMeasurement(
            total_covered=covered_lines, total_measured=measured_lines)
        coverage_totals.branch_level = CoverageMeasurement(
            total_covered=covered_branches, total_measured=measured_branches)
        return coverage_totals
예제 #4
0
def test_coverage_measurements_equal():
    """
    Test to make sure the coverage measurements is equal to another measurement of the same amount.
    """

    # Arrange
    first_measurement = CoverageMeasurement(total_covered=5, total_measured=10)

    second_measurement = CoverageMeasurement(total_covered=5, total_measured=10)

    # Act
    actual_result = first_measurement == second_measurement

    # Assert
    assert actual_result
예제 #5
0
def test_coverage_totals_not_equal_different_object():
    """
    Test to make sure the coverage totals is not equal to another object that is not a total object.
    """

    # Arrange
    first_total = CoverageTotals(project_name="?", report_source="pytest")
    first_total.branch_level = CoverageMeasurement(total_covered=5, total_measured=10)
    first_total.line_level = CoverageMeasurement(total_covered=15, total_measured=20)

    # Act
    actual_result = first_total == "second_total"

    # Assert
    assert not actual_result
예제 #6
0
def test_made_up_profile():
    """
    Test to make sure the model can test a fictional profile that does not have
    any line or branch measurements, say a coverage of assembly instructions.
    """

    # Arrange
    coverage_profile = CoverageTotals(project_name="?",
                                      report_source="asmunit")
    coverage_profile.instruction_level = CoverageMeasurement(total_covered=25,
                                                             total_measured=30)

    g_instructions = {"totalCovered": 25, "totalMeasured": 30}
    expected_dictionary = {
        "projectName": "?",
        "reportSource": "asmunit",
        "instructionLevel": g_instructions,
    }

    # Act
    coverage_profile_as_dictionary = coverage_profile.to_dict()
    back_from_dictionary = CoverageTotals.from_dict(
        coverage_profile_as_dictionary)

    # Assert
    assert coverage_profile_as_dictionary == expected_dictionary
    assert back_from_dictionary == coverage_profile
예제 #7
0
def test_coverage_measurements_not_equal():
    """
    Test to make sure the coverage measurements is not equal to another measurement of almost the same amount.
    """

    # Arrange
    first_total_measurement = 20
    second_total_measurement = 21

    first_measurement = CoverageMeasurement(
        total_covered=5, total_measured=first_total_measurement
    )

    second_measurement = CoverageMeasurement(
        total_covered=5, total_measured=second_total_measurement
    )

    # Act
    actual_result = first_measurement == second_measurement

    # Assert
    assert not actual_result
예제 #8
0
def test_coverage_measurement_not_equal_different_object():
    """
    Test to make sure the coverage measurements is not equal to another object that is not a total object.
    """

    # Arrange
    first_measurement = CoverageMeasurement(total_covered=5, total_measured=10)

    # Act
    actual_result = first_measurement == "second_measurement"

    # Assert
    assert not actual_result
예제 #9
0
def test_junit_jacoco_profile():
    """
    Test to make sure the model handles the jacoco profile used by junit.
    """

    # Arrange
    coverage_profile = CoverageTotals(project_name="?", report_source="junit")
    coverage_profile.instruction_level = CoverageMeasurement(total_covered=25,
                                                             total_measured=30)
    coverage_profile.line_level = CoverageMeasurement(total_covered=15,
                                                      total_measured=20)
    coverage_profile.branch_level = CoverageMeasurement(total_covered=5,
                                                        total_measured=10)
    coverage_profile.complexity_level = CoverageMeasurement(total_covered=6,
                                                            total_measured=11)
    coverage_profile.method_level = CoverageMeasurement(total_covered=3,
                                                        total_measured=4)
    coverage_profile.class_level = CoverageMeasurement(total_covered=1,
                                                       total_measured=1)

    g_instructions = {"totalCovered": 25, "totalMeasured": 30}
    g_line = {"totalCovered": 15, "totalMeasured": 20}
    g_branch = {"totalCovered": 5, "totalMeasured": 10}
    g_complexity = {"totalCovered": 6, "totalMeasured": 11}
    g_method = {"totalCovered": 3, "totalMeasured": 4}
    g_class = {"totalCovered": 1, "totalMeasured": 1}
    expected_dictionary = {
        "projectName": "?",
        "reportSource": "junit",
        "instructionLevel": g_instructions,
        "lineLevel": g_line,
        "branchLevel": g_branch,
        "complexityLevel": g_complexity,
        "methodLevel": g_method,
        "classLevel": g_class,
    }

    # Act
    coverage_profile_as_dictionary = coverage_profile.to_dict()
    back_from_dictionary = CoverageTotals.from_dict(
        coverage_profile_as_dictionary)

    # Assert
    assert coverage_profile_as_dictionary == expected_dictionary
    assert back_from_dictionary == coverage_profile