|
| 1 | +# All functions starting with "test_" should run and execute `print("OK")` exactly once. |
| 2 | +# This can be checked by running validTest.py. |
| 3 | + |
| 4 | +import sys |
| 5 | +import os |
| 6 | + |
| 7 | +sys.path.append(os.path.dirname(os.path.dirname((__file__)))) |
| 8 | +from testlib import expects |
| 9 | + |
| 10 | +# These are defined so that we can evaluate the test code. |
| 11 | +NONSOURCE = "not a source" |
| 12 | +SOURCE = "source" |
| 13 | + |
| 14 | + |
| 15 | +def is_source(x): |
| 16 | + return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j |
| 17 | + |
| 18 | + |
| 19 | +def SINK(x): |
| 20 | + if is_source(x): |
| 21 | + print("OK") |
| 22 | + else: |
| 23 | + print("Unexpected flow", x) |
| 24 | + |
| 25 | + |
| 26 | +def SINK_F(x): |
| 27 | + if is_source(x): |
| 28 | + print("Unexpected flow", x) |
| 29 | + else: |
| 30 | + print("OK") |
| 31 | + |
| 32 | +# ------------------------------------------------------------------------------ |
| 33 | +# Actual tests |
| 34 | +# ------------------------------------------------------------------------------ |
| 35 | + |
| 36 | +def read_sql(sql): |
| 37 | + SINK(sql) # $ flow="SOURCE, l:+5 -> sql" |
| 38 | + |
| 39 | +def process(func, arg): |
| 40 | + func(arg) |
| 41 | + |
| 42 | +process(func=read_sql, arg=SOURCE) |
| 43 | + |
| 44 | + |
| 45 | +def read_sql_star(sql): |
| 46 | + SINK(sql) # $ MISSING: flow="SOURCE, l:+5 -> sql" |
| 47 | + |
| 48 | +def process_star(func, *args): |
| 49 | + func(*args) |
| 50 | + |
| 51 | +process_star(read_sql_star, SOURCE) |
| 52 | + |
| 53 | + |
| 54 | +def read_sql_dict(sql): |
| 55 | + SINK(sql) # $ flow="SOURCE, l:+5 -> sql" |
| 56 | + |
| 57 | +def process_dict(func, **args): |
| 58 | + func(**args) |
| 59 | + |
| 60 | +process_dict(func=read_sql_dict, sql=SOURCE) |
| 61 | + |
| 62 | + |
| 63 | +# TODO: |
| 64 | +# Consider adding tests for |
| 65 | +# threading.Thread, multiprocess.Process, |
| 66 | +# concurrent.futures.ThreadPoolExecutor, |
| 67 | +# and concurrent.futures.ProcessPoolExecutor. |
0 commit comments