Repository navigation
Creating Tasks
A task is one exercise: instructions, starter code, optional hints and solution, and the tests that decide when it is solved. You create it with an interactive command:
pyics create_task [--fp path/to/task]Without --fp, the task file is written to the working directory, named after the task. The .pyicstask.json suffix is added if it is missing.
Have these files ready. create_task asks for paths to existing files; it doesn't create them for you.
-
The exercise file: the starter code students get, e.g.
.exercises/dfs.pywith a function stub and a# TODO. At least one is required. It can also be a Jupyter notebook. -
The solution file (optional, recommended): e.g.
.solutions/dfs.py. You need it to checkGeneralTests while you create them, and it is useful as the test information file. - A test information file (optional, recommended): a Python file (or notebook) that defines the values your tests need, such as arguments, expected results and rule lists. See below.
Work out what to check before you start. Choosing Tests helps you pick the right test for each check.
| Key | Does |
|---|---|
| enter | submit an answer |
| ctrl+d | submit a multi-line answer (instructions, hints, expected output) |
| esc | go back to the previous prompt, keeping its answer for you to change |
| ctrl+c | cancel; nothing is written |
| tab | complete a file path |
Invalid answers aren't accepted: the error is shown under the prompt, and you can correct it. Nothing is written until you finish the last prompt.
The task's name identifies it in the course. It must be unique among the tasks of a course.
Shown in the app's header for as long as the task is open. Keep them short and concrete: what to implement, and any rules (e.g. "without recursion"). Longer explanations belong in the exercise file, as comments or docstrings, or in a notebook's markdown cells.
Add as many hints as you like, in order. Students reveal them one at a time with h; revealed hints stay visible until the app is closed. A good sequence goes from a nudge to an almost-solution:
- "Keep the paths still to be explored in a stack:
pop()from the top,appendnew ones." - "Start with the stack
[(start,)]. Take the top path; if it ends at the goal, return it…"
Give the path of each exercise file. Paths are stored relative to the task file. The file's current contents are stored as the starter code.
If an exercise file is a notebook with sections, you are asked which section the task is about.
Optional. Their contents are stored too. Solution files are written to students' machines when the task opens, unless you pack the course with --no_solutions (see How Courses Work).
Choose a kind of test, fill in its parameters, and repeat until you choose Done. A task with several tests is solved once all of them pass (soft tests aside).
For each test, you are first asked: "Reference a file with test information?" If you do, the values that file defines are offered for the test's parameters.
Then each parameter of the test is asked for:
-
Text parameters (
name, aPrintTest'sexpectedoutput, …) are typed as plain text. -
file_path: choose one of the task's exercise files. -
Everything else is a Python expression, e.g.
[("A", "B"), ("B", "C")],("A", "B", "D")or{"concept": "loop", "max": 0}. The variables of the test information file are in scope, and listed under the prompt. - For a
SimpleTest,Raises(...)andMake(...)are in scope as well (see the SimpleTest Reference). - For a
StructureTest, the available concepts are listed under the prompt.
A GeneralTest is run against the solution file right away: you see how many of its tests pass, and can keep it, edit it again, or discard it.
Typing long values into a prompt is error-prone. Instead, write them in a Python file:
# dfs_info.py
graph = [("A", "B", 1), ("A", "C", 1), ("B", "D", 1), ("D", "E", 1), ("E", "G", 1)]
function_name = "depth_first_search"
function_args = [graph, "A", "G"]
expected = ("A", "B", "D", "E", "G")
rules = [{"concept": "recursion", "scope": "depth_first_search", "max": 0,
"message": "Use a stack instead of recursion."}]-
Names that match a parameter are selected automatically. Above,
function_name,function_args,expectedandrulesfill the parameters of the same name. Other values (likegraph) can be used in the expressions you type. -
Functions and classes work too. For a
SpecTest, the expected signature can be a function or class defined in the file. Using your solution file as the test information file is often the quickest way to do this. - The file runs in its own directory, like the tests, so it can read data files and import modules next to it.
- A notebook can be the test information file, e.g. your solution notebook. Its code cells run as they do in tests.
-
Objects of classes the file defines can't be stored in a task, because the file isn't there when the course runs. Use
Make("Graph", edges)instead, which creates the object from the student's class during the test (see SimpleTest Reference: objects as arguments).
pyics edit_task path/to/task.pyicstask.jsonThis goes through the same prompts, prefilled with the task's current values: confirming each one leaves the task as it was. Along the way you can:
- Update a file: if an exercise or solution file on disk differs from the stored version, you see the difference and can choose Update to store the version on disk. Do this after every change to starter code or solutions: the task only knows what it stored.
- Replace or remove files: tests of a replaced file then test the new one.
- Keep, edit or remove tests and hints, one by one, and add new ones.
If you rename the task, the course manifests below the working directory that include it are updated too. --max_depth sets how many directory levels are searched (3 by default).
- Write the solution first, then derive the starter code from it. Every test should pass on the solution.
- One concept per task. Several small tasks give better feedback than one large one.
- Give tests clear names. The name is what students see when a test fails, e.g. "Finds a path from A to G", not "test 1".
-
Use soft tests for style. A
StructureTestwithsoft=Truecan point out a nested loop without blocking progress. -
Turn off tracing sparingly.
traceable=Falsehides a test's arguments from the trace (t), e.g. when they would reveal the solution. Tracing is one of the most useful tools students have.
Next: Choosing Tests, or Creating Courses once your tasks are ready.
PyICs instructor wiki · Generated from the wiki/ directory of the repository: edit the pages there, not here. · Report a problem