File: fun_call_limit.py

package info (click to toggle)
micropython 1.26.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,196 kB
  • sloc: ansic: 324,551; python: 63,215; xml: 4,241; makefile: 3,618; sh: 1,586; javascript: 754; asm: 723; cpp: 83; exp: 11; pascal: 6
file content (36 lines) | stat: -rw-r--r-- 930 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Test the limit of the number of arguments to a function call.
# This currently tests the case of *args after many positional args.


def f(*args):
    return len(args)


def test(n):
    pos_args = ",".join(str(i) for i in range(n))
    s = "f({}, *(100, 101), 102, 103)".format(pos_args)
    try:
        return eval(s)
    except SyntaxError:
        return "SyntaxError"


# If the port has at least 32-bits then this test should pass.
print(test(29))

# This test should fail on all ports (overflows a small int).
print(test(70))

# Check that there is a correct transition to the limit of too many args before *args.
reached_limit = False
for i in range(30, 70):
    result = test(i)
    if reached_limit:
        if result != "SyntaxError":
            print("FAIL")
    else:
        if result == "SyntaxError":
            reached_limit = True
        else:
            if result != i + 4:
                print("FAIL")