def invoke_file_in_directory_check(filecheck, directory): """Check to see if the file is in the directory.""" # get the project home, which contains the content subject to checking gatorgrader_home = util.get_project_home() # get the project directory for checking and then check for file directory_path = files.create_path(home=directory) # the directory is absolute, meaning that it does not need to be # rooted in the context of the project directory if directory_path.is_absolute(): was_file_found = files.check_file_in_directory(file=filecheck, home=directory) # the directory is not absolute, meaning that it should be rooted # in the context of the project directory. Note that this is # normally the case when GatorGrader is used through a Gradle configuration else: was_file_found = files.check_file_in_directory(directory, file=filecheck, home=gatorgrader_home) # construct the message about whether or not the file exists message = ("The file " + filecheck + " exists in the " + directory + constants.markers.Space + "directory") # diagnostic is created when file does not exist in specified directory # call report_result to update report for this check diagnostic = ("Did not find the specified file in the " + directory + constants.markers.Space + "directory") report_result(was_file_found, message, diagnostic) return was_file_found
def test_many_files_in_subdirectory_casesensitive(tmpdir): """Ensure that check_file_in_directory can find many files in a subdirectory.""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 # case sensitive found was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="hello.txt", home=tmpdir.dirname) assert was_file_found is True readme_file = tmpdir.join("sub").join("README.md") readme_file.write("# README") was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="README.md", home=tmpdir.dirname) assert was_file_found is True # case sensitive not found was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="HELLO.TXT", home=tmpdir.dirname) assert was_file_found is False readme_file = tmpdir.join("sub").join("README.md") readme_file.write("# README") was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="README.MD", home=tmpdir.dirname) assert was_file_found is False
def test_many_files_found_in_subdirectory(tmpdir): """check_file_in_directory can find many files file in a subdirectory""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 was_file_found = files.check_file_in_directory( "hello.txt", tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub") assert was_file_found is True readme_file = tmpdir.join("sub").join("README.md") readme_file.write("# README") was_file_found = files.check_file_in_directory( "README.md", tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub") assert was_file_found is True
def test_one_file_not_found_in_subdirectory_casesensitive(tmpdir): """Ensure check_file_in_directory cannot find one file in a subdirectory.""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="HELLO_NOT_THERE.TXT", home=tmpdir.dirname) assert was_file_found is False was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="HELLO.TXT", home=tmpdir.dirname) assert was_file_found is False
def test_many_files_not_found_in_subdirectory(tmpdir): """Ensure check_file_in_directory cannot find many files in a subdirectory.""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="hello_not_there.txt", home=tmpdir.dirname) assert was_file_found is False readme_file = tmpdir.join("sub").join("README.md") readme_file.write("# README") was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="README_not_there.md", home=tmpdir.dirname) assert was_file_found is False
def test_one_file_found_in_subdirectory_case_sensitivity(tmpdir): """Ensure that check_file_in_directory can find case-sensitive file name in a subdirectory.""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 # the file should be found with the lowercase name was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="hello.txt", home=tmpdir.dirname) assert was_file_found is True # the file should be not found with the uppercase name was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="HELLO.txt", home=tmpdir.dirname) assert was_file_found is False
def test_one_file_not_found_in_subdirectory(tmpdir): """check_file_in_directory cannot find one file file in a subdirectory""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 was_file_found = files.check_file_in_directory( "hello_not_there.txt", tmpdir.dirname + "/" + tmpdir.basename + "/" + "sub") assert was_file_found is False
def test_one_file_found_in_subdirectory(tmpdir): """Ensure that check_file_in_directory can find one file in a subdirectory.""" hello_file = tmpdir.mkdir("sub").join("hello.txt") hello_file.write("content") assert hello_file.read() == "content" assert len(tmpdir.listdir()) == 1 was_file_found = files.check_file_in_directory(tmpdir.basename, "sub", file="hello.txt", home=tmpdir.dirname) assert was_file_found is True
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 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 message = ( "The file " + filecheck + " exists in the " + directory + SPACE + "directory" ) # diagnostic is created when file does not exist in specified directory # call report_result to update report for this check diagnostic = ( "Did not find the specified file in the " + directory + SPACE + "directory" ) report_result(was_file_found, message, diagnostic) return was_file_found