def test_add_multiple_results_to_report(reset_results_dictionary): """Add multiple row to the report and check for containment""" identifier, new_result = report.add_result("Command executes", True, "") # create the first result and add it to the report dictionary assert identifier == 0 assert new_result is not None assert isinstance(new_result, dict) is True assert len(new_result) == 3 assert report.get_size() == 1 assert new_result[report.CHECK] == "Command executes" assert new_result[report.OUTCOME] is True assert new_result[report.DIAGNOSTIC] == "" # create the second result and add it to the report dictionary identifier_next, new_result_next = report.add_result( "Check for 3 paragraphs", False, "Only found 2 paragraphs" ) assert identifier_next == 1 assert new_result_next is not None assert isinstance(new_result_next, dict) is True assert len(new_result_next) == 3 assert report.get_size() == 2 assert new_result_next[report.CHECK] == "Check for 3 paragraphs" assert new_result_next[report.OUTCOME] is False assert new_result_next[report.DIAGNOSTIC] == "Only found 2 paragraphs" assert isinstance(report.get_details(), dict) is True
def update_report(status, message, diagnostic): """Update the report after running a check""" # found at least the required number of an entity # do not produce a diagnostic message if status: report.add_result(message, status, NO_DIAGNOSTIC) # did not find at least the required number of an entity # produce a diagnostic message using the actual count else: report.add_result(message, status, diagnostic)
def invoke_file_in_directory_check(filecheck, directory): """Check to see if the file is in the directory""" # get the home directory for checking and then check for file gatorgrader_home = util.get_gatorgrader_home() was_file_found = files.check_file_in_directory( filecheck, gatorgrader_home + directory) # construct the message about whether or not the file exists # note that no diagnostic is needed and the result is boolean message = ("The file " + filecheck + " exists in the " + directory + SPACE + "directory") # produce the final report and return the result # note that update_report is not called because # there will never be a diagnostic for this invoke report.add_result(message, was_file_found, NO_DIAGNOSTIC) return was_file_found
def test_add_single_result_to_report(reset_results_dictionary): """Add a single row to the report and check for containment""" identifier, new_result = report.add_result("Command executes", True, "") assert identifier == 0 assert new_result is not None assert len(new_result) == 3 assert report.get_size() == 1 assert new_result[report.CHECK] == "Command executes" assert new_result[report.OUTCOME] is True assert new_result[report.DIAGNOSTIC] == ""
def test_add_single_result_to_report_check_text_output_list(reset_results_dictionary): """Add a single row to the report and check the textual output""" identifier, new_result = report.add_result("Command executes", True, "") assert identifier == 0 assert new_result is not None assert len(new_result) == 3 assert report.get_size() == 1 assert new_result[report.CHECK] == "Command executes" assert new_result[report.OUTCOME] is True assert new_result[report.DIAGNOSTIC] == "" output_list = [] report.output_text(new_result, output_list) assert len(output_list) == 1 assert "\n" not in output_list[0]
def test_output_json_complete(reset_results_dictionary): """Add multiple row to the report and check final output as JSON-based text""" report.add_result("Command executes", True, "") report.add_result("Check for 3 paragraphs", False, "Only found 2 paragraphs") report.add_result("Check for 10 comments", False, "Only found 2 comments") output_list = report.output_list(report.get_details(), report.JSON) assert len(output_list) == 3 output = " ".join(output_list) produced_output = report.output(output_list) assert output == produced_output
def test_output_text(reset_results_dictionary): """Add multiple rows to the report and check final output as list-based text""" report.add_result("Command executes", True, "") report.add_result("Check for 3 paragraphs", False, "Only found 2 paragraphs") report.add_result("Check for 10 comments", False, "Only found 2 comments") output_list = report.output_list(report.get_details(), report.TEXT) assert len(output_list) == 3 output = "\n".join(output_list) assert output is not None assert "\n" in output
def test_add_single_result_to_report_check_text_output_diagnostic_nested( reset_results_dictionary ): """Add a single row to the report and check the textual output""" identifier, new_result = report.add_result( "Command executes", False, "Missing trailing slash" ) assert identifier == 0 assert new_result is not None assert len(new_result) == 3 assert report.get_size() == 1 assert new_result[report.CHECK] == "Command executes" assert new_result[report.OUTCOME] is False assert new_result[report.DIAGNOSTIC] == "Missing trailing slash" output_list = [] report.output_text(report.get_details(), output_list) assert len(output_list) == 1 assert "\n" in output_list[0]
def test_dictionary_is_nested(reset_results_dictionary): """Add a single row to the report and check for containment""" identifier, new_result = report.add_result("Command executes", True, "") assert identifier == 0 assert report.contains_nested_dictionary(new_result) is False assert report.contains_nested_dictionary(report.get_details()) is True