Example #1
0
def test_find_not_equal_value_not_deep():
    """Check if the maximum value is found in a dictionary deep."""
    input_file_one = {"John": 21, "Mike": 21, "Sarah": 21, "Bob": 21}
    found = util.get_first_not_equal_value(input_file_one, 21)
    assert found == (0, 0)
Example #2
0
def invoke_all_comment_checks(filecheck,
                              directory,
                              expected_count,
                              comment_type,
                              language,
                              exact=False):
    """Perform the comment check and return the results."""
    met_or_exceeded_count = 0
    actual_count = 0
    comment_count_details = {}
    # check single-line comments
    if comment_type == constants.comments.Single_Line:
        # check comments in Java
        if language == constants.languages.Java:
            met_or_exceeded_count, actual_count, comment_count_details = entities.entity_greater_than_count(
                filecheck,
                directory,
                expected_count,
                comments.count_singleline_java_comment,
                exact,
            )
        # check comments in Python
        if language == constants.languages.Python:
            met_or_exceeded_count, actual_count, comment_count_details = entities.entity_greater_than_count(
                filecheck,
                directory,
                expected_count,
                comments.count_singleline_python_comment,
                exact,
            )
    # check multiple-line comments
    elif comment_type == constants.comments.Multiple_Line:
        # check comments in Java
        if language == constants.languages.Java:
            met_or_exceeded_count, actual_count, comment_count_details = entities.entity_greater_than_count(
                filecheck,
                directory,
                expected_count,
                comments.count_multiline_java_comment,
                exact,
            )
        # check comments in Python
        if language == constants.languages.Python:
            met_or_exceeded_count, actual_count, comment_count_details = entities.entity_greater_than_count(
                filecheck,
                directory,
                expected_count,
                comments.count_multiline_python_comment,
                exact,
            )
    # check comments in a not-supported language
    # currently the only valid options are:
    # --> single-line
    # --> multiple-line
    # this means that this check will fail because
    # it will not find any of the specified comments
    else:
        pass
    # create the message and the diagnostic
    if not exact:
        # create an "at least" message, which is the default
        message = ("The " + filecheck + " in " + directory + " has at least " +
                   str(expected_count) + constants.markers.Space +
                   comment_type + constants.markers.Space + language +
                   " comment(s)")
    else:
        # create an "exact" message, which is an opt-in
        message = ("The " + filecheck + " in " + directory + " has exactly " +
                   str(expected_count) + constants.markers.Space +
                   comment_type + constants.markers.Space + language +
                   " comment(s)")
    # --> exactness is not required, so find the first minimum value
    if not exact:
        actual_count = util.get_first_minimum_value_deep(comment_count_details)
        if actual_count != (0, 0):
            actual_count = actual_count[1][1]
        else:
            actual_count = 0
        # get the "most minimal" actual_count from the flattened report from previously run check
        fragment_diagnostic, fragment_count = util.get_file_diagnostic_deep_not_exact(
            comment_count_details)
    # --> exactness is required, so find the first value that does not match the specified value
    elif exact:
        fragment_diagnostic, fragment_count = util.get_file_diagnostic_deep_exact(
            comment_count_details, expected_count)
        new_actual_count = util.get_first_not_equal_value_deep(
            comment_count_details, expected_count)
        if new_actual_count == {}:
            new_actual_count = util.get_first_not_equal_value(
                comment_count_details, expected_count)
        if new_actual_count != (0, 0):
            new_actual_count = new_actual_count[1][1]
            if new_actual_count != actual_count:
                met_or_exceeded_count = False
                actual_count = new_actual_count
    diagnostic = ("Found " + str(actual_count) + constants.markers.Space +
                  "comment(s)" + constants.markers.Space +
                  fragment_diagnostic + constants.markers.Space +
                  "or the output")
    report_result(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count
Example #3
0
def test_find_not_equal_value_not_deep_all_not_same():
    """Check if the maximum value is found in a dictionary deep."""
    input_file_one = {"John": 21, "Mike": 52, "Sarah": 12, "Bob": 43}
    found = util.get_first_not_equal_value(input_file_one, 43)
    assert found[0] == "John"
    assert found[1] == 21