Beispiel #1
0
def test_checkerdir_extraction_from_commandline_arguments(tmpdir):
    """Ensure that command-line argument extraction works in checker function if specified checkerdir."""
    _ = tmpdir.mkdir("checks").join("check_messages.py")
    assert len(tmpdir.listdir()) == 1
    checker_directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "checks"
    commandline_arguments = ["--checkerdir", checker_directory, "check_messages"]
    gg_arguments, remaining_arguments = arguments.parse(commandline_arguments)
    args_verified = arguments.verify(gg_arguments)
    assert args_verified is True
    found_checker_directory = checkers.get_checker_dir(gg_arguments)
    assert found_checker_directory == checker_directory
Beispiel #2
0
def test_checkerdir_is_not_valid_arguments_verify(tmpdir):
    """Check that command-line argument with valid directory verifies."""
    _ = tmpdir.mkdir("checks").join("check_FakeMessages.py")
    assert len(tmpdir.listdir()) == 1
    # this directory does not exist on the file system and verification should not work
    checker_directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "checksWRONG"
    commandline_arguments = [
        "--checkerdir", checker_directory, "check_FakeMessages"
    ]
    gg_arguments, remaining_arguments = arguments.parse(commandline_arguments)
    args_verified = arguments.verify(gg_arguments)
    assert args_verified is False
Beispiel #3
0
def test_check_extraction_from_commandline_arguments(tmpdir):
    """Ensure that command-line argument extraction works in checker function."""
    checker = "check_CountCommits"
    _ = tmpdir.mkdir("checks").join(checker + ".py")
    assert len(tmpdir.listdir()) == 1
    checker_directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "checks"
    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
Beispiel #4
0
def test_act_produces_output(
    commandline_arguments,
    chosen_file,
    containing_directory,
    provided_count,
    expected_result,
    tmpdir,
    load_checker,
):
    """Check that using the check produces output."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        new_file = tmpdir.mkdir(containing_directory).join(chosen_file)
        new_file.write(
            "paragraph one \n\n paragraph two two \n\n paragraph three three three"
        )
        assert (
            new_file.read() ==
            "paragraph one \n\n paragraph two two \n\n paragraph three three three"
        )
        assert len(tmpdir.listdir()) == 1
        overall_directory = (tmpdir.dirname + "/" + tmpdir.basename + "/" +
                             containing_directory)
        commandline_arguments = [
            "CountParagraphWords",
            "--file",
            "file_to_find",
            "--directory",
            overall_directory,
            "--count",
            provided_count,
        ]
        parsed_arguments, remaining_arguments = arguments.parse(
            commandline_arguments)
        args_verified = arguments.verify(parsed_arguments)
        assert args_verified is True
        check_exists, checker_source, check_file = load_checker(
            parsed_arguments)
        assert check_exists is True
        check = checker_source.load_plugin(check_file)
        check_result = check.act(parsed_arguments, remaining_arguments)
        # check the result
        assert check_result is not None
        assert len(check_result) == 1
        # assert check_result[0] is expected_result
        # check the contents of the report
        assert report.get_result() is not None
        assert len(report.get_result()["check"]) > 1
        assert report.get_result()["outcome"] is expected_result
        if expected_result:
            assert report.get_result()["diagnostic"] == ""
        else:
            assert report.get_result()["diagnostic"] != ""
Beispiel #5
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
Beispiel #6
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
Beispiel #7
0
def test_reset_checker_source(load_checker):
    """Ensure that reset of the checker source works correctly."""
    assert checkers.CHECKER_SOURCE is None
    testargs = [os.getcwd()]
    commandline_arguments = [
        "CountCommandOutput",
        "--command",
        'echo "CorrectCommand"',
        "--count",
        "100",
    ]
    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
        check_exists, checker_source, check_file = load_checker(parsed_arguments)
        assert check_exists is True
    checkers.reset_source()
    assert checkers.CHECKER_SOURCE is None
Beispiel #8
0
def check_arguments(system_arguments):
    """Check the arguments return the desired actions to perform"""
    # parse and verify the arguments
    actions = []
    gg_arguments = arguments.parse(system_arguments)
    # Action: display the welcome message
    if gg_arguments.nowelcome is not True:
        actions.append([DISPLAY, "welcome_message", VOID])
    if gg_arguments.json is True:
        # pylint: disable=global-statement
        global OUTPUT_TYPE
        OUTPUT_TYPE = getattr(REPORT, JSON)
    did_verify_arguments = arguments.verify(gg_arguments)
    # arguments are incorrect
    if did_verify_arguments is False:
        # Action: display incorrect arguments message
        actions.append([DISPLAY, "incorrect_message", VOID])
        # Action: exit the program
        actions.append([RUN, "run_exit", [INCORRECT_ARGUMENTS]])
    return gg_arguments, actions
Beispiel #9
0
def test_act_produces_output(commandline_arguments, load_checker):
    """Check that using the check produces output."""
    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
        check_exists, checker_source, check_file = load_checker(
            parsed_arguments)
        assert check_exists is True
        check = checker_source.load_plugin(check_file)
        check_result = check.act(parsed_arguments, remaining_arguments)
        # the result is True
        assert check_result is not None
        assert len(check_result) == 1
        assert check_result[0] is True
        # the report contains expected results
        assert report.get_result() is not None
        assert len(report.get_result()["check"]) > 1
        assert report.get_result()["outcome"] is True
        assert report.get_result()["diagnostic"] == ""
Beispiel #10
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
Beispiel #11
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
        )
Beispiel #12
0
def test_act_produces_output_with_exact(
    commandline_arguments,
    chosen_file,
    containing_directory,
    provided_count,
    expected_result,
    tmpdir,
    load_checker,
):
    """Check that using the check produces output."""
    test_contents = """
