Пример #1
0
def test_check_extraction_from_commandline_arguments_has_help_single_checker_filtered(
):
    """Ensure that checker finding and help extraction works for a single filtered check."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        checker = "ListChecks"
        commandline_arguments = [
            "--checkerdir",
            "./gator/checks",
            "ListChecks",
            "--namecontains",
            "Exec",
        ]
        gg_arguments, remaining_arguments = arguments.parse(
            commandline_arguments)
        args_verified = arguments.verify(gg_arguments)
        assert args_verified is True
        found_check = checkers.get_chosen_check(gg_arguments)
        assert found_check == checker
        checker_source = checkers.get_source()
        check_helps = checkers.get_checks_help(checker_source,
                                               namecontains="Exec")
        assert check_helps != ""
        assert "Exec" in check_helps
        counted_newlines = check_helps.count("\n")
        assert counted_newlines > 0
Пример #2
0
def test_check_extraction_from_commandline_arguments_has_help_two_checkers_one_invalid(
    tmpdir
):
    """Ensure that checker finding and help extraction works for a provided checker."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        checker_file = tmpdir.mkdir("internal_checkers").join("check_testing.py")
        # this must be valid Python code because it will be loaded by pluginbase
        checker_file.write('"' 'a checker"' "")
        checker_directory = (
            tmpdir.dirname + "/" + tmpdir.basename + "/" + "internal_checkers"
        )
        checker = "check_CountCommits"
        assert len(tmpdir.listdir()) == 1
        commandline_arguments = ["--checkerdir", checker_directory, checker]
        gg_arguments, remaining_arguments = arguments.parse(commandline_arguments)
        args_verified = arguments.verify(gg_arguments)
        assert args_verified is True
        found_check = checkers.get_chosen_check(gg_arguments)
        assert found_check == checker
        # ensure that get_checks_help does not try to create a help
        # message for an invalid check that does not have a get_parser function
        checker_source = checkers.get_source([checker_directory])
        check_helps = checkers.get_checks_help(checker_source)
        assert check_helps != ""
        assert "CountCommits" in check_helps
        counted_newlines = check_helps.count("\n")
        assert counted_newlines > 0
