Skip to content

Commit 51fc812

Browse files
committed
chore: Turtle test exercise and production Python execution environment
The Python execution environment is identical to production and a Turtle example was added for easy local testing.
1 parent 955f7d6 commit 51fc812

File tree

7 files changed

+522
-5
lines changed

7 files changed

+522
-5
lines changed

db/seeds/turtle/default.pylintrc

Lines changed: 419 additions & 0 deletions
Large diffs are not rendered by default.

db/seeds/turtle/main.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from turtle import *
2+
3+
def erstelle_turtle(x, y, rotationsWinkel = 0, shape = "triangle", color = "green"):
4+
steuerung = Turtle()
5+
steuerung.speed(0) # schnellste Animationsgeschwindigkeit, um sichtbare Bewegung zu vermeiden
6+
steuerung.shape(shape)
7+
steuerung.color(color)
8+
steuerung.right(rotationsWinkel)
9+
steuerung.penup()
10+
steuerung.goto(x, y)
11+
steuerung.direction = "stop" # nur für Kopf relevant
12+
return steuerung
13+
14+
rechts = erstelle_turtle(180, -160)
15+
unten = erstelle_turtle(160, -180, 90)
16+
links = erstelle_turtle(140, -160, 180)
17+
oben = erstelle_turtle(160, -140, 270)
18+
kopf = erstelle_turtle(0, 0, 0, "square", "black")
19+
20+
def setze_richtung(dahin, dahinNicht):
21+
# Vermeiden, dass Schlangenkopf zurück in sich selbst laufen kann
22+
if kopf.direction != dahinNicht:
23+
kopf.direction = dahin
24+
kopf_bewegen()
25+
26+
def kopf_bewegen():
27+
if kopf.direction == "down":
28+
y = kopf.ycor()
29+
kopf.sety(y - 20)
30+
31+
elif kopf.direction == "right":
32+
x = kopf.xcor()
33+
kopf.setx(x + 20)
34+
35+
elif kopf.direction == "up":
36+
y = kopf.ycor()
37+
kopf.sety(y + 20)
38+
39+
elif kopf.direction == "left":
40+
x = kopf.xcor()
41+
kopf.setx(x - 20)
42+
43+
44+
def checke_kollision_mit_fensterrand():
45+
if kopf.xcor() > 190 or kopf.xcor() < -190 or kopf.ycor() > 190 or kopf.ycor() < -190:
46+
spiel_neustarten()
47+
48+
49+
def interpretiere_eingabe(x, y):
50+
if (x >= 170 and x <= 190 and y >= -170 and y <= -150):
51+
setze_richtung("right", "left")
52+
elif (x >= 150 and x <= 170 and y >= -190 and y <= -170):
53+
setze_richtung("down", "up")
54+
elif (x >= 130 and x <= 150 and y >= -170 and y <= -150):
55+
setze_richtung("left", "right")
56+
elif (x >= 150 and x <= 170 and y >= -150 and y <= -130):
57+
setze_richtung("up", "down")
58+
else:
59+
return None
60+
checke_kollision_mit_fensterrand()
61+
62+
def spiel_neustarten():
63+
kopf.goto(0, 0)
64+
kopf.direction = "stop"
65+
66+
onclick(interpretiere_eingabe)
67+
mainloop()

db/seeds/turtle/test_style.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pylint import epylint as lint
2+
import glob
3+
4+
pylint_opts = ['--rcfile=default.pylintrc']
5+
exercise = glob.glob('main.py')[0]
6+
lint.lint(exercise, options=pylint_opts)
7+
exit()

spec/factories/execution_environment.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@
7373
created_by_teacher
7474
default_memory_limit
7575
default_cpu_limit
76-
docker_image { 'openhpi/co_execenv_python:3.4' }
76+
docker_image { 'openhpi/co_execenv_python:3.8' }
7777
file_type { association :dot_py, user: }
7878
help
79-
name { 'Python 3.4' }
79+
name { 'Python 3.8' }
8080
network_enabled { false }
8181
privileged_execution { false }
8282
permitted_execution_time { 10.seconds }
8383
pool_size { 0 }
84-
run_command { 'python3 %{filename}' }
84+
run_command { 'python3 -B /usr/lib/python3.8/webpython.py -f %{filename}' }
8585
singleton_execution_environment
8686
test_command { 'python3 -m unittest --verbose %{module_name}' }
87-
testing_framework { 'PyUnitAdapter' }
87+
testing_framework { 'PyUnitAndPyLintAdapter' }
8888
end
8989

9090
factory :ruby, class: 'ExecutionEnvironment' do

spec/factories/exercise.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ def create_seed_file(exercise, path, file_attributes = {})
7575
end
7676
end
7777

78+
factory :turtle, class: 'Exercise' do
79+
created_by_teacher
80+
description { 'Interactive Turtle test exercise.' }
81+
execution_environment { association :python, user: }
82+
instructions
83+
title { 'Interactive Turtle' }
84+
85+
after(:create) do |exercise|
86+
create_seed_file(exercise, 'turtle/main.py', role: 'main_file')
87+
create_seed_file(exercise, 'turtle/test_style.py', feedback_message: 'Your solution is not correctly formated.', hidden: true, role: 'teacher_defined_linter')
88+
create_seed_file(exercise, 'turtle/default.pylintrc', hidden: true, role: 'regular_file')
89+
end
90+
end
91+
7892
factory :fibonacci, class: 'Exercise' do
7993
created_by_teacher
8094
description { 'Implement a recursive function that calculates a requested Fibonacci number.' }

spec/factories/file_type.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@
124124
singleton_file_type
125125
end
126126

127+
factory :dot_pylintrc, class: 'FileType' do
128+
created_by_admin
129+
editor_mode { 'ace/mode/plain_text' }
130+
executable
131+
file_extension { '.pylintrc' }
132+
indent_size { 4 }
133+
name { 'Python' }
134+
singleton_file_type
135+
end
136+
127137
factory :dot_rb, class: 'FileType' do
128138
created_by_admin
129139
editor_mode { 'ace/mode/ruby' }

spec/services/proforma_service/convert_task_to_exercise_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
before { create(:python) }
147147

148148
it 'sets the execution_environment based on proglang name and value' do
149-
expect(convert_to_exercise_service).to have_attributes(execution_environment: have_attributes(name: 'Python 3.4'))
149+
expect(convert_to_exercise_service).to have_attributes(execution_environment: have_attributes(name: 'Python 3.8'))
150150
end
151151
end
152152

0 commit comments

Comments
 (0)