Beispiel #1
0
def test_relational_operator_exacted_false_not_exacted():
    """Check to see if the exacted relational operator returns False, no exacting."""
    relation_boolean, relation_value = util.greater_than_equal_exacted(10, 100)
    assert relation_boolean is False
    assert relation_value == 10
    relation_boolean, relation_value = util.greater_than_equal_exacted(
        10, 100, False)
    assert relation_boolean is False
    assert relation_value == 10
Beispiel #2
0
def commits_greater_than_count(path, expected_count, exact=False):
    """Returns count and true if count of commits is greater than limit, else False"""
    # extract the commit log and then count the commits
    commits = get_commmits(path)
    number_commits = count_commits(commits)
    # check the condition and also return number_commits
    return util.greater_than_equal_exacted(number_commits, expected_count, exact)
Beispiel #3
0
def specified_tag_greater_than_count(
    chosen_tag,
    checking_function,
    expected_count,
    given_file,
    containing_directory,
    exact=False,
):
    """Determine if the tag count is greater than expected in given file(s)."""
    # Use these two variables to keep track of tag counts for multiple files.
    # The idea is that file_tags_count_dictionary will store (key, value) pairs
    # where the key is the file and the count is the number of entities in that file.
    file_tags_count = 0
    file_tags_count_dictionary = {}
    # Create a Path object to the chosen file in the containing directory, accounting
    # for the fact that a wildcard like "*.md" will create multiple paths. Note that
    # the create_paths function can only return valid paths, regardless of input.
    for file_for_checking in files.create_paths(
        file=given_file, home=containing_directory
    ):
        file_tag_count = 0
        # since the specified file must be valid and thus suitable for checking,
        # read the contents of the file and then check for the chosen tag
        file_contents = file_for_checking.read_text()
        file_tag_count = checking_function(file_contents, chosen_tag)
        file_tags_count_dictionary[file_for_checking.name] = file_tag_count
    # return the minimum value and the entire dictionary of counts
    minimum_pair = util.get_first_minimum_value(file_tags_count_dictionary)
    file_tags_count = minimum_pair[1]
    # check the condition and also return file_tags_count
    return (
        util.greater_than_equal_exacted(file_tags_count, expected_count, exact),
        file_tags_count_dictionary,
    )
Beispiel #4
0
def entity_greater_than_count(given_file,
                              containing_directory,
                              expected_count,
                              checking_function,
                              exact=False):
    """Return count and determines if the entity count is greater than expected"""
    file_entity_count = count_entities(given_file, containing_directory,
                                       checking_function)
    # check the condition and also return file_entity_count
    return util.greater_than_equal_exacted(file_entity_count, expected_count,
                                           exact)
Beispiel #5
0
def invoke_all_total_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 = False
    (
        met_or_exceeded_count,
        actual_count,
        actual_count_dictionary,
    ) = entities.entity_greater_than_count_total(filecheck, directory,
                                                 expected_count,
                                                 count_function, exact)
    met_or_exceeded_count = util.greater_than_equal_exacted(
        actual_count, expected_count, exact)[0]
    # 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
    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
    filename_count = expected_count
    if filename:
        filename_diagnostic = (constants.markers.Of_File +
                               constants.markers.Space + filename)
        sum_actual_count_dictionary = util.sum_dictionary_values(
            actual_count_dictionary)
        filename_count = sum_actual_count_dictionary[filename]
    if filename_diagnostic is not constants.markers.Nothing:
        diagnostic = ("Found " + str(filename_count) +
                      constants.markers.Space + conclusion +
                      constants.markers.Space + filename_diagnostic)
    else:
        diagnostic = ("Did not find " + str(filename_count) +
                      constants.markers.Space + conclusion +
                      constants.markers.Space + constants.words.In_The +
                      constants.markers.Space +
                      constants.markers.Unknown_File +
                      constants.markers.Space + constants.markers.File)
    report_result(met_or_exceeded_count, message, diagnostic)
    return met_or_exceeded_count
