Skip to content

Commit f294778

Browse files
Code cleanup (#14)
1 parent a732091 commit f294778

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

create_debug_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
import os
3-
import sys
43
import subprocess
4+
import sys
55

66
if not __file__.endswith("shell.py"):
77
subprocess.call(

tin/templates/docs/sample_graders.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<h3>A grader for a program that outputs the nth Fibonacci number</h3>
1212
<pre><code>import sys, subprocess
13+
1314
N = 100
1415
cur_fib = 1
1516
next_fib = 1
@@ -19,32 +20,37 @@ <h3>A grader for a program that outputs the nth Fibonacci number</h3>
1920
try:
2021
res = subprocess.run(
2122
[sys.executable, sys.argv[1], str(i)],
22-
timeout = 5,
23-
stdin = subprocess.DEVNULL,
24-
stdout = subprocess.PIPE,
25-
stderr = subprocess.PIPE,
23+
timeout=5,
24+
stdin=subprocess.DEVNULL,
25+
stdout=subprocess.PIPE,
26+
stderr=subprocess.PIPE,
2627
)
2728
except subprocess.TimeoutExpired:
28-
print("Script timeout for number {}".format(i))
29+
print(f"Script timeout for number {i}")
2930
else:
3031
stdout = res.stdout.strip()
3132
if not res.stderr and res.returncode == 0:
3233
try:
3334
if int(stdout) == cur_fib:
3435
score += 1
3536
else:
36-
print("Invalid result for number {} (printed {}, answer is {})".format(i, int(stdout), cur_fib))
37+
print(
38+
f"Invalid result for number {i} (printed {int(stdout)}, answer is {cur_fib})"
39+
)
3740
failing_cases.append(i)
3841
except ValueError:
39-
print("Non-integer printed for number {}".format(i))
42+
print(f"Non-integer printed for number {i}")
4043
failing_cases.append(i)
4144
else:
42-
print("Script error for number {}".format(i))
45+
print(f"Script error for number {i}")
4346
failing_cases.append(i)
4447
next_fib, cur_fib = cur_fib + next_fib, next_fib
45-
print("Score: {}".format(score / N))
48+
print(f"Score: {score / N}")
4649

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

5056
{% endblock %}

tin/templates/venvs/show.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h2 class="left">{{ venv.name }}</h2>
2020
<p>If it takes more than a few minutes, please contact the Tin maintainers by emailing <a href="mailto:{{ DEVELOPER_EMAIL }}">{{ DEVELOPER_EMAIL }}</a>
2121
{% else %}
2222
<h3>Installed packages</h3>
23-
23+
2424
{% if venv.installing_packages %}
2525
<p class="italic">This virtual environment is currently installing or upgrading packages. This list may be
2626
incomplete.</p>
@@ -49,7 +49,7 @@ <h3>Installed packages</h3>
4949
{% endif %}
5050
{% endwith %}
5151
</table>
52-
52+
5353
<h3>Install packages</h3>
5454
{% if venv.installing_packages %}
5555
<p class="italic">
@@ -72,7 +72,7 @@ <h3>Install packages</h3>
7272
<input type="submit" value="Install packages"{% if venv.installing_packages %} disabled{% endif %}>
7373
</form>
7474
{% endif %}
75-
75+
7676
{% if venv.package_installation_output and not venv.installing_packages %}
7777
<h3>Last package installation output</h3>
7878
<pre><code class="nohljsln">{{ venv.package_installation_output }}</code></pre>

0 commit comments

Comments
 (0)