repomate-junit4 Module Reference

This module reference is intended for developers contributing to repomate-junit4 and should not be considered a stable API.

junit4

Plugin that runs JUnit4 on test classes and corresponding production classes.

Important

Requires javac and java to be installed, and having hamcrest-core-1.3.jar and junit-4.12.jar on the local macine.

This plugin performs a fairly complicated tasks of running test classes from pre-specified reference tests on production classes that are dynamically discovered in student repositories. See the README for more details.

class repomate_junit4.junit4.JUnit4Hooks[source]
act_on_cloned_repo(path)[source]

Look for production classes in the student repo corresponding to test classes in the reference tests directory.

Assumes that all test classes end in Test.java and that there is a directory with the same name as the master repo in the reference tests directory.

Parameters:path (Union[str, Path]) – Path to the student repo.
Return type:HookResult
Returns:a plug.HookResult specifying the outcome.
clone_parser_hook(clone_parser)[source]

Add reference_tests_dir argument to parser.

Parameters:clone_parser (ConfigParser) – The clone subparser.
Return type:None
config_hook(config_parser)[source]

Look for hamcrest and junit paths in the config, and get the classpath.

Parameters:config – the config parser after config has been read.
Return type:None
parse_args(args)[source]

Get command line arguments.

Parameters:args (Namespace) – The full namespace returned by

:param argparse.ArgumentParser.parse_args():

Return type:None

_java

Utility functions for activities related to Java.

This module contains utility functions dealing with Java-specific behavior, such as parsing package statements from Java files and determining if a class is abstract.

repomate_junit4._java.extract_package(class_)[source]

Return the name package of the class. An empty string denotes the default package.

Return type:str
repomate_junit4._java.extract_package_root(class_, package)[source]

Return the package root, given that class_ is the path to a .java file. If the package is the default package (empty string), simply return a copy of class_.

Raise if the directory structure doesn’t correspond to the package statement.

Return type:Path
repomate_junit4._java.fqn(package_name, class_name)[source]

Return the fully qualified name (Java style) of the class.

Parameters:
  • package_name (str) – Name of the package. The default package should be an empty string.
  • class_name (str) – Canonical name of the class.
Return type:

str

Returns:

The fully qualified name of the class.

repomate_junit4._java.generate_classpath(*paths, classpath='')[source]

Return a classpath including all of the paths provided. Always appends the current working directory to the end.

Parameters:
  • paths (Path) – One or more paths to add to the classpath.
  • classpath (str) – An initial classpath to append to.
Return type:

str

Returns:

a formated classpath to be used with java and javac

repomate_junit4._java.is_abstract_class(class_)[source]

Check if the file is an abstract class.

Parameters:class – Path to a Java class file.
Return type:bool
Returns:True if the class is abstract.
repomate_junit4._java.javac(java_files, classpath)[source]

Run javac on all of the specified files, assuming that they are all .java files.

Parameters:
Return type:

Tuple[str, str]

Returns:

(status, msg), where status is e.g. Status.ERROR and the message describes the outcome in plain text.

repomate_junit4._java.pairwise_compile(test_classes, java_files, classpath)[source]

Compile test classes with their associated production classes.

For each test class:

  1. Find the associated production class among the java_files

2. Compile the test class together with all of the .java files in the associated production class’ directory.

Parameters:
  • test_classes (List[Path]) – A list of paths to test classes.
  • java_files (List[Path]) – A list of paths to java files from the student repo.
  • classpath (str) – A base classpath to use.
Return type:

Tuple[List[HookResult], List[HookResult]]

Returns:

A tuple of lists of HookResults on the form (succeeded, failed)

repomate_junit4._java.properly_packaged(path, package)[source]

Check if the path ends in a directory structure that corresponds to the package.

Parameters:
  • path (Path) – Path to a Java file.
  • package (str) – The name of a Java package.
Return type:

bool

Returns:

True iff the directory structure corresponds to the package name.

_junit4_runner

repomate_junit4._junit4_runner.get_num_failed(test_output)[source]

Get the amount of failed tests from the error output of JUnit4.

Return type:int
repomate_junit4._junit4_runner.parse_failed_tests(test_output)[source]

Return a list of test failure descriptions, excluding stack traces.

Return type:str
repomate_junit4._junit4_runner.run_test_class(test_class, prod_class, classpath, verbose=False, security_policy=None)[source]

Run a single test class on a single production class.

Parameters:
  • test_class (Path) – Path to a Java test class.
  • prod_class (Path) – Path to a Java production class.
  • classpath (str) – A classpath to use in the tests.
  • verbose (bool) – Whether to output more failure information.
Return type:

Tuple[str, str]

Returns:

()

repomate_junit4._junit4_runner.security_policy(classpath, active)[source]

Yield the path to the default security policy file if active, else yield None. The policy file is deleted once the context is exited.

TODO: Make it possible to use a custom security policy here.