Accessing submission metadata
You can access submission metadata from within AutoTest, for example to automatically subtract points for late submissions.
You may want to access some submission metadata in your tests, for example to automatically subtract points when a student submitted after the deadline, or you maybe need to generate input for the tests but want it to be different for each student. To enable this you first need to check the "Submission information" checkbox in the "Advanced options" list at the bottom of the AutoTest category editing window.
When you have done this, all steps in the current category will have an extra environment variable named
$CG_INFOdefined. This variable contains a JSON object with the following keys:
deadlineThe deadline of this assignment.
lock_dateThe lock date of this assignment.
submitted_atThe date and time the student submitted their work.
result_idAn identifier unique to this AutoTest result. This value changes every time the AutoTest is run, even if it is run multiple times for the same submission of the same student.
student_idAn identifier unique to the student for which the AutoTest is run. This value stays constant between runs of different submissions by the same student.
These variables are also available using the
cg_at_utilsmodule in Python. Import
from cg_at_utils import CG_INFOin your Python scripts and use them in your AutoTest category.
You want to generate a list of 100 random numbers as inputs to the tests.
- 1.Create a Python script named
generate.pyto generate the inputs. It uses the
$CG_INFOto seed the random number generator. This has the consequence that the generated list of numbers stays the same between submissions of the same student. Upload the script created in step 1 as a fixture.import osimport randomfrom cg_at_utils import CG_INFOrandom.seed(CG_INFO.student_id)for _ in range(100):print(random.random())
- 2.Create a run program step and pipe the generated numbers to the student's code with
python3.7 generate.py | my_test_script.