Skip to content

Commit e83c02a

Browse files
authored
Merge pull request #203 from datacamp/doc-update-squash
Squashed commit of the following:
2 parents 799aa79 + 35abd93 commit e83c02a

4 files changed

Lines changed: 77 additions & 5 deletions

File tree

docs/source/Home.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ To robustly test the equality of objects, and results of evaluations, it has to
4141

4242
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.
4343

44-
For more full examples of SCTs for Python exercises on DataCamp, check out the [source files of the introduction to Python course](http://www.github.com/datacamp/courses-intro-to-python). In the chapter files there, you can can see the SCTs that have been written for several exercises.
45-
46-
To test your understanding of writing SCTs for Python exercises on the DataCamp platform, you can take the course [Writing SCTs with pythonwhat](https://www.datacamp.com/courses/writing-scts-with-pythonwhat) course.
44+
For more full examples of SCTs for Python exercises on DataCamp, check out the [source files of the pythonwhat tutorial course](http://www.github.com/datacamp/courses-pythonwhat-tutorial). In the chapter files there, you can can see the SCTs that have been written for several exercises. Another useful course is [introduction to Python](http://www.github.com/datacamp/courses-intro-to-python).
4745

4846
After reading through this documentation, we hope writing SCTs for Python exercises on DataCamp becomes a painless experience. If this is not the case and you think improvements to `pythonwhat` and this documentation are possible, [please let us know](mailto:content-engineering@datacamp.com)!

docs/source/part_checks.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,52 @@ followed by its iterator.
209209
.multi(check_body().has_equal_value()) \
210210
.check_iter().has_equal_value()
211211
212+
has_context
213+
~~~~~~~~~~~~~
214+
215+
.. autofunction:: pythonwhat.check_has_context.has_context
216+
217+
Tests whether context variables defined by the student match the solution, for a selected block of code.
218+
A context variable is one that is defined in a looping or block statement.
219+
For example, ``ii`` in the code below.
220+
221+
.. code::
222+
223+
[ii + 1 for ii in range(3)]
224+
225+
By default, the test fails if the submission code does not have the same number of context variables.
226+
This is illustrated below.
227+
228+
**Solution Code**
229+
230+
.. code::
231+
232+
# ii and ltr are context variables
233+
for ii, ltr in enumerate(['a']): pass
234+
235+
**SCT**
236+
237+
.. code::
238+
239+
Ex().check_for_loop(0).check_body().has_context()
240+
241+
**Passing Submission**
242+
243+
.. code::
244+
245+
# still 2 variables, just different names
246+
for jj, Ltr in enumerate(['a']): pass
247+
248+
**Failing Submission**
249+
250+
.. code::
251+
252+
# only 1 variable
253+
for ii in enumerate(['a']): pass
254+
255+
.. note::
256+
257+
that if you use ``has_context(exact_names = True)``, then the submission must use the same names for the context variables, which would cause the passing submission above to fail.
212258

213259
set_context
214260
~~~~~~~~~~~~~

docs/source/quickstart_guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ The SCT uses three `pythonwhat` chains to test the correctness of the student's
4747
In all the test statements above, feedback messages will be automatically generated when something goes wrong. However, it is possible to manually set these feedback messages. For example, in the code below,
4848

4949
```python
50-
Ex().check_object(undefined_msg="`x` is undefined!") \
50+
Ex().check_object(missing_msg="`x` is undefined!") \
5151
.has_equal_value(incorrect_msg="wrong value for `x`")
5252
```
5353

5454
the automatic messages for when `x` is undefined or incorrect are replaced with manual feedback. Now, if students submit `x = 4` instead of `x = 5`, they will see the message, "wrong value for `x`". Finally, notice that you can use Markdown syntax inside the strings here.
5555

56-
The same holds for `test_output_contains()`: you can use the `no_output_msg` argument to specify a custom message. For more information on all the different arguments you can set in the different `pythonwhat` functions, have a look at the articles in this wiki, describing them in detail.
56+
The same holds for `has_equal_value()`: you can use the `incorrect_msg` argument to specify a custom message. For more information on all the different arguments you can set in the different `pythonwhat` functions, have a look at the articles in this wiki, describing them in detail.
5757

5858
Next Steps
5959
----------

docs/source/simple_tests/test_object.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,31 @@ Of course primitive classes like `str`, `int`, `list`, `dict`, ... can be tested
9797
As explained in the [Processes article](../expression_tests.md), objects are extracted from their respected processes by 'dilling' and 'undilling' them. However, you can manually set a 'converter' with the `set_converter()` function. This will override the default dilling and undilling behavior, and enables you to make simplified representations of custom objects, testing only exactly what you want to test.
9898

9999
**NOTE**: Behind the scenes, `pythonwhat` has to fetch the value of objects from sub-processes. The required 'dilling' and 'undilling' can cause issues for exotic objects. For more information on this and possible errors that can occur, read the [Processes article](../expression_tests.md).
100+
101+
check_object
102+
------------
103+
104+
```eval_rst
105+
.. autofunction:: pythonwhat.check_object.check_object
106+
```
107+
108+
is_instance
109+
-----------
110+
111+
```eval_rst
112+
.. autofunction:: pythonwhat.check_object.is_instance
113+
```
114+
115+
has_key
116+
-----------
117+
118+
```eval_rst
119+
.. autofunction:: pythonwhat.check_object.has_key
120+
```
121+
122+
has_equal_key
123+
---------------
124+
125+
```eval_rst
126+
.. autofunction:: pythonwhat.check_object.has_equal_key
127+
```

0 commit comments

Comments
 (0)