def test_file_exists_in_directory_check_fragments(reset_results_dictionary, tmpdir): """Checks that the checking of fragments in a file works correctly""" reflection_file = tmpdir.mkdir("sub").join("reflection.md") reflection_file.write( "hello world 44 fine\n\nhi there nice again\n\nff! Is now $@name again\n\n" ) assert ( reflection_file.read() == "hello world 44 fine\n\nhi there nice again\n\nff! Is now $@name again\n\n" ) assert len(tmpdir.listdir()) == 1 directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub" reflection_file = "reflection.md" invoke.invoke_all_fragment_checks("hello", 1, reflection_file, directory, "") details = report.get_details() invoke.invoke_all_fragment_checks("@name", 1, reflection_file, directory, "") details = report.get_details() invoke.invoke_all_fragment_checks("again", 2, reflection_file, directory, "") details = report.get_details() invoke.invoke_all_fragment_checks("planet", 2, reflection_file, directory, "") details = report.get_details() assert details is not None
def test_comment_counts_check_multiple_java(reset_results_dictionary, tmpdir): """Checks that invocation of comment counting check works correctly""" hello_file = tmpdir.mkdir("subdirectory").join("Hello.java") hello_file.write("/* hello world */") assert hello_file.read() == "/* hello world */" assert len(tmpdir.listdir()) == 1 directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "subdirectory" hello_file = "Hello.java" invoke.invoke_file_in_directory_check(hello_file, directory) details = report.get_details() assert details is not None invoke.invoke_all_comment_checks(hello_file, directory, 1, "multiple-line", "Java") details = report.get_details() assert details is not None
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 test_file_exists_in_directory_check_paragraphs_exact( reset_results_dictionary, tmpdir): """Checks that the checking of paragraphs works for exact correctly""" reflection_file = tmpdir.mkdir("sub").join("reflection.md") reflection_file.write("hello world 44\n\nhi\n\nff!$@name\n\n^^44") assert reflection_file.read( ) == "hello world 44\n\nhi\n\nff!$@name\n\n^^44" assert len(tmpdir.listdir()) == 1 directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub" reflection_file = "reflection.md" invoke.invoke_all_paragraph_checks(reflection_file, directory, 4, True) details = report.get_details() assert details is not None invoke.invoke_all_paragraph_checks(reflection_file, directory, 200, True) details = report.get_details() assert details is not None
def test_content_string_check_fragments_exact(reset_results_dictionary): """Checks that the checking of words works correctly""" value = "hello world 44 fine\n\nhi there nice again\n\nff! Is now $@name again\n\n" invoke.invoke_all_fragment_checks("hello", 1, invoke.NOTHING, invoke.NOTHING, value, True) details = report.get_details() assert details is not None
def test_content_string_check_fragments_with_threshold( reset_results_dictionary): """Checks that the checking of words works correctly""" value = "hello world 44 fine\n\nhi there nice again\n\nff! Is now $@name again\n\n" invoke.invoke_all_count_checks(1, contents=value) invoke.invoke_all_count_checks(2, contents=value) invoke.invoke_all_count_checks(7, contents=value) details = report.get_details() assert details is not None
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_file_exists_in_directory_check_words(reset_results_dictionary, tmpdir): """Checks that the checking of words works correctly""" reflection_file = tmpdir.mkdir("sub").join("reflection.md") reflection_file.write( "hello world 44 fine\n\nhi there nice again\n\nff! Is now $@name again\n\n" ) assert ( reflection_file.read() == "hello world 44 fine\n\nhi there nice again\n\nff! Is now $@name again\n\n" ) assert len(tmpdir.listdir()) == 1 directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub" reflection_file = "reflection.md" invoke.invoke_all_word_count_checks(reflection_file, directory, 4) details = report.get_details() assert details is not None invoke.invoke_all_word_count_checks(reflection_file, directory, 200) details = report.get_details() assert details is not None
def test_file_exists_in_directory_check(reset_results_dictionary, tmpdir): """Checks to that invocation of file existence check works correctly""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub" hello_file = "hello.txt" invoke.invoke_file_in_directory_check(hello_file, directory) details = report.get_details() assert details is not None
def test_run_command_grab_output_as_string_count_lines_exact( reset_results_dictionary, tmpdir): """Checks that invocation of command produces correct captured output for exact line count""" tmpdir.mkdir("Hello1") tmpdir.mkdir("Hello2") tmpdir.mkdir("Hello3") assert len(tmpdir.listdir()) == 3 directory = tmpdir.dirname + "/" + tmpdir.basename + "/" met_or_exceeded_count = invoke.invoke_all_command_count_checks( "ls " + directory, 3, True) assert met_or_exceeded_count is True met_or_exceeded_count = invoke.invoke_all_command_count_checks( "ls " + directory, 4, True) assert met_or_exceeded_count is False details = report.get_details() assert details is not None
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
def test_commit_checks_exact(reset_results_dictionary): """Checks to that invocation of commit check exacted works correctly""" invoke.invoke_commits_check(".", sys.maxsize, True) details = report.get_details() assert details is not None