Exemple #1
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
    # check single-line comments
    if comment_type == SINGLE:
        # check comments in Java
        if language == JAVA:
            met_or_exceeded_count, actual_count = entities.entity_greater_than_count(
                filecheck,
                directory,
                expected_count,
                comments.count_singleline_java_comment,
                exact,
            )
        # check comments in Python
        if language == PYTHON:
            met_or_exceeded_count, actual_count = entities.entity_greater_than_count(
                filecheck,
                directory,
                expected_count,
                comments.count_singleline_python_comment,
                exact,
            )
    # check multiple-line comments (only in Java)
    elif comment_type == MULTIPLE:
        met_or_exceeded_count, actual_count = entities.entity_greater_than_count(
            filecheck,
            directory,
            expected_count,
            comments.count_multiline_java_comment,
            exact,
        )
    # create the message and the diagnostic
    if not exact:
        message = ("The " + filecheck + " in " + directory + " has at least " +
                   str(expected_count) + SPACE + comment_type + SPACE +
                   language + " comment(s)")
    else:
        message = ("The " + filecheck + " in " + directory + " has exactly " +
                   str(expected_count) + SPACE + comment_type + SPACE +
                   language + " comment(s)")
    diagnostic = "Found " + str(
        actual_count) + " comment(s) in the specified file"
    update_report(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count
Exemple #2
0
def invoke_all_paragraph_checks(filecheck,
                                directory,
                                expected_count,
                                exact=False):
    """Perform the paragraph check and return the results."""
    met_or_exceeded_count = 0
    met_or_exceeded_count, actual_count, actual_count_dictionary = entities.entity_greater_than_count(
        filecheck, directory, expected_count, fragments.count_paragraphs,
        exact)
    # 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 +
                   "paragraph(s)")
    else:
        # create an "exact" message, which is an opt-in
        message = ("The " + filecheck + " in " + directory + " has exactly " +
                   str(expected_count) + constants.markers.Space +
                   "paragraph(s)")
    # produce the diagnostic and report the result
    flat_actual_count_dictionary = util.flatten_dictionary_values(
        actual_count_dictionary)
    fragment_diagnostic = util.get_file_diagnostic(
        flat_actual_count_dictionary)
    diagnostic = ("Found " + str(actual_count) + constants.markers.Space +
                  "paragraph(s)" + constants.markers.Space +
                  fragment_diagnostic + constants.markers.Space +
                  constants.markers.File)
    # create the diagnostic and then report the result
    report_result(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count
Exemple #3
0
def invoke_all_minimum_word_count_checks(filecheck,
                                         directory,
                                         expected_count,
                                         count_function,
                                         conclusion,
                                         exact=False):
    """Perform the word count check and return the results."""
    met_or_exceeded_count = 0
    (
        met_or_exceeded_count,
        actual_count,
        actual_count_dictionary,
    ) = entities.entity_greater_than_count(filecheck, directory,
                                           expected_count, count_function,
                                           exact)
    # 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 + conclusion)
    else:
        # create an "exact" message, which is an opt-in
        message = ("The " + filecheck + " in " + directory + " has exactly " +
                   str(expected_count) + constants.markers.Space + conclusion)
    # create a diagnostic message and report the result
    # replace "in every" with "in a" and a specific paragraph number.
    # This diagnostic signals the fact that there was at least
    # a single paragraph that had a word count below the standard
    # set for all of the paragraphs in the technical writing
    # across all of the files specified (i.e., those matched by wildcards)
    word_diagnostic, filename = util.get_word_diagnostic(
        actual_count_dictionary, expected_count)
    # there is no need for a filename diagnostic unless there are multiple results
    filename_diagnostic = constants.markers.Nothing
    # there is a filename, which means that there was a wildcard specified
    # and thus this diagnostic is for one file; give name at the end
    if filename:
        filename_diagnostic = (constants.markers.Of_File +
                               constants.markers.Space + filename)
    # since there is a word_diagnostic, this means that there is a need to customize
    # the diagnostic message because the check is not going to pass correctly
    if word_diagnostic:
        conclusion = conclusion.replace(constants.words.In_Every,
                                        word_diagnostic)
        # the actual_count may vary depending on whether the check is checking for exact
        # equality or if there is a minimum threshold that the inputs must satisfy
        # --> exactness is not required, so find the minimum value across all inputs
        if not exact:
            actual_count = util.get_first_minimum_value_deep(
                actual_count_dictionary)[1][1]
        # --> exactness is required, so find the first value that does not match the specified value
        elif exact:
            actual_count = util.get_first_not_equal_value_deep(
                actual_count_dictionary, expected_count)[1][1]
        # create the diagnostic message using all of the parts, specifically highlighting
        # the ways in which the check failed, thereby improving a person's debugging process
    diagnostic = ("Found " + str(actual_count) + constants.markers.Space +
                  conclusion + constants.markers.Space + filename_diagnostic)
    report_result(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count
Exemple #4
0
def invoke_all_word_count_checks(filecheck, directory, expected_count, exact=False):
    """Perform the word count check and return the results"""
    met_or_exceeded_count = 0
    met_or_exceeded_count, actual_count = entities.entity_greater_than_count(
        filecheck, directory, expected_count, fragments.count_words
    )
    # create the message and the diagnostic
    if not exact:
        message = (
            "The "
            + filecheck
            + " in "
            + directory
            + " has at least "
            + str(expected_count)
            + SPACE
            + "word(s) in every paragraph"
        )
    else:
        message = (
            "The "
            + filecheck
            + " in "
            + directory
            + " has exactly "
            + str(expected_count)
            + SPACE
            + "word(s) in every paragraph"
        )
    diagnostic = (
        "Found " + str(actual_count) + " word(s) in a paragraph of the specified file"
    )
    report_result(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count
Exemple #5
0
def test_file_contains_multiline_comment_not_greater(tmpdir):
    """Checks that the file is not above the check level"""
    hello_file = tmpdir.mkdir("subdirectory").join("Hello.java")
    hello_file.write("/ hello world")
    assert hello_file.read() == "/ hello world"
    assert len(tmpdir.listdir()) == 1
    greater_than_count, __ = entities.entity_greater_than_count(
        hello_file.basename,
        hello_file.dirname,
        1,
        comments.count_multiline_java_comment,
    )
    assert greater_than_count is False
Exemple #6
0
def test_file_contains_multiline__python_comment_greater(tmpdir):
    """Checks that the file is above the check level"""
    hello_file = tmpdir.mkdir("subdirectory").join("Hello.py")
    string = "Hello \n World"
    hello_file.write('"""{}"""'.format(string))
    assert hello_file.read() == '"""Hello \n World"""'
    assert len(tmpdir.listdir()) == 1
    greater_than_count, __ = entities.entity_greater_than_count(
        hello_file.basename,
        hello_file.dirname,
        1,
        comments.count_multiline_python_comment,
    )
    assert greater_than_count is True
Exemple #7
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