Beispiel #6
0
def entity_greater_than_count_total(
    given_file, containing_directory, expected_count, checking_function, exact=False
):
    """Return a count and determination if entity count is greater than expected."""
    # call the count_entities function in this module
    file_entity_count, file_entity_count_dictionary = count_entities(
        given_file, containing_directory, checking_function
    )
    count_status_list = util.greater_than_equal_exacted(
        expected_count, file_entity_count, exact
    )
    count_status = count_status_list[0]
    return count_status, file_entity_count, file_entity_count_dictionary
Beispiel #7
0
def specified_source_greater_than_count(
    expected_count,
    given_file=NOTHING,
    containing_directory=NOTHING,
    contents=NOTHING,
    exact=False,
):
    """Determines if the line count is greater than expected"""
    # count the fragments in either a file in a directory or String contents
    file_line_count = count_lines(given_file, containing_directory, contents)
    # the fragment count is at or above the threshold
    # check the condition and also return file_fragment_count
    return util.greater_than_equal_exacted(file_line_count, expected_count,
                                           exact)
Beispiel #8
0
def specified_entity_greater_than_count(
    chosen_fragment,
    checking_function,
    expected_count,
    given_file=NOTHING,
    containing_directory=NOTHING,
    contents=NOTHING,
    exact=False,
):
    """Determines if the entity count is greater than expected"""
    # count the fragments/regex in either a file in a directory or String contents
    file_entity_count = count_entities(chosen_fragment, checking_function,
                                       given_file, containing_directory,
                                       contents)
    # check the condition and also return file_entity_count
    return util.greater_than_equal_exacted(file_entity_count, expected_count,
                                           exact)
Beispiel #9
0
def specified_tag_greater_than_count(
    chosen_tag,
    checking_function,
    expected_count,
    given_file,
    containing_directory,
    exact=False,
):
    """Determines if the tag count is greater than expected in a given file"""
    file_for_checking = Path(containing_directory + FILE_SEPARATOR +
                             given_file)
    file_tag_count = 0
    if file_for_checking.is_file():
        file_contents = file_for_checking.read_text()
        file_tag_count = checking_function(file_contents, chosen_tag)

    # check the condition and also return file_tag_count
    return util.greater_than_equal_exacted(file_tag_count, expected_count,
                                           exact)
Beispiel #10
0
def specified_entity_greater_than_count(
    chosen_fragment,
    checking_function,
    expected_count,
    given_file=constants.markers.Nothing,
    containing_directory=constants.markers.Nothing,
    contents=constants.markers.Nothing,
    exact=False,
):
    """Determine if the entity count is greater than expected."""
    # count the fragments/regex in either a file in a directory or String contents
    file_entity_count, file_entity_count_dictionary = count_entities(
        chosen_fragment, checking_function, given_file, containing_directory,
        contents)
    # check the condition and also return file_entity_count
    condition_truth, value = util.greater_than_equal_exacted(
        file_entity_count, expected_count, exact)
    # also return an empty dictionary since this function does not
    # need to count details about multiple entities
    return condition_truth, value, file_entity_count_dictionary
Beispiel #11
0
def specified_source_greater_than_count(
    expected_count,
    given_file=constants.markers.Nothing,
    containing_directory=constants.markers.Nothing,
    contents=constants.markers.Nothing,
    exact=False,
):
    """Determine if the line count is greater than expected."""
    # count the fragments in either a file in a directory or str contents,
    # with the str contents coming from the output from running a command
    file_lines_count, file_contents_count_dictionary = count_lines(
        given_file, containing_directory, contents)
    # the fragment count is at or above the threshold
    # check the condition and also return the file_lines_count
    # and the dictionary itself so as to support good diagnostics
    return (
        (
            util.greater_than_equal_exacted(file_lines_count, expected_count,
                                            exact),
            file_lines_count,
        ),
        file_contents_count_dictionary,
    )
Beispiel #12
0
def test_relational_operator_exacted_true_exacted():
    """Check to see if the exacted relational operator returns True."""
    relation_boolean, relation_value = util.greater_than_equal_exacted(
        100, 100, True)
    assert relation_boolean is True
    assert relation_value == 100