Пример #3
0
def test_check_function_verification_list(commandline_arguments):
    """Ensure that check verification works for standard functions."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        parsed_arguments, remaining_arguments = arguments.parse(
            commandline_arguments)
        args_verified = arguments.verify(parsed_arguments)
        assert args_verified is True
        external_checker_directory = checkers.get_checker_dir(parsed_arguments)
        checker_source = checkers.get_source([external_checker_directory])
        check_name = checkers.get_chosen_check(parsed_arguments)
        check_file = checkers.transform_check(check_name)
        check_exists = checkers.verify_check_existence(check_file,
                                                       checker_source)
        assert check_exists is True
        # create the check
        check = checker_source.load_plugin(check_file)
        # verify that the check has the functions, specified separately
        assert (checkers.verify_check_functions(
            check, ["act", "get_parser", "parse"]) is True)
        # verify that the check has the functions, specified according to defaults
        assert checkers.verify_check_functions(check) is True
        # verify that the check does not have the provided functions, specified separately
        assert (checkers.verify_check_functions(
            check, ["actWRONG", "get_parser", "parse"]) is False)
        assert (checkers.verify_check_functions(
            check, ["act", "get_parserWRONG", "parse"]) is False)
        assert (checkers.verify_check_functions(
            check, ["actWRONG", "get_parser", "parseWRONG"]) is False)
Пример #4
0
 def _load_checker(parsed_arguments):
     """Define internal function to load a checker using pluginbase."""
     external_checker_directory = checkers.get_checker_dir(parsed_arguments)
     checker_source = checkers.get_source([external_checker_directory])
     check_name = checkers.get_chosen_check(parsed_arguments)
     check_file = checkers.transform_check(check_name)
     check_exists = checkers.verify_check_existence(check_file,
                                                    checker_source)
     return (check_exists, checker_source, check_file)
Пример #5
0
def check(system_arguments):
    """Orchestrate a full check of the specified deliverables."""
    # *Section: Initialize
    # step_results = []
    check_results = []
    # **Step: Parse and then verify the arguments, extract remaining arguments
    parsed_arguments, remaining_arguments = parse_arguments(system_arguments)
    verification_status = verify_arguments(parsed_arguments)
    # **Step: Get the source of all the checkers available from either:
    # --> the internal directory of checkers (e.g., "./gator/checks")
    # --> the directory specified on the command-line
    external_checker_directory = checkers.get_checker_dir(parsed_arguments)
    checker_source = checkers.get_source([external_checker_directory])
    # **Step: Get and perform the preliminary actions before running a checker
    # if the arguments did not parse or verify correctly, then:
    # --> argparse will cause the program to crash with an error OR
    # --> one of the actions will be to display the help message and exit
    actions = get_actions(parsed_arguments, verification_status)
    perform_actions(actions)
    # *Section: Perform the check
    # **Step: Get and transform the name of the chosen checker and
    # then prepare for running it by ensuring that it is:
    # --> available for use (i.e., pluginbase found and loaded it)
    check_name = checkers.get_chosen_check(parsed_arguments)
    check_file = checkers.transform_check(check_name)
    check_exists = checkers.verify_check_existence(check_file, checker_source)
    # **Step: Load the check and verify that it is valid:
    check_verified = False
    check = None
    if check_exists:
        check = checker_source.load_plugin(check_file)
        check_verified = checkers.verify_check_functions(check)
    # produce error message and exit because the check is not valid
    if not check_exists or not check_verified:
        # do not potentially produce the welcome message again
        parsed_arguments.nowelcome = True
        actions = get_actions(parsed_arguments, check_verified)
        perform_actions(actions)
    # **Step: Perform the check since it exists and it is verified
    check_result = check.act(parsed_arguments, remaining_arguments)
    check_results.extend(check_result)
    # *Section: Output the report
    # **Step: get the report's details
    result = report.get_result()
    # **Step: Override the result's description if a user-provided description exists
    result = description.transform_result_dictionary(parsed_arguments, result)
    # **Step: produce the output
    produced_output = report.output(report.get_result(), OUTPUT_TYPE)
    # **Step: display the output
    display.message(produced_output)
    # Section: Return control back to __main__ in gatorgrader
    # Only step: determine the correct exit code for the checks
    correct_exit_code = leave.get_code(check_results)
    return correct_exit_code
Пример #6
0
def test_load_checkers_list_is_not_empty_default_input():
    """Ensure that checker loading results in non-empty list with defaults."""
    checker_source = checkers.get_source()
    # the source for the plugins is not empty
    assert checker_source is not None
    # the source for the plugins contains plugins
    # that adhere to the naming scheme "check_<ACTION><ENTITY>"
    # for instance "check_commits"
    # we know that this should be true because all
    # internal GatorGrader plugins adhere to this convention
    for checker in checker_source.list_plugins():
        assert "check_" in checker
Пример #7
0
def test_load_checkers_list_is_not_empty_provided_input(tmpdir):
    """Ensure that checker loading results in non-empty list with provided list."""
    checker_file = tmpdir.mkdir("internal_checkers").join("check_testing.py")
    # this must be valid Python code because it will be loaded by pluginbase
    checker_file.write('"' 'a checker"' "")
    checker_directory = (tmpdir.dirname + "/" + tmpdir.basename + "/" +
                         "internal_checkers")
    list_of_checker_directories = [checker_directory]
    checker_source = checkers.get_source(list_of_checker_directories)
    assert checker_source is not None
    checker_source_list = checker_source.list_plugins()
    assert len(checker_source_list) >= 1
Пример #8
0
def test_load_checkers_list_is_not_empt_blank_input():
    """Ensure that checker loading results in non-empty list with defaults."""
    # this case would occur on the command-line when
    # the checkerdir is not specified as an argument
    checker_source = checkers.get_source([""])
    # the source for the plugins is not empty
    assert checker_source is not None
    # the source for the plugins contains plugins
    # that adhere to the naming scheme "check_<ACTION><ENTITY>"
    # for instance "check_commits"
    # we know that this should be true because all
    # internal GatorGrader plugins adhere to this convention
    for checker in checker_source.list_plugins():
        assert "check_" in checker
Пример #9
0
 def print_help(self, status=1, message=None):
     """Print the standard help message and then list the checkers."""
     # display the standard help message
     super().print_help()
     # Get all of the checks available through pluginbase.
     # Note that the "--checkdir" is not available because
     # when argparse recognizes "--help" the parse is not
     # completed. This means that this function can only
     # display those internal checks through pluginbase.
     checker_source = checkers.get_source()
     help_messages = checkers.get_checks_help(
         checker_source, indent=constants.markers.Indent)
     # display a blank line, a label, and then the collected
     # help messages from the internal checks through pluginbase
     display.line()
     display.line("internal checks:")
     display.line(help_messages)
Пример #10
0
def test_check_function_verification_separate(commandline_arguments):
    """Ensure that check verification works for standard functions."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        parsed_arguments, remaining_arguments = arguments.parse(commandline_arguments)
        args_verified = arguments.verify(parsed_arguments)
        assert args_verified is True
        external_checker_directory = checkers.get_checker_dir(parsed_arguments)
        checker_source = checkers.get_source([external_checker_directory])
        check_name = checkers.get_chosen_check(parsed_arguments)
        check_file = checkers.transform_check(check_name)
        check_exists = checkers.verify_check_existence(check_file, checker_source)
        assert check_exists is True
        check = checker_source.load_plugin(check_file)
        assert checkers.verify_check_function(check, "act") is True
        assert checkers.verify_check_function(check, "get_parser") is True
        assert checkers.verify_check_function(check, "parse") is True
