Skip to content

Commit

Permalink
[feat] Prefix cli options with --junit4 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse authored Nov 24, 2019
1 parent d56e66c commit 4cf235f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ fi

pip install -e ".[TEST]"

wget http://central.maven.org/maven2/junit/junit/4.12/junit-4.12.jar
wget http://central.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
curl https://search.maven.org/remotecontent?filepath=junit/junit/4.12/junit-4.12.jar -o junit-4.12.jar
curl https://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar -o hamcrest-core-1.3.jar
27 changes: 14 additions & 13 deletions repobee_junit4/junit4.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,65 +145,66 @@ def clone_parser_hook(
clone_parser: The ``clone`` subparser.
"""
clone_parser.add_argument(
"-rtd",
"--reference-tests-dir",
"--junit4-reference-tests-dir",
help="Path to a directory with reference tests.",
type=str,
dest="reference_tests_dir",
required=not self._reference_tests_dir,
)

clone_parser.add_argument(
"-i",
"--ignore-tests",
"--junit4-ignore-tests",
help="Names of test classes to ignore.",
type=str,
dest="ignore_tests",
nargs="+",
)

clone_parser.add_argument(
"-ham",
"--hamcrest-path",
"--junit4-hamcrest-path",
help="Absolute path to the `{}` library.".format(
_junit4_runner.HAMCREST_JAR
),
type=str,
dest="hamcrest_path",
# required if not picked up in config_hook nor on classpath
required=not self._hamcrest_path
and _junit4_runner.HAMCREST_JAR not in self._classpath,
)

clone_parser.add_argument(
"-junit",
"--junit-path",
"--junit4-junit-path",
help="Absolute path to the `{}` library.".format(
_junit4_runner.JUNIT_JAR
),
type=str,
dest="junit_path",
# required if not picked up in config_hook nor on classpath
required=not self._junit_path
and _junit4_runner.JUNIT_JAR not in self._classpath,
)

clone_parser.add_argument(
"--disable-security",
"--junit4-disable-security",
help=(
"Disable the default security policy (student code can do "
"whatever)."
),
dest="disable_security",
action="store_true",
)

verbosity = clone_parser.add_mutually_exclusive_group()
verbosity.add_argument(
"-v",
"--verbose",
"--junit4-verbose",
help="Display more information about test failures.",
dest="verbose",
action="store_true",
)
verbosity.add_argument(
"-vv",
"--very-verbose",
"--junit4-very-verbose",
help="Display the full failure output, without truncating.",
dest="very_verbose",
action="store_true",
)

Expand Down
40 changes: 21 additions & 19 deletions tests/unit_tests/test_junit4.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,22 @@ class TestCloneParserHook:
"verbose, very_verbose", [(None, None), (False, True), (True, False)]
)
def test_arguments_get_added(self, junit4_hooks, verbose, very_verbose):
"""Just test that `-rtd`, `-i`, `-ham` and `-junit` get added
correctly and that the args can then be parsed as expected.
"""
parser = ArgumentParser()
sys_args = [
"-rtd",
"--junit4-reference-tests-dir",
RTD,
"-i",
"--junit4-ignore-tests",
" ".join(IGNORE_TESTS),
"-ham",
"--junit4-hamcrest-path",
HAMCREST_PATH,
"-junit",
"--junit4-junit-path",
JUNIT_PATH,
]

if verbose:
sys_args += ["-v"]
sys_args += ["--junit4-verbose"]
if very_verbose:
sys_args += ["-vv"]
sys_args += ["--junit4-very-verbose"]

junit4_hooks.clone_parser_hook(parser)

Expand All @@ -268,14 +265,14 @@ def test_verbose_and_very_verbose_mutually_exclusive(self, junit4_hooks):
"""
parser = ArgumentParser()
sys_args = [
"-rtd",
"--junit4-reference-tests-dir",
RTD,
"-ham",
"--junit4-hamcrest-path",
HAMCREST_PATH,
"-junit",
"--junit4-junit-path",
JUNIT_PATH,
"--verbose",
"--very-verbose",
"--junit4-verbose",
"--junit4-very-verbose",
]

junit4_hooks.clone_parser_hook(parser)
Expand All @@ -289,14 +286,14 @@ def test_args_required_if_undefined(self, junit4_hooks, skip_arg):
defined in either config or classpath (for hamcrest and junit).
"""
parser = ArgumentParser()
sys_args = ["-i", " ".join(IGNORE_TESTS)]
sys_args = ["--junit4-ignore-tests", " ".join(IGNORE_TESTS)]

if skip_arg != "ham":
sys_args.extend(["-ham", HAMCREST_PATH])
sys_args.extend(["--junit4-hamcrest-path", HAMCREST_PATH])
if skip_arg != "junit":
sys_args.extend(["-junit", JUNIT_PATH])
sys_args.extend(["--junit4-junit-path", JUNIT_PATH])
if skip_arg != "rtd":
sys_args.extend(["-rtd", RTD])
sys_args.extend(["--junit4-refernce-tests-dir", RTD])

junit4_hooks.clone_parser_hook(parser)

Expand All @@ -309,7 +306,12 @@ def test_hamcrest_and_junit_not_required_if_on_classpath(
"""Just checks that there is no chrash."""
config_parser = ConfigParser()
arg_parser = ArgumentParser()
sys_args = ["-rtd", RTD, "-i", " ".join(IGNORE_TESTS)]
sys_args = [
"--junit4-reference-tests-dir",
RTD,
"--junit4-ignore-tests",
" ".join(IGNORE_TESTS),
]
getenv_empty_classpath.side_effect = (
lambda name: CLASSPATH_WITH_JARS if name == "CLASSPATH" else None
)
Expand Down

0 comments on commit 4cf235f

Please sign in to comment.