All notable changes to the pythonwhat project will be documented in this file. This project adheres to Semantic Versioning.
- Support Python version 3.9
- Update dependencies to up-to-date versions
- Update behaviour of has_expr() default feedback message. If the student's evaluation is too long, it is now shortened and an ellipsis is added.
- Fix string formatting in has_expr(). Strings will now have quotes in error messages. Leading and trailing whitespace is no longer removed.
- Update to protowhat v2 (embedding xwhats,
prepare_validation
helper, for checking bash history, autodebug)
- Add support for replacing the placeholder
__focus__
with the focused code in theexpr_code
argument - Expose bash history functionality from protowhat
- Use path info in
run
- Improve checking exceptions
- Improve checking file content
- Speed improvements
- Expose
_debug
function - Update protowhat
state
is now the first argument to SCT functions (instead of a keyword argument)- functionality is shared with protowhat:
Reporter
,Chain
,F
and logic SCTs are reusedState
andFeedback
inheritDispatcher
handles parsing (decoupled fromState
)Test
moved
- Local setup with
setup_state
now works correctly (e.g. when the PEC contains a list comprehension)
- Add optional
force_diagnose
parameter totest_exercise
to force passing thediagnose
tests incheck_correct
.
Documentation has been improved significantly (hopefully):
- Every 'compound statement check' has an example with explanation in the reference now.
- Common usecases have additional examples
- Checking compound statements article has been simplified, limits to context now.
- More helpful message in case check_object or has_printout not called on root state
- More helpful message in case the zoomed in on object is not an AST
- Explain has_equal_value vs has_equal_ast
- Get rid of some articles in favor of more fleshed out reference documentation
- CI is now using the
datacamp
account on PyPi
- Tuples of Numpy arrays can now be checked properly.
- Code in
ObjectAssignmentParser
that is not used.
- Function
has_no_error()
to check earlier on whether the student did not generate any errors.
- Messaging between V1 and V2 is entirely consistent now.
- No need for
__JINJA__
prefix in custom messages specified in SCTs anymore.
- No more support for
expand_message
argument in old 'node checking functions' such astest_for_loop()
.
- Ability to check class definitions with
check_class_def()
(andcheck_bases()
). Tested and documented.
- The
check_object()
only on root check is only done ifPYTHONWHAT_V2_ONLY
environment variable is set.
- More checks that guard against commonly made mistakes (some in v2 only, others not)
- Function documentation (with examples) for
multi()
,check_or()
,check_correct()
andcheck_not()
- If an SCT is incorrectly coded, it will generate more easily understandable errors so the author can easily fix the issue.
- If an SCT correctly runs but does not make a lot of sense, easily understanble errors will be thrown so the author can make improvements.
check_object()
does not check whether the targeted object is specified in the solution process if student and solution process are identical (as is the case in theSingleProcessExercise
).has_expr()
, the function used byhas_equal_value()
,has_equal_output()
andhas_equal_error()
can take anoverride
argument, that causes the solution expression not to run and use the value specified inoverride
instead. For more information, have a look at the 'SingleProcessExercise' article on the documentation.
call()
can no longer be used. UseEx().check_function_def().check_call().has_equal_x()
instead.has_key()
andhas_equal_key()
can no longer be used. UseEx().check_object().check_keys().has_equal_x()
instead.
- Fixed:
check_keys()
allows for more exotic ways of indexing as well, even though it's needed very rarely
- You can now use
Ex().check_object('df').check_keys('a').has_equal_value()
to test DataFrame columns and dictionary elements. - You can now use
Ex().check_function_def('my_fun').check_call('f(1,3,4)').has_equal_x()
to check the value, output or error that calling a function generates. Soon, thecall()
syntax, although still supported, will be removed. - More manual signatures have been added for functions in the
numpy.random
submodule, so SCT authors have to specifysignature=False
less and there is more robust argument matching.
- Update docs to promote new functions introduced above.
- Messaging has improved: if there is crazy nesting, only the last two 'expand messages' are included. That way, you don't get feedback messages like "Check the first for loop. Check the body. Check the first for loop. Check the body. Check the function. ...".
- The function parser (used by
check_function()
) now also discovers function calls in lists and dictionaries. has_import()
is now more flexible by default, not requiring students to use the same alias.
- Nothing for now, but the following functions will be discontinued in the future:
test_function_definition()
test_with()
test_object_after_expression()
has_key()
andhas_equal_key()
call()
- Add
check_df()
to the API again. Turns out quite a lot of live exercises use it by now!
- Fix issue in
test_data_frame()
if message is not specified. - Improve messaging in
has_key()
andhas_equal_key()
.
- If
PYTHONWHAT_V2_ONLY = '1'
is set as an environment variable, you can no longer use any of thetest_
functions.- Instead of
Ex().test_or(...)
, you have to useEx().check_or(...)
. - Instead of
Ex().test_correct(...)
, you have to useEx().check_correct(...)
. - Instead of
test_mc()
, you have to useEx().has_chosen()
. Docs have been updated accordingly.
- Instead of
- The package structure has been updated significantly
- Distributing nearly all new functions over
check_funcs.py
,has_funcs.py
andcheck_logic.py
. - Grouping all old functions to test compound statements.
- Moving around and rewriting tests to use
pytest
more and be more readable overall.
- Distributing nearly all new functions over
test_not()
's functionality was tested more and bugs that appeared were fixed. It was nowhere used, so it was removed from the API in favor forcheck_not()
, which has the same functionality.
extend()
can not be used anymore.check_df()
can not be used anymore. UPDATE: added again in 2.14.2.
- The documentation pages have undergone significant maintenance.
- There is now a tutorial that gradually exposes you to
pythonwhat
. - The articles have been brushed up to include more examples and more involved examples.
- The articles have been split up into basic and advanced articles to make it clear what is most important.
test_correct()
as a tool to add robustness is now featured more prominently
- There is now a tutorial that gradually exposes you to
set_context()
can now be used to specify arguments either by position, either by name, making it a great tool for flexible checking.- For
has_equal_output()
, the message that was generated didn't always make sense. That is fixed now. - Highlighting was removed in an SCT chain when
set_context()
was used. This is no longer the case. - Small fixes for bugs that should not have impacted students in the first place.
Small changes to follow up on 2.13.0
- Get rid of
typestr
argument incheck_function()
as it's used nowhere - Change the internals of has_printout, to be more allowing for different ways of doing things
- Improve variable names for readability and understanding
test_function()
andtest_function_v2()
now usecheck_function()
andcheck_args()
behind the scenes. That way, when we make improvements to the messaging logic, all SCTs that use any of these three functions will benefit from them. In the future, we will deprecatetest_function()
andtest_function_v2()
as they are not explicit enough about what is being tested and how.test_function('print')
andcheck_function('print')
useEx().has_printout()
behind the scenes when appropriate. This makes the SCTs much more accepting for different ways of doing printouts.- You can now use
check_finalbody()
to check thefinally
part of atry-except
block. - Drastically improve
has_equal_ast()
messaging. - If you manually specify
code
argument inhas_equal_ast()
, you have to specify theincorrect_msg
because the machine-generated one will be meaningless (for now).
-
BIG ONE: You can now test method calls that have subscripts in them. This is particularly useful for
pandas
, where you for example want to test a calldf[df.b == 'x'].a.sum()
. You can now do that with:# Check whether the function was called: Ex().check_function('df.a.sum', signature=False) # Check whether the function was called and generated the correct result: Ex().check_function('df.a.sum', signature=False).has_equal_value()
This update means that you should no longer need to use two
has_equal_ast()
's inside atest_correct()
to allow for two different ways of doing a pandas operation. If you do, please create an issue! -
Some fixes to
has_printout()
that caused it not to work in all cases. -
check_function()
now refers to a function call in the way that the student defined it. When a student usesimport pandas as pd
and then has to call a functionpd.Series()
,check_function()
will refer to the function withpd.Series()
and notpandas.Series()
.
test_dict_comp()
,test_try_except()
,test_generator_exp()
andtest_lambda_function()
have been removed from the API. The couple of SCTs on DataCamp that used these functions have been converted to use the moderncheck_
functions.
-
If manually specifying
incorrect_msg
in has_equal_x: do not prepend previously generated messages. You no longer have to setexpand_msg = ""
. -
Overall, improvement of automaticlaly generated messages:
- Bite-size messages that are pasted together
- More meaningful defaults that help (see
tests/test_messaging.py
) - Get rid of default-generated messages scattered all over the place
- Better description of arguments
- Better description of calls
- Get rid of
has_key()
andhas_equal_key()
docs, as they will be phased out - Improved handling of getting results, output and values from process
- Simplify old
test_expression_x()
functions and group in one file
-
You can now robustly test printouts with
Ex().has_printout(index = x)
. This function will look for thex
'thprint()
call in the solution code, rerun that call while capturing the output, and then look for that output in the output that was generated by the student's code submission.Ex().has_printout(index=0)
This approach is far easier and more robust than using
Ex().check_function().check_args().has_equal_value()
.
- Improvement in messages that are generated by default when checking
*args
and**kwargs
arguments in function calls.
-
You can now use
test_or()
insidetest_correct()
:Ex().test_correct( check_object(...) test_or( check_function(...), has_equal_ast(...) ) )
- Whether or not something should be highlighted can be specified through the state now
- You can use
<other_fun>.disable_highlighting().<anohter_fun>
anywhere in the SCT chain to disable highlighting.
- There are no more
highlight
arguments in any pythonwhat SCT functions. Feedback
now takes a state from which it reads which part should be highlighting and whether it should be highlighted.- Use of
StubState
to trick the system somewhat, should be refactored at some point, but works fine. test_function_v2()
andtest_function()
only higlight if theindex = 1
, i.e. when the first call of a certain function is being checked. Added tests (and updated other tests) accordingly.
- In
check_args()
, you can now use['args', 0]
and['kwargs', 'a']
to look for matched positional star args, and matched named star args. The docs have been updated accordingly: https://pythonwhat.readthedocs.io/en/stable/articles/checking_function_calls.html
- The equality checks for lists, dicts, numpy arrays, pandas dataframes and pandas series have been made faster, without compromising backwards compatibility.
- There was a nasty bug with signature binding when using
check_function()
for the same function when this function took only positional args. This would alleviate the need of anysignature=False
usage, once and for all!
- Reference documentation now contains examples for
set_context()
andset_env()
. - A
tests/test_debug.py
file has been added to easily test questions that CDs might have.
- There was a bug in the feedback message generation for errors. It now just refers to the console.
- All new
has_()
functions are now properly documented, so there should be no reason for you to use atest_
function other thantest_or
andtest_correct
. If you do find yourself using it (because you don't know the alternative), ping me and we'll talk! - Added documentation on the
check_function_def()
related functions. index = 0
is now a default for functions likecheck_if_else()
,check_function()
etc.- Like there is
set_context
, there is nowset_env
to set environment variables before using something likehas_equal_value()
. Theseset_
functions serve as alternatives for theextra_env
andcontext_vals
arguments that appear in many functions and that I plan to discontinue at some point. - Added a
test_
tocheck_
article, that explains how you can go from old-style to new-style SCTs. Feel free to contribute!!
- If you experiment locally, you will now see the feedback message that the SCT chain would generate (this is explained in the README on GitHub):
from pythonwhat.local import setup_state
s = setup_state(sol_code="x = 4", stu_code="x = 5")
s.check_object('x').has_equal_value()
# <traceback omitted>
# pythonwhat.Test.TestFail: Check the variable `x`. Unexpected expression value: expected `4`, got `5`.
- The glossary is featured more prominently in the docs, as it is a good resource to see how everything fits together.
- There is no support for
keep_objs_in_env
, as nobody is using it.