Пример #11
0
def test_check_extraction_from_commandline_arguments_has_help_single_checker():
    """Ensure that checker finding and help extraction works for a provided checker."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        checker = "check_CountCommits"
        commandline_arguments = [checker]
        gg_arguments, remaining_arguments = arguments.parse(commandline_arguments)
        args_verified = arguments.verify(gg_arguments)
        assert args_verified is True
        found_check = checkers.get_chosen_check(gg_arguments)
        assert found_check == checker
        checker_source = checkers.get_source()
        check_helps = checkers.get_checks_help(checker_source)
        assert check_helps != ""
        assert "CountCommits" in check_helps
        counted_newlines = check_helps.count("\n")
        assert counted_newlines > 0
Пример #12
0
def act(main_parsed_arguments, check_remaining_arguments):
    """Perform the action for this check."""
    check_parsed_arguments = parse(check_remaining_arguments)
    # get the source of all the checkers available from either:
    # --> the internal directory of checkers (e.g., "./gator/checks")
    # --> the directory specified on the command-line
    external_checker_directory = checkers.get_checker_dir(
        main_parsed_arguments)
    checker_source = checkers.get_source([external_checker_directory])
    # must filter the names of checks with check_parsed_arguments.namecontains filter
    # verification of the arguments is necessary because --namecontains is optional
    # and there is no suitable default value for this command-line argument
    if checkers.verify_arguments_not_none(
        [check_parsed_arguments, check_parsed_arguments.namecontains]):
        help_messages = checkers.get_checks_help(
            checker_source, namecontains=check_parsed_arguments.namecontains)
    # no need to filter the help menus based on name containment
    else:
        help_messages = checkers.get_checks_help(checker_source)
    # create a label that explains the meaning of the check
    label = "Find the available checks that match an optional pattern"
    # there were no checks that matched, which means:
    # --> only the label is display, without any help messages
    # --> the diagnostic should indicate that the search failed
    # --> the check "failed", ensuring that the diagnostic appears
    if help_messages is constants.markers.Nothing:
        help_messages = label
        diagnostic = "Could not find any matching checks"
        did_check_pass = False
    # there were checks that matched, which means:
    # --> the label is display, then newlines, and then all matching help messages
    # --> the diagnostic should not appear since the search succeeded
    else:
        # add a label to the first line of the help messages
        # then add a blank line and then add the messages themselves
        help_messages = (label + constants.markers.Newline +
                         constants.markers.Newline + help_messages)
        # there is no diagnostic message because this check passed
        diagnostic = constants.markers.Nothing
        did_check_pass = True
    # use invoke to create a report that can be returned as output
    invoke.report_result(did_check_pass, help_messages, diagnostic)
    return [did_check_pass]