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_INFO defined. This variable contains a JSON object with the following keys:
  • deadline The deadline of this assignment. (general "Everyone" Schedule settings)
  • lock_date The lock date of this assignment. (general "Everyone" Schedule settings)
  • submitted_at The date and time the student submitted their work.
  • result_id An 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_id An 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_utils module in Python. Import CG_INFO using from cg_at_utils import CG_INFO in your Python scripts and use them in your AutoTest category.

Example: subtracting points for late submissions

Example: generating random inputs

You want to generate a list of 100 random numbers as inputs to the tests.
  1. 1.
    Create a Python script named to generate the inputs. It uses the student_id key of $CG_INFO to 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 os
    import random
    from cg_at_utils import CG_INFO
    for _ in range(100):
  2. 2.
    Create a run program step and pipe the generated numbers to the student's code with python3.7 | my_test_script.