fix wrong path in tests

This commit is contained in:
virusdefender 2016-03-31 18:33:58 +08:00
parent 62619ae9da
commit 4315efac56

View File

@ -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)