Tutorial: Moodle VPL -- Evaluation Using A Custom Python Program
--E. Mendelowitz (talk) 13:30, 4 July 2014 (PST)
In this tutorial we setup a VPL activity to test student Python programs using a custom python program. The custom program tests for the existence of a function called randomInt and checks to see if the value returned by the function is actually an integer. (These are tests that cannon be done using the standard VPL .cases
file).
Setup
- Moodle Version 2.7 + (Build: 20140529)
- VPL Version 3.0.1
- For details on how Moodle and VPL were installed, go to this page.
Step-By-Step
- Log in as the instructor for the course on Moodle
- Create a new VPL activity
- 1 file max, set submission period, individual work, Grade of type point, 100 max, set category if necessary, Save and Display
- Execution Options: Run: No, Debug: No, Evaluate: Yes, Evaluate just on submission: No, Automatic Grade: Yes.
- Requested files: randomInts.py
- Create the following Execution files (found under Advanced Settings)
Execution-Files
vpl_evaluate.sh
#! /bin/bash
echo "#! /bin/bash" > vpl_execution
echo "python3.4 customEval.py">> vpl_execution
chmod +x vpl_execution
This will cause VPL to run the python program customEval.py
when the student assignment is evaluated.
customEval.py
- In the execution file's file menu choose new and set the file name to
customEval.py
# customEval.py
# E. Mendelowitz
def comment(s):
'''formats strings to create VPL comments'''
print('Comment :=>> ' + s)
def grade(num):
'''formats a number to create a VPL grade'''
print('Grade :=>> ' + str(num))
try:
import randomInts
except:
comment("unable to import randomInts")
grade(0)
exit()
try:
randomInts.randomInt
except:
comment("randomInts.randomInt isn't defined")
grade(25)
exit()
try:
if(type(randomInts.randomInt()) == int):
comment("great job!")
grade(100)
else:
comment("randomInts.randomInt doesn't return an int as required.")
grade(90)
except:
comment("randomInts.randomInt crashes")
grade(75)
Make customEval.py Available
- Go to Advanced Settings>Files To Keep When Running
- check
customEval.py
Testing
Error-Free Execution
- Go to the VPL Administration block, click on Testing activity, then News and enter the file name
randomInts.py
and following program in the text area:import random def randomInt(): return int(random.random()*10)
- Press save and evaluate
- Verify that you get a grade of 100/100 and a "great job!" comment.
Execution with Student Errors
- Modify the program by removing the int in the return statement i.e.:
import random def randomInt(): return random.random()*10
- Press save and evaluate
- Verify that you get a grade of 90/100 and randomInts.randomInt doesn't return an int as required is in the comments.
- Next modify the program by change the name
randomInt
torandInt
- Press save and evaluate
- Verify that you get a grade of 25/100 and randomInts.randomInt isn't defined. is in the comments.