This repository was archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Common Code
jy95 edited this page Jul 30, 2019
·
1 revision
#!/bin/python3
import importlib.util
import sys
# Dynamically load modules we need
# Credits to https://stackoverflow.com/a/67692/6149867
# And for the explanation : http://www.blog.pythonlibrary.org/2016/05/27/python-201-an-intro-to-importlib/
def dynamically_load_module(module, path):
spec = importlib.util.spec_from_file_location(module, path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
#####################################
# Our import for common run file #
#####################################
sys.path.append("/course/common")
runfile = dynamically_load_module("runfile", "/course/common/runfile.py")
runfile.main()package src;
import com.github.guillaumederval.javagrading.GradingListener;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import java.util.List;
public class StudentTestRunner {
public static void main(String [] args) {
JUnitCore runner = new JUnitCore();
runner.addListener(new GradingListener());
Result result = runner.run(InginiousTests.class);
if(result.wasSuccessful()){
System.exit(0);
} else {
determineProblem(result);
}
}
/*
* Makes the distinction between two different failure cases :
* - The student has a mistake in his/her code. (Sys exit 1)
* - The student used a forbidden instruction in his/her code. (Sys exit 2)
*/
private static void determineProblem(Result result){
boolean flag = false;
if(result.getFailureCount() != 0) {
List<Failure> failures = result.getFailures();
for (Failure fail : failures) {
flag |= fail.getMessage()!= null && fail.getMessage().contains("access denied");
}
}
if(flag) {
System.exit(2); // The student used a forbidden instruction
} else {
System.exit(1); // There's an error in your code etc etc...
}
}
}package src;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
public class StudentTestRunner {
public static void main(String[] args) {
JUnitCore runner = new JUnitCore();
Result result = runner.run(StudentTests.class);
}
}package src;
import com.github.guillaumederval.javagrading.Grade;
import com.github.guillaumederval.javagrading.GradeFeedback;
import com.github.guillaumederval.javagrading.GradeFeedbacks;
import com.github.guillaumederval.javagrading.GradingRunner;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import templates.*;
import java.util.*;
// TODO Add your additional imports
@RunWith(GradingRunner.class) // classic "jail runner" from Guillaume's library
public class InginiousTests {
@Test
@Grade
@GradeFeedbacks({@GradeFeedback(message = "", onSuccess = true), @GradeFeedback(message = "MethodName() didn't work\n", onFail = true, onTimeout = true)})
public void test1() {
// For example ....
assertEquals(expected, result);
}
// TODO Add more tests
}