コード例 #1
0
def test_gatorgrader_home_is_set():
    """Ensure that the GATORGRADER_HOME environment variable is set."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        gatorgrader_home = util.get_gatorgrader_home()
        # If GATORGRADER_HOME is not set, then it will be set
        # by default to the home directory. These assertions
        # use Pathlib objects to do the comparison so as to
        # ensure that they pass across all operating systems
        current_working_directory = files.create_program_path()
        assert gatorgrader_home is not None
        assert files.create_path(home=gatorgrader_home) == files.create_path(
            home=current_working_directory)
コード例 #2
0
ファイル: invoke.py プロジェクト: Alex-Yarkosky/gatorgrader
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
コード例 #3
0
def get_source(checker_paths=[]):
    """Load all of the checkers using pluginbase."""
    # define the "package" in which the checks reside
    # the term "package" corresponds to "module.sub-module"
    checker_base = PluginBase(package=constants.packages.Checks)
    # remove any directories from the path listings that are Nothing (i.e., "")
    # this case occurs when the optional --checkerdir is not provided on command-line
    if constants.markers.Nothing in checker_paths:
        checker_paths.remove(constants.markers.Nothing)
    # Create the directory where the internal checkers live inside of GatorGrader.
    # Note that this directory includes the home for GatorGrader, which can be set
    # by an environment variable and otherwise defaults to the directory from which
    # GatorGrader was run and then the directory where internal checkers are stored.
    internal_checker_path = files.create_path(
        constants.checkers.Internal_Checkers_Dir,
        home=util.get_gatorgrader_home())
    # create the listing of the paths that could contain checkers, including
    # all of the provided paths for external checkers and the directory that
    # contains all of the internal checkers provided by GatorGrader
    all_checker_paths = checker_paths + [str(internal_checker_path)]
    # Create and return a source of checkers using PluginBase.
    # The documentation for this function advices that you
    # give an identifier to the source for the plugins
    # because this will support saving and transfer, if needed.
    # Only perform this operation if the checker source is None,
    # meaning that it has not already been initialized.
    # pylint: disable=global-statement
    global CHECKER_SOURCE
    if CHECKER_SOURCE is None:
        CHECKER_SOURCE = checker_base.make_plugin_source(
            identifier=constants.checkers.Plugin_Base_Identifier,
            searchpath=all_checker_paths,
        )
    return CHECKER_SOURCE
コード例 #4
0
def test_create_one_file_path_with_one_middle(tmpdir):
    """Ensure that creating a single file path works correctly."""
    hello_file = tmpdir.mkdir("sub").join("hello.txt")
    hello_file.write("content")
    assert hello_file.read() == "content"
    assert len(tmpdir.listdir()) == 1
    created_path = files.create_path(tmpdir.basename,
                                     "sub",
                                     file="hello.txt",
                                     home=tmpdir.dirname)
    assert created_path.name == "hello.txt"
    assert created_path.parent.absolute is not None
    assert created_path.parent.name == "sub"
コード例 #5
0
def verify(args):
    """Check if the arguments are correct."""
    # assume the arguments are valid, then prove otherwise
    verified_arguments = True
    # CHECKERDIR: an external directory of checks was specified
    # ENSURE: this directory is a valid directory
    if args.checkerdir is not None:
        # assume that it is not a valid directory, then prove otherwise
        verified_arguments = False
        checkerdir_path = files.create_path(file="", home=args.checkerdir)
        # the directory does exist, so this argument is verified
        if checkerdir_path.is_dir():
            verified_arguments = True
    return verified_arguments
コード例 #6
0
def verify(args):
    """Check if the arguments are correct."""
    # assume the arguments are valid, then prove otherwise
    verified_arguments = True
    # CHECKERDIR: an external directory of checks was specified
    # ENSURE: the directory is a valid directory
    if args.checkerdir is not None:
        # if the directory does exist, this argument is verified
        checkerdir_path = files.create_path(file="", home=args.checkerdir)
        verified_arguments = verified_arguments and checkerdir_path.is_dir()
    # DESCRIPTION: a string to use as the check result's message
    # ENSURE: the description is a valid description
    if args.description is not None:
        # assume that the description is not valid
        verified_arguments = verified_arguments and description.is_valid_description(
            args.description)
    return verified_arguments
コード例 #7
0
def verify_gatorgrader_home(current_gatorgrader_home):
    """Verify that the GATORGRADER_HOME variable is set correctly."""
    # assume that the home is not verified and try to prove otherwise
    # a directory is verified if:
    # 1) it exists on the file system
    # 2) is ends in the word "gatorgrader"
    verified_gatorgrader_home = False
    # pylint: disable=bad-continuation
    if current_gatorgrader_home is not None:
        # the provided input parameter is not empty, so try to
        # create a path for the directory contained in parameter
        possible_gatorgrader_home = files.create_path(
            home=current_gatorgrader_home)
        # this directory exists and the final part of the directory is "gatorgrader"
        if (possible_gatorgrader_home.exists()
                and possible_gatorgrader_home.name == constants.paths.Home):
            verified_gatorgrader_home = True
    return verified_gatorgrader_home