def test_runner_compile_error(): try: print( soSorryYouLose( str(dummypath / "dummy_iwontcompile.c"), str(dummypath / "dummy_input.txt"), str(dummypath / "dummy_input.txt") ) ) except ContainerError as err: assert 1
def validate_code(source_code, language_name, task): """ :param source_code: the code which is a solution of the task by a user :param language_name: the name of the programming language of the task :param task: selected task by a user :return: `Status <../html/submissions.html#submissions-status-module>`_ """ language = Language.from_string(language_name) lang_suffix = "." + language.get_suffix() try: code_file = create_tmp_file("sourceCode" + lang_suffix, source_code) input_public_file = create_tmp_file("input0.txt", task.input_public) input_hidden_file = create_tmp_file("tnput1.txt", task.input_hidden) output = soSorryYouLose(code_file, input_public_file, input_hidden_file) except MemoryError: return Status.MLE, except TimeoutError: return Status.TLE, except ContainerError as err: return Status.CE, err.stderr.decode("utf-8") finally: os.remove(code_file) os.remove(input_public_file) os.remove(input_hidden_file) out = output.split("__SPLIT_PLACEHOLDER__\n") ok = judge(task.output_public, out[0]) if not ok: return Status.WA, \ "on test:\n" + \ task.input_public + \ "\nExpected output:\n" + \ task.output_public + \ "\ngot:\n" + \ out[0] ok = judge(task.output_hidden, out[1]) if ok: return Status.OK, else: return Status.WA, "on hidden tests"
def test_runner_fails_code_file_doesnt_exist(): with pytest.raises(FileNotFoundError): soSorryYouLose("/path/to/nowhere.c", inputpath, inputpath)
def test_runner_out_of_mem(): codefpath = str(dummypath / 'heavyone.py') with pytest.raises(OutOfMemoryError) as err: soSorryYouLose(codefpath, str(dummypath / 'dummy_input.txt'), str(dummypath / 'dummy_input.txt'), mem_limit="4m", time_limit=100) assert str(err.value) == OutOfMemoryError.FAIL_MSG
def test_runner_timeout(): codefpath = str(dummypath / 'goodnight.py') with pytest.raises(TimeoutError) as err: soSorryYouLose(codefpath, str(dummypath / 'dummy_input.txt'), str(dummypath / 'dummy_input.txt'), time_limit=1.0) assert str(err.value) == TimeoutError.FAIL_MSG
def test_runner_c_stdin_ok(): codefpath = str(dummypath / "dummy_stdin.c") infile = str(dummypath / "dummy_input.txt") expected = "It takes 8 bits to represent 220\n" assert soSorryYouLose(codefpath, infile, infile) == expected + "__SPLIT_PLACEHOLDER__\n" + expected
def test_runner_java_ok(): codefpath = str(dummypath / "dummy.java") expected = "Factorial of 4 is 24\n" assert soSorryYouLose(codefpath, inputpath, inputpath) == expected + "__SPLIT_PLACEHOLDER__\n" + expected
def test_runner_go_ok(): codefpath = str(dummypath / "dummy.go") expected = "GO somewhere else!\n" assert soSorryYouLose(codefpath, inputpath, inputpath) == expected + "__SPLIT_PLACEHOLDER__\n" + expected
def test_runner_py3_ok(): codefpath = str(dummypath / "dummy.py") expected = "The 10th Fib number is 55\n" assert soSorryYouLose(codefpath, inputpath, inputpath) == expected + "__SPLIT_PLACEHOLDER__\n" + expected
def test_runner_cpp_ok(): codefpath = str(dummypath / "dummy.cpp") expected = "Distance from p1 and p2 is 0\n" assert soSorryYouLose(codefpath, inputpath, inputpath) == expected + "__SPLIT_PLACEHOLDER__\n" + expected
def test_runner_c_ok(): codefpath = str(dummypath / "dummy.c") expected = "It takes 8 bits to represent 222\n" assert soSorryYouLose(codefpath, inputpath, inputpath) == expected + "__SPLIT_PLACEHOLDER__\n" + expected
def test_runner_fails_for_invalid_path(path): with pytest.raises(ValueError): soSorryYouLose(path, str(dummypath / "dummy_input.txt"), str(dummypath / "dummy_input.txt"))
def test_runner_fails_stdin_file_doesnt_exist(): with pytest.raises(FileNotFoundError): soSorryYouLose(str(dummypath / "dummy.c"), "/path/to/nowhere.txt", "/path/to/nowhere.txt")