Skip to content

Commit ead450d

Browse files
committed
doc update
1 parent bc6228d commit ead450d

5 files changed

Lines changed: 52 additions & 8 deletions

File tree

docs/source/Home.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ Overview
3434

3535
To get started, make sure to check out the [Quickstart Guide](quickstart_guide.md).
3636

37-
To robustly test the equality of objects, and results of evaluations, it has to fetch the information from the respective processes, i.e. the student and solution processes. By default, this is done through a process of 'dilling' and 'undilling', but it's also possible to define your own converters to customize the way objects and results are compared. For more background on this, check out the [Processes article](expression_tests.md). For some more background on the principle of 'sub-SCTs', i.e. sets of tests to be called on a particular part or a particular state of a student's submission, have a look at the [Part Checks article](part_checks.rst).
37+
```eval_rst
38+
39+
To robustly test the equality of objects, and results of evaluations, it has to fetch the information from the respective processes, i.e. the student and solution processes. By default, this is done through a process of 'dilling' and 'undilling', but it's also possible to define your own converters to customize the way objects and results are compared. For more background on this, check out :ref:`managing-processes`. For some more background on the principle of 'sub-SCTs', i.e. sets of tests to be called on a particular part or a particular state of a student's submission, have a look at the :doc:`Part Checks article <part_checks>`.
40+
```
3841

3942
The remainder of the wiki goes over every test function that `pythonwhat` features, explaining all arguments and covering different use cases. They will give you an idea of how, why and when to use them.
4043

docs/source/expression_tests.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ For example, the SCT below shows how to run some `pre_code`, and then evaluate t
320320
Ex().check_function_def('my_fun').call("f(1, 2)", test="output", pre_code="x = 1")
321321
```
322322

323+
```eval_rst
324+
.. _managing-processes:
325+
```
326+
323327

324328
Managing Processes
325329
-----------------

docs/source/part_checks.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ Helper Functions
161161
multi
162162
~~~~~~~
163163

164-
Runs multiple subtests.
165-
164+
.. autofunction:: pythonwhat.check_funcs.multi
166165

167166
Comma separated arguments
168167
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -214,6 +213,8 @@ followed by its iterator.
214213
set_context
215214
~~~~~~~~~~~~~
216215

216+
.. autofunction:: pythonwhat.check_funcs.set_context
217+
217218
Sets the value of a temporary variable, such as ``ii`` in the list comprehension below.
218219

219220
.. code::
@@ -261,6 +262,8 @@ When you try to set context values that don't match any target variables in the
261262
with_context
262263
~~~~~~~~~~~~~~
263264

265+
.. autofunction:: pythonwhat.check_funcs.with_context
266+
264267
Runs subtests after setting the context for a ``with`` statement.
265268

266269
This function takes arguments in the same form as ``multi``.
@@ -291,6 +294,8 @@ and replacing step (3) with any sub-tests given as arguments.
291294
fail
292295
~~~~~~
293296

297+
.. autofunction:: pythonwhat.check_funcs.fail
298+
294299
Fails. This function takes a single argument, ``msg``, that is the feedback given to the student.
295300
Note that this would be a terrible idea for grading submissions, but may be useful while writing SCTs.
296301
For example, failing a test will highlight the code as if the previous test/check had failed.
@@ -315,14 +320,14 @@ Check Functions
315320
(e.g. ``Ex().check_list_comp(0).check_ifs(0)``)
316321
* **missing_msg**: optional feedback message if node or part doesn't exist.
317322

318-
319323
Note that code in all caps indicates the name of a piece of code that may be inspected using, ``check_{part}``,
320324
where ``{part}`` is replaced by the name in caps (e.g. ``check_if_else(0).check_test()``).
321325
Target variables are those that may be set using ``set_context``.
322326
These variables may only be set in places where python would set them.
323327
For example, this means that a list comprehension's ITER part has no target variables,
324328
but its BODY does.
325329

330+
326331
+------------------------+------------------------------------------------------+-------------------+
327332
| check | parts | target variables |
328333
+========================+======================================================+===================+
@@ -380,9 +385,9 @@ but its BODY does.
380385
| | FINALBODY | |
381386
| | | |
382387
+------------------------+------------------------------------------------------+-------------------+
383-
|check_with(0) | .. code:: python | `f`` |
388+
|check_with(0) | .. code:: python | ``f`` |
384389
| | | |
385-
| | with CONTEXT_TEST as f: | |
390+
| | with CONTEXT[0] as f1, CONTEXT[1] as f2: | |
386391
| | BODY | |
387392
| | | |
388393
+------------------------+------------------------------------------------------+-------------------+

docs/source/simple_tests/has_equal_ast.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ has_equal_ast
22
--------------
33

44
```eval_rst
5-
.. automodule:: pythonwhat.check_funcs.has_equal_ast
6-
:members:
5+
.. autofunction:: pythonwhat.check_funcs.has_equal_ast
76
```
87

98
An abstract syntax tree (AST) is a way of representing the high-level structure of python code.

pythonwhat/check_funcs.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ def call(args,
402402
from pythonwhat import utils
403403

404404
def has_equal_ast(incorrect_msg="FMT: Your code does not seem to match the solution.", state=None):
405+
"""Test whether abstract syntax trees match between the student and solution code.
406+
407+
Args:
408+
incorrect_msg: message displayed when ASTs mismatch.
409+
"""
405410
rep = Reporter.active_reporter
406411

407412
stu_rep = ast.dump(state.student_tree)
@@ -424,6 +429,34 @@ def has_expr(incorrect_msg="FMT:Unexpected expression {test}: expected `{sol_eva
424429
highlight=None,
425430
state=None,
426431
test=None):
432+
"""Run student and solution code, compare returned value, printed output, or errors.
433+
434+
Args:
435+
incorrect_msg (str): feedback message if the output of the expression in the solution doesn't match
436+
the one of the student. This feedback message will be expanded if it is used in the context of
437+
another test function, like test_if_else.
438+
error_msg (str): feedback message if there was an error when running the student code.
439+
Note that when testing for an error, this message is displayed when none is raised.
440+
undefined_msg (str): feedback message if the name argument is defined, but a variable
441+
with that name doesn't exist after running the student code.
442+
extra_env (dict): set variables to the extra environment. They will update the student
443+
and solution environment in the active state before the student/solution code in the active
444+
state is ran. This argument should contain a dictionary with the keys the names of
445+
the variables you want to set, and the values are the values of these variables.
446+
context_vals (list): set variables which are bound in a for loop to certain values. This argument is
447+
only useful if you use the function in a test_for_loop. It contains a list with the values
448+
of the bound variables.
449+
expr_code (str): if this variable is not None, the expression in the student/solution code will not
450+
be ran. Instead, the given piece of code will be ran in the student as well as the solution environment
451+
and the result will be compared.
452+
pre_code (str): the code in string form that should be executed before the expression is executed.
453+
This is the ideal place to set a random seed, for example.
454+
keep_obj_in_env (list()): a list of variable names that should be hold in the copied environment where
455+
the expression is evaluated. All primitive types are copied automatically, other objects have to
456+
be passed explicitely.
457+
name (str): the name of a variable, or expression, whose value will be tested after running the
458+
student and solution code. This could be thought of as post code.
459+
"""
427460
rep = Reporter.active_reporter
428461

429462
# run function to highlight a block of code

0 commit comments

Comments
 (0)