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_file_exists_in_directory_check_test_file(reset_results_dictionary): """Check that invocation of file existence check works correctly.""" testargs = [os.getcwd()] with patch.object(sys, "argv", testargs): directory = "tests" test_file = "test_invoke.py" invoke.invoke_file_in_directory_check(test_file, directory) details = report.get_result() # file is found in the specified directory assert details is not None assert details[constants.results.Outcome] is True assert "exists in" in details[constants.results.Description] assert details[constants.results.Diagnostic] == ""
def test_file_exists_in_directory_check(reset_results_dictionary, tmpdir): """Check 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_result() # file is found in the specified directory assert details is not None assert details[constants.results.Outcome] is True assert "exists in" in details[constants.results.Description] assert details[constants.results.Diagnostic] == ""
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_comment_counts_check_single_python(reset_results_dictionary, tmpdir): """Checks that invocation of comment counting check works correctly""" hello_file = tmpdir.mkdir("subdirectory").join("Hello.py") 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.py" invoke.invoke_file_in_directory_check(hello_file, directory) details = report.get_result() assert details is not None report.reset() invoke.invoke_all_comment_checks(hello_file, directory, 1, "single-line", "Python") details = report.get_result() assert details is not None
def test_comment_counts_check_multiple_python_not_enough( reset_results_dictionary, tmpdir): """Check that invocation of comment counting check works correctly.""" hello_file = tmpdir.mkdir("subdirectory").join("Hello.py") hello_file.write('""" hello world """') assert hello_file.read() == '""" hello world """' assert len(tmpdir.listdir()) == 1 # directory = tmpdir.dirname + '"""' + tmpdir.basename + '"""' + "subdirectory" directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "subdirectory" hello_file = "Hello.py" invoke.invoke_file_in_directory_check(hello_file, directory) details = report.get_result() assert details is not None report.reset() invoke.invoke_all_comment_checks(hello_file, directory, 100, "multiple-line", "Python") details = report.get_result() assert details is not None
def test_comment_counts_check_multiple_java_invalid_check( reset_results_dictionary, tmpdir): """Check 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_result() assert details is not None report.reset() # this check cannot pass because of the fact that it asks # for "standard-line" comments, which are not supported by this function invoke.invoke_all_comment_checks(hello_file, directory, 1, "standard-line", "Java") details = report.get_result() assert details is not None
def act(main_parsed_arguments, check_remaining_arguments): """Perform the action for this check.""" # extract the two arguments for this check: # --> file is the name of the file for which the search is conducted # --> directory is the name of the directory that should contain the specified file check_parsed_arguments = parse(check_remaining_arguments) # Directly run the check since at least one of the argument's for it is mandatory. # This means that the use of check_ConfirmFileExists would have already failed by this # point since argparse will exit the program if a command-line argument is not provided file = check_parsed_arguments.file directory = check_parsed_arguments.directory return [invoke.invoke_file_in_directory_check(file, directory)]