From 62c11f2796fb0c65ae691b8eb0475ec1bb031674 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 23 Sep 2024 10:37:21 +0200 Subject: [PATCH] Change default checker to oicompare (#31) * Change default checker to oicompare * Ability to change oicompare's language * Allow changing oicompare format (cherry picked from commit de8cc9330145f76be7a769d75a333d61cd72b899) --- sio/executors/checker.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/sio/executors/checker.py b/sio/executors/checker.py index 7e3f29d..eb16080 100644 --- a/sio/executors/checker.py +++ b/sio/executors/checker.py @@ -58,11 +58,13 @@ def execute_checker(with_stderr=False, stderr=None): return renv['stdout'] -def _run_compare(env): - e = SandboxExecutor('exec-sandbox-v1.2') - renv = _run_in_executor(env, [os.path.join('bin', 'compare'), - 'hint', 'out'], e, ignore_errors=True) - return renv['stdout'] + +def _run_compare(env, format): + e = SandboxExecutor('oicompare-sandbox-v1.0.2') + renv = _run_in_executor( + env, [os.path.join('bin', 'oicompare'), 'hint', 'out', format], e, ignore_errors=True + ) + return renv def _limit_length(s): if len(s) > RESULT_STRING_LENGTH_LIMIT: @@ -83,7 +85,21 @@ def run(environ, use_sandboxes=True): output = _run_checker(environ, use_sandboxes) elif use_sandboxes: - output = _run_compare(environ) + renv = _run_compare(environ, environ.get('checker_format', 'english_abbreviated')) + if renv['return_code'] == 0: + environ['result_code'] = 'OK' + environ['result_percentage'] = (100, 1) + elif renv['return_code'] == 1: + environ['result_code'] = 'WA' + environ['result_percentage'] = (0, 1) + # Should be redundant because we are using oicompare with abbreviated output, + # but just in case. + environ['result_string'] = _limit_length(renv['stdout'][0]) + else: + raise CheckerError( + 'oicompare returned code(%d). Checker renv: %s' % (renv['return_code'], renv) + ) + return environ else: output = _run_diff(environ) except (CheckerError, ExecError) as e: