new checker

This commit is contained in:
Egor Matveev 2022-02-07 21:01:32 +03:00
parent ea8c5085b9
commit aa4d167039
2 changed files with 8 additions and 11 deletions

View File

@ -1,5 +1,6 @@
from os import listdir, mkdir, chmod
from os.path import join, exists
from shutil import copyfile
from subprocess import call, TimeoutExpired
from Main.management.commands.bot import bot
@ -38,9 +39,10 @@ class BaseTester:
raise TestException("RE")
result = open(join(self.solution.testing_directory, "output.txt"), "r").read().strip().replace('\r\n', '\n')
print("got result", result)
if exists(join(self.path, "checker.sh")):
self.solution.exec_command(f"chmod 777 checker.sh")
code = self.solution.exec_command(f"./checker.sh --expected {self.predicted} --output {result}")
if exists(join(self.path, "checker.py")):
copyfile(join(self.path, filename + '.a'), join(self.path, 'expected.txt'))
call(f"docker run --name solution_{self.solution.id}_checker --volume=/sprint-data/solutions/{self.solution.id}:/app -t -d python:3.6", shell=True)
code = call(f'docker exec -i solution_{self.solution.id}_checker sh -c "cd app && python checker.py"', timeout=1)
if code != 0:
raise TestException("WA")
else:
@ -93,16 +95,11 @@ class BaseTester:
print("Container created")
for file in ExtraFile.objects.filter(task=self.solution.task):
with open(
join(self.path, file.filename), "w" if file.filename == 'checker.sh' else 'wb'
join(self.path, file.filename), 'wb'
) as fs:
bts = get_bytes(file.fs_id)
if file.filename == 'checker.sh':
fs.write(bts.decode("utf-8"))
else:
fs.write(bts)
fs.write(bts)
print("Files copied")
for file in listdir(self.path):
chmod(join(self.path, file), 0o777)
try:
self.before_test()
print("before test finished")

View File

@ -216,7 +216,7 @@
<td valign="top">
{% for test in task.files %}
<div id="file_{{ test.id }}">
<i class="fa {% if test.filename == "checker.sh" %}fa-cogs{% else %}fa-file{% endif %}"></i> <button class="btn btn-link" {% if not test.readable %}style="color: red;" {% else %}data-toggle="modal" data-target="#filesModalLong{{ test.id }}"{% endif %}>{{ test.filename }}</button><button class="btn btn-link" style="color: black;" onclick="deleteFile({{ test.id }});"><i class="fa fa-times"></i> </button><br>
<i class="fa {% if test.filename == "checker.py" %}fa-cogs{% else %}fa-file{% endif %}"></i> <button class="btn btn-link" {% if not test.readable %}style="color: red;" {% else %}data-toggle="modal" data-target="#filesModalLong{{ test.id }}"{% endif %}>{{ test.filename }}</button><button class="btn btn-link" style="color: black;" onclick="deleteFile({{ test.id }});"><i class="fa fa-times"></i> </button><br>
{% if test.readable %}
<form method="POST">{% csrf_token %}
<!-- Modal -->