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 import listdir, mkdir, chmod
from os.path import join, exists from os.path import join, exists
from shutil import copyfile
from subprocess import call, TimeoutExpired from subprocess import call, TimeoutExpired
from Main.management.commands.bot import bot from Main.management.commands.bot import bot
@ -38,9 +39,10 @@ class BaseTester:
raise TestException("RE") raise TestException("RE")
result = open(join(self.solution.testing_directory, "output.txt"), "r").read().strip().replace('\r\n', '\n') result = open(join(self.solution.testing_directory, "output.txt"), "r").read().strip().replace('\r\n', '\n')
print("got result", result) print("got result", result)
if exists(join(self.path, "checker.sh")): if exists(join(self.path, "checker.py")):
self.solution.exec_command(f"chmod 777 checker.sh") copyfile(join(self.path, filename + '.a'), join(self.path, 'expected.txt'))
code = self.solution.exec_command(f"./checker.sh --expected {self.predicted} --output {result}") 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: if code != 0:
raise TestException("WA") raise TestException("WA")
else: else:
@ -93,16 +95,11 @@ class BaseTester:
print("Container created") print("Container created")
for file in ExtraFile.objects.filter(task=self.solution.task): for file in ExtraFile.objects.filter(task=self.solution.task):
with open( with open(
join(self.path, file.filename), "w" if file.filename == 'checker.sh' else 'wb' join(self.path, file.filename), 'wb'
) as fs: ) as fs:
bts = get_bytes(file.fs_id) 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") print("Files copied")
for file in listdir(self.path):
chmod(join(self.path, file), 0o777)
try: try:
self.before_test() self.before_test()
print("before test finished") print("before test finished")

View File

@ -216,7 +216,7 @@
<td valign="top"> <td valign="top">
{% for test in task.files %} {% for test in task.files %}
<div id="file_{{ test.id }}"> <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 %} {% if test.readable %}
<form method="POST">{% csrf_token %} <form method="POST">{% csrf_token %}
<!-- Modal --> <!-- Modal -->