Skip to content

Commit

Permalink
Code cleanup (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 authored May 9, 2024
1 parent a732091 commit f294778
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion create_debug_users.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
import sys

if not __file__.endswith("shell.py"):
subprocess.call(
Expand Down
26 changes: 16 additions & 10 deletions tin/templates/docs/sample_graders.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<h3>A grader for a program that outputs the nth Fibonacci number</h3>
<pre><code>import sys, subprocess

N = 100
cur_fib = 1
next_fib = 1
Expand All @@ -19,32 +20,37 @@ <h3>A grader for a program that outputs the nth Fibonacci number</h3>
try:
res = subprocess.run(
[sys.executable, sys.argv[1], str(i)],
timeout = 5,
stdin = subprocess.DEVNULL,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
timeout=5,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
except subprocess.TimeoutExpired:
print("Script timeout for number {}".format(i))
print(f"Script timeout for number {i}")
else:
stdout = res.stdout.strip()
if not res.stderr and res.returncode == 0:
try:
if int(stdout) == cur_fib:
score += 1
else:
print("Invalid result for number {} (printed {}, answer is {})".format(i, int(stdout), cur_fib))
print(
f"Invalid result for number {i} (printed {int(stdout)}, answer is {cur_fib})"
)
failing_cases.append(i)
except ValueError:
print("Non-integer printed for number {}".format(i))
print(f"Non-integer printed for number {i}")
failing_cases.append(i)
else:
print("Script error for number {}".format(i))
print(f"Script error for number {i}")
failing_cases.append(i)
next_fib, cur_fib = cur_fib + next_fib, next_fib
print("Score: {}".format(score / N))
print(f"Score: {score / N}")

with open(sys.argv[4], "a") as logfile:
logfile.write("User: {}; Score: {}/{}; Failing test cases: {}\n".format(sys.argv[3], score, N, ", ".join(map(str, failing_cases))))</code></pre>
logfile.write(
f"User: {sys.argv[3]}; Score: {score}/{N}; Failing test cases: {', '.join(str(case) for case in failing_cases)}\n"
)
</code></pre>

{% endblock %}
6 changes: 3 additions & 3 deletions tin/templates/venvs/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 class="left">{{ venv.name }}</h2>
<p>If it takes more than a few minutes, please contact the Tin maintainers by emailing <a href="mailto:{{ DEVELOPER_EMAIL }}">{{ DEVELOPER_EMAIL }}</a>
{% else %}
<h3>Installed packages</h3>

{% if venv.installing_packages %}
<p class="italic">This virtual environment is currently installing or upgrading packages. This list may be
incomplete.</p>
Expand Down Expand Up @@ -49,7 +49,7 @@ <h3>Installed packages</h3>
{% endif %}
{% endwith %}
</table>

<h3>Install packages</h3>
{% if venv.installing_packages %}
<p class="italic">
Expand All @@ -72,7 +72,7 @@ <h3>Install packages</h3>
<input type="submit" value="Install packages"{% if venv.installing_packages %} disabled{% endif %}>
</form>
{% endif %}

{% if venv.package_installation_output and not venv.installing_packages %}
<h3>Last package installation output</h3>
<pre><code class="nohljsln">{{ venv.package_installation_output }}</code></pre>
Expand Down

0 comments on commit f294778

Please sign in to comment.