예제 #1
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
예제 #2
0
def invoke_all_fragment_checks(
    fragment,
    expected_count,
    filecheck=constants.markers.Nothing,
    directory=constants.markers.Nothing,
    contents=constants.markers.Nothing,
    exact=False,
):
    """Perform the check for a fragment existence in file or contents and return the results."""
    met_or_exceeded_count = 0
    met_or_exceeded_count, actual_count, actual_count_dictionary = fragments.specified_entity_greater_than_count(
        fragment,
        fragments.count_specified_fragment,
        expected_count,
        filecheck,
        directory,
        contents,
        exact,
    )
    # create a message for a file in directory
    if (filecheck is not constants.markers.Nothing
            and directory is not constants.markers.Nothing):
        # create an "at least" message, which is the default
        if exact is not True:
            message = ("The " + filecheck + " in " + directory +
                       " has at least " + str(expected_count) + " of the '" +
                       fragment + "' fragment")
        # create an "exact" message, which is an opt-in
        else:
            message = ("The " + filecheck + " in " + directory +
                       " has exactly " + str(expected_count) + " of the '" +
                       fragment + "' fragment")
    # create a message for a string
    # this case is run when a program is
    # executed and then produces output
    else:
        # create an "at least" message, which is the default
        if exact is not True:
            message = ("The command output" + " has at least " +
                       str(expected_count) + " of the '" + fragment +
                       "' fragment")
        # create an "exact" message, which is an opt-in
        else:
            message = ("The command output" + " has exactly " +
                       str(expected_count) + " of the '" + fragment +
                       "' fragment")
    # produce the diagnostic and report the result
    fragment_diagnostic = util.get_file_diagnostic(actual_count_dictionary)
    # when the file is "unknown" then this means that the content is from a command
    # and thus it is better to use the generic phrase "file" instead of this default
    fragment_diagnostic = fragment_diagnostic.replace(
        constants.markers.Unknown_File, constants.markers.File)
    diagnostic = ("Found " + str(actual_count) + constants.markers.Space +
                  "fragment(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
예제 #3
0
def invoke_all_count_checks(
    expected_count,
    filecheck=constants.markers.Nothing,
    directory=constants.markers.Nothing,
    contents=constants.markers.Nothing,
    exact=False,
):
    """Perform the check for the count of lines in file or contents and return the results."""
    met_or_exceeded_count = 0
    (
        (
            met_or_exceeded_count,
            actual_count,
        ),
        actual_count_dictionary,
    ) = fragments.specified_source_greater_than_count(expected_count,
                                                      filecheck, directory,
                                                      contents, exact)
    # create a message for a file in directory
    if (filecheck is not constants.markers.Nothing
            and directory is not constants.markers.Nothing):
        if exact is not True:
            message = ("The " + filecheck + " in " + directory +
                       " has at least " + str(expected_count) + " line(s)")
        else:
            message = ("The " + filecheck + " in " + directory +
                       " has exactly " + str(expected_count) + " line(s)")
    # create a message for a string (normally from program execution)
    else:
        if exact is not True:
            message = ("The command output" + " has at least " +
                       str(expected_count) + " lines")
        else:
            message = ("The command output" + " has exactly " +
                       str(expected_count) + " lines")
    # Produce the diagnostic and report the result.
    # If a wildcard (i.e., "*.py") was given for the filename, then
    # this diagnostic is customized for the file that first breaks the check.
    fragment_diagnostic = util.get_file_diagnostic(actual_count_dictionary)
    # when the file is "unknown" then this means that the content is from a command
    # and thus it is better to use the generic phrase "file" instead of this default
    fragment_diagnostic = fragment_diagnostic.replace(
        constants.markers.Unknown_File, constants.markers.File)
    diagnostic = ("Found " + str(actual_count) + constants.markers.Space +
                  "line(s)" + constants.markers.Space + fragment_diagnostic +
                  constants.markers.Space + "or the output")
    # extract the result as to whether or not the check passed
    extracted_result = met_or_exceeded_count[0]
    # use the created diagnostic to report the result
    report_result(extracted_result, message, diagnostic)
    return extracted_result
예제 #4
0
def invoke_all_markdown_checks(markdown_tag,
                               expected_count,
                               filecheck,
                               directory,
                               exact=False):
    """Perform the check for a markdown tag existence in a file and return the results."""
    met_or_exceeded_count = 0
    # perform the count, saving the details in a way that preserves information if the
    # filecheck was given as a wildcard (i.e., "*.py")
    (
        (
            met_or_exceeded_count,
            actual_count,
        ),
        count_dictionary,
    ) = markdown.specified_tag_greater_than_count(
        markdown_tag,
        markdown.count_specified_tag,
        expected_count,
        filecheck,
        directory,
        exact,
    )
    # create an "at least" message which is the default
    if exact is not True:
        message = ("The " + filecheck + " in " + directory + " has at least " +
                   str(expected_count) + " of the '" + markdown_tag + "' tag")
    # create an "exact" message which is an opt-in
    else:
        message = ("The " + filecheck + " in " + directory + " has exactly " +
                   str(expected_count) + " of the '" + markdown_tag + "' tag")
    # Produce the diagnostic and report the result.
    # If a wildcard (i.e., "*.py") was given for the filename, then
    # this diagnostic is customized for the file that first breaks the check.
    fragment_diagnostic = util.get_file_diagnostic(count_dictionary)
    diagnostic = ("Found " + str(actual_count) + constants.markers.Space +
                  "tag(s)" + constants.markers.Space + fragment_diagnostic +
                  constants.markers.Space + constants.markers.File)
    # create the diagnostic and report the result
    report_result(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count