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 # --> count is required to specify the expected number of multiple-line comments in the file # --> language is the programming language for the comments, either Python or Java # --> exact is optional, but will either be True or False and False by default 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_CountMultipleLineComments would have already failed by this # point since argparse will exit the program if a command-line argument is not provided. count = check_parsed_arguments.count file = check_parsed_arguments.file directory = check_parsed_arguments.directory language = check_parsed_arguments.language exact = check_parsed_arguments.exact return [ invoke.invoke_all_comment_checks(file, directory, count, constants.comments.Multiple_Line, language, exact) ]