## What Do People Think about GatorGrader?

GatorGrader addresses many of the challenges that an instructor faces when
designing automated checks for the source code or technical writing that a

## Installing GatorGrader

Installing GatorGrader is not necessary if you intend to use it through its
[Gradle plugin](https://github.com/GatorEducator/gatorgradle). If you want to

## Running GatorGrader

Students and instructors normally use GatorGrader through its [Gradle
plugin](https://github.com/GatorEducator/gatorgradle), specifying the requested

## Testing GatorGrader

### Automated Testing

The developers use [Pytest](https://docs.pytest.org/en/latest/) for the testing
of GatorGrader. Depending on your goals, there are several different..."""
    testargs = [os.getcwd()]
    with patch.object(sys, "argv", testargs):
        new_file = tmpdir.mkdir(containing_directory).join(chosen_file)
        new_file.write(test_contents)
        assert new_file.read() == test_contents
        assert len(tmpdir.listdir()) == 1
        overall_directory = (
            tmpdir.dirname + "/" + tmpdir.basename + "/" + containing_directory
        )
        commandline_arguments = [
            "CountMarkdownTags",
            "--file",
            "file_to_find",
            "--directory",
            overall_directory,
            "--count",
            provided_count,
            "--tag",
            "heading",
            "--exact",
        ]
        parsed_arguments, remaining_arguments = arguments.parse(commandline_arguments)
        args_verified = arguments.verify(parsed_arguments)
        assert args_verified is True
        check_exists, checker_source, check_file = load_checker(parsed_arguments)
        assert check_exists is True
        check = checker_source.load_plugin(check_file)
        check_result = check.act(parsed_arguments, remaining_arguments)
        # check the result
        assert check_result is not None
        assert len(check_result) == 1
        # assert check_result[0] is expected_result
        # check the contents of the report
        assert report.get_result() is not None
        assert len(report.get_result()["check"]) > 1
        assert report.get_result()["outcome"] is expected_result
        if expected_result:
            assert report.get_result()["diagnostic"] == ""
        else:
            assert report.get_result()["diagnostic"] != ""
Beispiel #13
0
def test_arguments_verified(verifiable_gg_args):
    """Run arguments with verifiable arguments and it is verified"""
    gg_arguments = arguments.parse(verifiable_gg_args)
    gg_args_verified = arguments.verify(gg_arguments)
    assert gg_args_verified == VERIFIED
Beispiel #14
0
def test_default_argument_values_correct(no_gg_args):
    """The default command-line arguments are correct"""
    gg_arguments = arguments.parse(no_gg_args)
    arguments_args_verified = arguments.verify(gg_arguments)
    assert arguments_args_verified == NOT_VERIFIED
Beispiel #15
0
def test_invalid_argument_combinations_accepted(chosen_arguments):
    """Check that not valid argument combinations do not verify correctly"""
    parsed_arguments = arguments.parse(chosen_arguments)
    verified_arguments = arguments.verify(parsed_arguments)
    assert verified_arguments is False
Beispiel #16
0
def verify_arguments(parsed_arguments):
    """Parse, verify, and then return the parsed command-line arguments."""
    # verify the command-line arguments
    did_verify_arguments = arguments.verify(parsed_arguments)
    return did_verify_arguments
Beispiel #17
0
def test_description_is_not_valid_arguments_verify(commandline_arguments):
    """Check that command-line argument without valid string verifies."""
    gg_arguments, remaining_arguments = arguments.parse(commandline_arguments)
    args_verified = arguments.verify(gg_arguments)
    assert args_verified is False
Beispiel #18
0
def test_basic_check_correct():
    """Ensure when given verifiable arguments, there is no error and it is verified."""
    gg_arguments, remaining_arguments = arguments.parse(["CheckCommits"])
    args_verified = arguments.verify(gg_arguments)
    assert args_verified == VERIFIED
Beispiel #19
0
def test_optional_commandline_arguments_can_verify(commandline_arguments):
    """Check that correct optional command-line arguments check correctly."""
    gg_arguments, remaining_arguments = arguments.parse(commandline_arguments)
    args_verified = arguments.verify(gg_arguments)
    assert args_verified is True