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 test_find_not_equal_value_deep_all_same(): """Check if the maximum value is found in a dictionary deep.""" input_file_one = {"John": 21, "Mike": 21, "Sarah": 21, "Bob": 21} input_file_two = {"John": 21, "Mike": 21, "Sarah": 21, "Bob": 21} input_file_three = {"John": 21, "Mike": 21, "Sarah": 21, "Bob": 21} outer_dictionary = { "input_file_one": input_file_one, "input_file_two": input_file_two, "input_file_three": input_file_three, } found = util.get_first_not_equal_value_deep(outer_dictionary, 21) assert found == {}
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