11from protowhat .sct_syntax import EagerChain , ExGen , LazyChainStart , state_dec_gen
22from pythonwhat .checks .check_wrappers import scts
33from pythonwhat .State import State
4- from pythonwhat .probe import Node , Probe , TEST_NAMES
5- from pythonwhat .utils import include_v1
6- from pythonwhat import test_funcs
7- from functools import wraps
84
95# TODO: could define scts for check_wrappers at the module level
106sct_dict = scts .copy ()
117
12-
13- def multi_dec (f ):
14- """Decorator for multi to remove nodes for original test functions from root node"""
15-
16- @wraps (f )
17- def wrapper (* args , ** kwargs ):
18- args = (
19- args [0 ] if len (args ) == 1 and isinstance (args [0 ], (list , tuple )) else args
20- )
21- for arg in args :
22- if isinstance (arg , Node ) and arg .parent .name is "root" :
23- arg .parent .remove_child (arg )
24- arg .update_child_calls ()
25- return f (* args , ** kwargs )
26-
27- return wrapper
28-
29-
308state_dec = state_dec_gen (sct_dict )
319
3210# todo: __all__?
@@ -45,22 +23,5 @@ def get_chains():
4523 }
4624
4725
48- if include_v1 ():
49- # Prepare SCTs that may be chained attributes ----------------------
50- # decorate functions that may try to run test_* function nodes as subtests
51- # so they remove those nodes from the tree
52- for k in ["multi" , "with_context" ]:
53- sct_dict [k ] = multi_dec (sct_dict [k ])
54-
55- # allow test_* functions as chained attributes
56- for k in TEST_NAMES :
57- sct_dict [k ] = Probe (tree = None , f = getattr (test_funcs , k ), eval_on_call = True )
58-
59- # original logical test_* functions behave like multi
60- # this is necessary to allow them to take check_* funcs as args
61- # since probe behavior will try to call all SCTs passed (assuming they're also probes)
62- for k in ["test_or" , "test_correct" ]:
63- sct_dict [k ] = multi_dec (getattr (test_funcs , k ))
64-
6526# Prepare check_funcs to be used alone (e.g. test = check_with().check_body())
6627v2_check_functions = {k : state_dec (v ) for k , v in scts .items ()}
0 commit comments