File tree 2 files changed +18
-6
lines changed
2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 1
1
import ast
2
+ import re
3
+
2
4
from pythonwhat .utils_ast import wrap_in_module
3
5
from collections .abc import Sequence , Mapping
4
6
from collections import OrderedDict
@@ -326,13 +328,15 @@ def visit_Dict(self, node):
326
328
def visit_Call (self , node ):
327
329
if self .call_lookup_active :
328
330
self .visit (node .func )
331
+ self .gen_name += "()"
329
332
else :
330
333
self .call_lookup_active = True
331
334
self .visit (
332
335
node .func
333
336
) # Need to visit func to start recording the current function name.
334
337
335
338
if self .gen_name :
339
+ self .gen_name = re .sub (r"(?:\(\))+(.)" , "\\ 1" , self .gen_name )
336
340
if self .gen_name not in self .out :
337
341
self .out [self .gen_name ] = []
338
342
Original file line number Diff line number Diff line change @@ -522,18 +522,26 @@ def test_function_call_in_comparison(code):
522
522
assert res ["correct" ]
523
523
524
524
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 ):
529
534
530
535
code = """
536
+ import numpy as np
537
+ np.array([])
538
+
531
539
def hof(arg1):
532
540
def inner(arg2):
533
541
return arg1, arg2
534
-
542
+
535
543
return inner
536
-
544
+
537
545
hof(1)(2)
538
546
"""
539
547
You can’t perform that action at this time.
0 commit comments