Skip to content

Commit 00702c1

Browse files
updata Anagram
1 parent eac8778 commit 00702c1

File tree

3 files changed

+21
-47
lines changed

3 files changed

+21
-47
lines changed

Anagram/run

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,22 @@
1-
#! /bin/python3
2-
# coding: utf-8
1+
#!/bin/python3
2+
import importlib.util
3+
import sys
34

4-
from inginious import input
5-
from inginious import feedback
6-
from inginious import input
7-
import subprocess
8-
from inginious import rst
9-
import re
105

6+
# Dynamically load modules we need
7+
# Credits to https://stackoverflow.com/a/67692/6149867
8+
# And for the explanation : http://www.blog.pythonlibrary.org/2016/05/27/python-201-an-intro-to-importlib/
9+
def dynamically_load_module(module, path):
10+
spec = importlib.util.spec_from_file_location(module, path)
11+
mod = importlib.util.module_from_spec(spec)
12+
spec.loader.exec_module(mod)
13+
return mod
1114

12-
# Will be filled by process.py
13-
exercise = 'Anagram'
14-
student_file = f'{exercise}.java'
15-
test_file = f'{exercise}TestInginious.java'
1615

17-
# Archive for jplag
16+
#####################################
17+
# Our import for common run file #
18+
#####################################
19+
sys.path.append("/course/common")
1820

19-
input.parse_template(student_file)
20-
21-
student_name = input.get_input("@username")
22-
subprocess.call(['archive', '-a', student_file,'-o',student_name+''], universal_newlines=True)
23-
24-
25-
compile_error = subprocess.call(f'javac -cp ".:libs/junit-4.12.jar:libs/hamcrest-core-1.3.jar:libs/JavaGrading.jar" RunTests.java {test_file} {student_file} 2>&1', shell=True, stdout=open('compiler.out', 'w'))
26-
27-
if compile_error != 0:
28-
codeblock = rst.get_codeblock("java", open('compiler.out').read())
29-
feedback.set_global_feedback("Votre code ne compile pas: \n\n" + codeblock, True)
30-
feedback.set_global_result("failed")
31-
exit(0)
32-
33-
34-
try:
35-
out = subprocess.check_output('java -cp "libs/junit-4.12.jar:libs/hamcrest-core-1.3.jar:libs/JavaGrading.jar:." RunTests', shell=True).decode('utf8')
36-
out = out[out.index('--- GRADE ---'):]
37-
38-
grade = re.findall(r"^TOTAL ([0-9\.]+)/([0-9\.]+)$", out, re.MULTILINE)[-1]
39-
grade = 100.0*float(grade[0])/float(grade[1])
40-
41-
feedback.set_grade(grade)
42-
output = '\n'.join(out.split('\n')[1:-4])
43-
feedback.set_global_feedback("Résultat des tests: \n\n" + output, True)
44-
45-
if grade < 99.99 :
46-
feedback.set_global_result("failed")
47-
else:
48-
feedback.set_global_result("success")
49-
except Exception as e:
50-
feedback.set_global_feedback("Une erreur s'est produite!." + str(e), True)
51-
feedback.set_global_result("failed")
21+
runfile = dynamically_load_module("runfile", "/course/common/runfile.py")
22+
runfile.main()

Anagram/src/AnagramTestInginious.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.Assert.*;
44

55
import com.github.guillaumederval.javagrading.*;
6+
import templates.*;
67
public class AnagramTestInginious {
78

89
@Test

Anagram/templates/Anagram.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
@@code@@
1+
package templates;
2+
3+
@@student_answer@@

0 commit comments

Comments
 (0)