File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 11import ast
2+ import re
3+
24from pythonwhat .utils_ast import wrap_in_module
35from collections .abc import Sequence , Mapping
46from collections import OrderedDict
@@ -326,13 +328,15 @@ def visit_Dict(self, node):
326328 def visit_Call (self , node ):
327329 if self .call_lookup_active :
328330 self .visit (node .func )
331+ self .gen_name += "()"
329332 else :
330333 self .call_lookup_active = True
331334 self .visit (
332335 node .func
333336 ) # Need to visit func to start recording the current function name.
334337
335338 if self .gen_name :
339+ self .gen_name = re .sub (r"(?:\(\))+(.)" , "\\ 1" , self .gen_name )
336340 if self .gen_name not in self .out :
337341 self .out [self .gen_name ] = []
338342
Original file line number Diff line number Diff line change @@ -522,18 +522,26 @@ def test_function_call_in_comparison(code):
522522 assert res ["correct" ]
523523
524524
525- def test_ho_function ():
526- # TODO: FunctionParser.visit_Call should append something to name to discern HOF calls
527- # e.g. () if node.func is Func (this should only affect limited exercises)
528- sct = "Ex().check_function('hof').check_args(0).has_equal_value(override=2)"
525+ @pytest .mark .parametrize (
526+ "sct" ,
527+ [
528+ "Ex().check_function('numpy.array')" ,
529+ "Ex().check_function('hof').check_args(0).has_equal_value(override=1)" ,
530+ "Ex().check_function('hof()').check_args(0).has_equal_value(override=2)" ,
531+ ],
532+ )
533+ def test_ho_function (sct ):
529534
530535 code = """
536+ import numpy as np
537+ np.array([])
538+
531539def hof(arg1):
532540 def inner(arg2):
533541 return arg1, arg2
534-
542+
535543 return inner
536-
544+
537545hof(1)(2)
538546 """
539547
You can’t perform that action at this time.
0 commit comments