diff --git a/tests/test.py b/tests/test.py index cc21570..df1263d 100644 --- a/tests/test.py +++ b/tests/test.py @@ -55,75 +55,64 @@ class JudgerTest(TestCase): def _judger_cpu_time_args_check(self): with self.assertRaisesRegexp(ValueError, "max_cpu_time must > 1 ms"): - judger.run(path="/bin/ls", - in_file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "/dev/null"), + judger.run(path="/bin/true", in_file="/dev/null", out_file="/dev/null", max_cpu_time=-1, max_memory=200000000, env=["aaa=123"], use_sandbox=False, use_nobody=False) def _judger_memory_args_check(self): with self.assertRaisesRegexp(ValueError, "max_memory must > 16M"): - judger.run(path="/bin/ls", - in_file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "/dev/null"), + judger.run(path="/bin/true", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=100, env=["aaa=123"], use_sandbox=True, use_nobody=True) def _judger_exec_file_args_check(self): - with self.assertRaisesRegexp(ValueError, "in_file does not exist"): - judger.run(path="/bin/xxx", - in_file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "/dev/null"), + with self.assertRaisesRegexp(ValueError, "Exec file does not exist"): + judger.run(path="/bin/not_found", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, env=["aaa=123"], use_sandbox=True, use_nobody=True) def _judger_in_file_args_check(self): with self.assertRaisesRegexp(ValueError, "in_file does not exist"): - judger.run(path="/bin/xxx", - in_file="/dev/xxx", + judger.run(path="/bin/true", in_file="/dev/xxx", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, env=["aaa=123"], use_sandbox=True, use_nobody=True) def _judger_args_args_check(self): with self.assertRaisesRegexp(ValueError, "args must be a list"): - judger.run(path="/bin/ls", - in_file="/dev/null", + judger.run(path="/bin/ls", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, args=123, use_sandbox=True, use_nobody=True) with self.assertRaisesRegexp(ValueError, "arg in args must be a string"): - judger.run(path="/bin/ls", - in_file="/dev/null", + judger.run(path="/bin/ls", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, args=["123", {"a": "b"}], use_sandbox=True, use_nobody=True) with self.assertRaisesRegexp(ValueError, "Number of args must < 95"): - judger.run(path="/bin/ls", - in_file="/dev/null", + judger.run(path="/bin/ls", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, args=["123"] * 200, use_sandbox=True, use_nobody=True) def _judger_env_args_check(self): with self.assertRaisesRegexp(ValueError, "env must be a list"): - judger.run(path="/bin/ls", - in_file="/dev/null", + judger.run(path="/bin/true", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, env=123, use_sandbox=True, use_nobody=True) with self.assertRaisesRegexp(ValueError, "env item must be a string"): - judger.run(path="/bin/ls", - in_file="/dev/null", + judger.run(path="/bin/ls", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, env=["123", {"a": "b"}], use_sandbox=True, use_nobody=True) with self.assertRaisesRegexp(ValueError, "Number of env must < 95"): - judger.run(path="/bin/ls", - in_file="/dev/null", + judger.run(path="/bin/true", in_file="/dev/null", out_file="/dev/null", max_cpu_time=1000, max_memory=200000000, env=["123=345"] * 200, use_sandbox=True, use_nobody=True) def _judger_user_args_check(self): os.setuid(pwd.getpwnam("nobody").pw_uid) with self.assertRaisesRegexp(ValueError, "Root user is required when use_nobody=True"): - judger.run(path="/bin/ls", - in_file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "/dev/null"), + judger.run(path="/bin/ls", in_file="/dev/null", out_file="/dev/null", max_cpu_time=2000, max_memory=200000000, env=["aaa=123"], use_sandbox=True, use_nobody=True)