@@ -212,6 +212,7 @@ def check_function_multiple_times():
212
212
# Methods ---------------------------------------------------------------------
213
213
214
214
215
+ # Manually create a signature for functions that need self passed
215
216
def test_method_1 ():
216
217
code = "df.groupby('b').sum()"
217
218
s = setup_state (
@@ -221,26 +222,29 @@ def test_method_1():
221
222
)
222
223
helper .passes (s .check_function ("df.groupby" ).check_args (0 ).has_equal_value ())
223
224
helper .passes (s .check_function ("df.groupby.sum" , signature = False ))
224
- from pythonwhat .signatures import sig_from_obj
225
- import pandas as pd
226
225
226
+ import inspect
227
+ from inspect import Parameter as param
228
+ manual_sig = inspect .Signature ([
229
+ param ("x" , param .POSITIONAL_OR_KEYWORD , default = None ),
230
+ param ("axis" , param .POSITIONAL_OR_KEYWORD , default = None )
231
+ ])
227
232
helper .passes (
228
- s .check_function ("df.groupby.sum" , signature = sig_from_obj ( pd . Series . sum ) )
233
+ s .check_function ("df.groupby.sum" , signature = manual_sig )
229
234
)
230
235
231
236
232
237
def test_method_2 ():
233
- code = "df[df.b == 'x'].a.sum( )"
238
+ code = "print('a' )"
234
239
s = setup_state (
235
240
sol_code = code ,
236
241
stu_code = code ,
237
- pec = "import pandas as pd; df = pd.DataFrame({'a': [1, 2, 3], 'b': ['x', 'x', 'y']}) " ,
242
+ pec = "" ,
238
243
)
239
- helper .passes (s .check_function ("df.a.sum" , signature = False ))
240
- from pythonwhat .signatures import sig_from_obj
241
- import pandas as pd
244
+ helper .passes (s .check_function ("print" , signature = False ))
242
245
243
- helper .passes (s .check_function ("df.a.sum" , signature = sig_from_obj (pd .Series .sum )))
246
+ from pythonwhat .signatures import sig_from_obj
247
+ helper .passes (s .check_function ("print" , signature = sig_from_obj ('print' )))
244
248
245
249
246
250
from pythonwhat .signatures import sig_from_params , param
0 commit comments