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
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
def test_find_minimum_in_dictionary_single_max_deep_words_diagnostic(): """Check to see if diagnostic is produced with a single minimum value.""" input_file_one = {1: 10, 2: 5, 3: 4} input_file_two = {1: 10, 2: 5, 3: 4} input_file_three = {1: 10, 2: 5, 3: 1} outer_dictionary = { "input_file_one": input_file_one, "input_file_two": input_file_two, "input_file_three": input_file_three, } diagnostic = util.get_word_diagnostic(outer_dictionary) assert diagnostic is not None assert diagnostic[0] == "in the third" assert diagnostic[1] == "input_file_three"
def test_find_minimum_in_dictionary_single_max_deep_words_diagnostic_realistic( ): """Check to see if diagnostic is produced with a single minimum value.""" outer_dictionary = { "README.md": { 1: 3, 2: 12, 3: 82, 4: 2, 5: 152, 6: 51, 7: 68, 8: 66, 9: 104, 10: 1, 11: 53, 12: 102, 13: 59, 14: 47, 15: 98, 16: 123, 17: 34, 18: 42, 19: 108, 20: 8, 21: 11, }, "LICENSE.md": { 1: 29, 2: 17, 3: 98, 4: 77, 5: 45, 6: 55, 7: 35, 8: 49, 9: 112, 10: 64, 11: 11, 12: 12, 13: 16, 14: 25, 15: 50, 16: 15, 17: 58, 18: 36, 19: 90, 20: 27, 21: 41, 22: 118, 23: 124, 24: 19, 25: 14, 26: 76, 27: 113, 28: 22, 29: 41, 30: 70, 31: 76, 32: 25, 33: 39, 34: 101, 35: 38, 36: 30, 37: 136, 38: 67, 39: 109, 40: 76, 41: 46, 42: 85, 43: 69, 44: 34, 45: 96, 46: 42, 47: 26, 48: 47, 49: 58, 50: 60, 51: 50, 52: 88, 53: 41, 54: 96, 55: 77, 56: 34, 57: 83, 58: 36, 59: 63, 60: 148, 61: 73, 62: 163, 63: 30, 64: 110, 65: 84, 66: 44, 67: 83, 68: 40, 69: 33, 70: 88, 71: 105, 72: 61, 73: 41, 74: 51, 75: 13, 76: 21, 77: 36, 78: 46, 79: 65, }, } util.get_word_diagnostic(outer_dictionary)
def test_word_diagnostic_empty_dictionary(): """Check to see if diagnostic is produced with an empty dictionary.""" word_count_dictionary = {} word_diagnostic = util.get_word_diagnostic(word_count_dictionary) assert word_diagnostic == ("", "")
def test_word_diagnostic_single_min_last(): """Check to see if diagnostic is produced with a single minimum value.""" word_count_dictionary_file_one = {1: 10, 2: 5, 3: 4} word_count_dictionary = {"file_one": word_count_dictionary_file_one} word_diagnostic = util.get_word_diagnostic(word_count_dictionary) assert word_diagnostic[0] == "in the third"