read test config from file

This commit is contained in:
virusdefender 2016-01-23 21:50:22 +08:00
parent 2299a0cd07
commit baa924ec52
10 changed files with 14 additions and 4 deletions

View File

@ -46,7 +46,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
if (!next) {
break;
}
if (!PyString_Check(next)) {
if (!PyString_Check(next) && !PyUnicode_Check(next)) {
PyErr_SetString(PyExc_ValueError, "arg must be string");
return NULL;
}
@ -68,7 +68,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
if (!next) {
break;
}
if (!PyString_Check(next)) {
if (!PyString_Check(next) && !PyUnicode_Check(next)) {
PyErr_SetString(PyExc_ValueError, "env must be string");
return NULL;
}

1
tests/1/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000}

1
tests/2/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 200000000}

1
tests/3/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000}

1
tests/4/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000}

1
tests/5/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000}

1
tests/6/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000}

1
tests/7/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000}

1
tests/8/config Normal file
View File

@ -0,0 +1 @@
{"language": "c", "max_cpu_time": 2000, "max_memory": 200000000, "args": ["hello", "123"]}

View File

@ -26,11 +26,13 @@ class JudgerTest(TestCase):
for i in range(1, 9):
test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), str(i))
exe_path = os.path.join("/tmp/judger_test", str(i))
self.assertEqual(self.compile_src(os.path.join(test_dir, "Main.c"), "c", exe_path), 0)
config = json.loads(open(os.path.join(test_dir, "config")).read())
self.assertEqual(self.compile_src(os.path.join(test_dir, "Main.c"), config.pop("language"), exe_path), 0)
run_result = judger.run(path=exe_path,
in_file=os.path.join(test_dir, "in"),
out_file=os.path.join(self.tmp_path, str(i) + ".out"),
max_cpu_time=2000, max_memory=200000000, args=["hello", "123"])
**config)
result = json.loads(open(os.path.join(test_dir, "result")).read())
self.assertEqual(result["flag"], run_result["flag"])
self.assertEqual(result["signal"], run_result["signal"])