diff --git a/judger.c b/judger.c index 9a679a2..83045d5 100644 --- a/judger.c +++ b/judger.c @@ -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; } diff --git a/tests/1/config b/tests/1/config new file mode 100644 index 0000000..4412869 --- /dev/null +++ b/tests/1/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000} \ No newline at end of file diff --git a/tests/2/config b/tests/2/config new file mode 100644 index 0000000..41e3a53 --- /dev/null +++ b/tests/2/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 200000000} \ No newline at end of file diff --git a/tests/3/config b/tests/3/config new file mode 100644 index 0000000..4412869 --- /dev/null +++ b/tests/3/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000} \ No newline at end of file diff --git a/tests/4/config b/tests/4/config new file mode 100644 index 0000000..4412869 --- /dev/null +++ b/tests/4/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000} \ No newline at end of file diff --git a/tests/5/config b/tests/5/config new file mode 100644 index 0000000..4412869 --- /dev/null +++ b/tests/5/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000} \ No newline at end of file diff --git a/tests/6/config b/tests/6/config new file mode 100644 index 0000000..4412869 --- /dev/null +++ b/tests/6/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000} \ No newline at end of file diff --git a/tests/7/config b/tests/7/config new file mode 100644 index 0000000..4412869 --- /dev/null +++ b/tests/7/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 20000000} \ No newline at end of file diff --git a/tests/8/config b/tests/8/config new file mode 100644 index 0000000..5c95759 --- /dev/null +++ b/tests/8/config @@ -0,0 +1 @@ +{"language": "c", "max_cpu_time": 2000, "max_memory": 200000000, "args": ["hello", "123"]} \ No newline at end of file diff --git a/tests/test.py b/tests/test.py index f69fca9..265a6f8 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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"])