|
4 | 4 | # |
5 | 5 | # Functions whose name ends with "_with_local_flow" will also be tested for local flow. |
6 | 6 |
|
7 | | -# Uncomment these to test the test code |
8 | | -# SOURCE = 42 |
9 | | -# def SINK(x): |
10 | | -# return 42 |
| 7 | +# These are included so that we can easily evaluate the test code |
| 8 | +SOURCE = "source" |
| 9 | +def SINK(x): |
| 10 | + print(x) |
11 | 11 |
|
12 | 12 | def test_tuple_with_local_flow(): |
13 | 13 | x = (3, SOURCE) |
14 | 14 | y = x[1] |
15 | 15 | SINK(y) |
16 | 16 |
|
| 17 | +# List taken from https://docs.python.org/3/reference/expressions.html |
| 18 | +# 6.2.1. Identifiers (Names) |
| 19 | +def test_names(): |
| 20 | + x = SOURCE |
| 21 | + SINK(x) |
| 22 | + |
| 23 | +# 6.2.2. Literals |
| 24 | +def test_string_literal(): |
| 25 | + x = "source" |
| 26 | + SINK(x) |
| 27 | + |
| 28 | +def test_bytes_literal(): |
| 29 | + x = b"source" |
| 30 | + SINK(x) |
| 31 | + |
| 32 | +def test_integer_literal(): |
| 33 | + x = 42 |
| 34 | + SINK(x) |
| 35 | + |
| 36 | +def test_floatnumber_literal(): |
| 37 | + x = 42.0 |
| 38 | + SINK(x) |
| 39 | + |
| 40 | +def test_imagnumber_literal(): |
| 41 | + x = 42j |
| 42 | + SINK(x) |
| 43 | + |
| 44 | +# 6.2.3. Parenthesized forms |
| 45 | +def test_parenthesized_form(): |
| 46 | + x = (SOURCE) |
| 47 | + SINK(x) |
| 48 | + |
| 49 | +# 6.2.5. List displays |
| 50 | +def test_list_display(): |
| 51 | + x = [SOURCE] |
| 52 | + SINK(x[0]) |
| 53 | + |
| 54 | +def test_list_comprehension(): |
| 55 | + x = [SOURCE for y in [3]] |
| 56 | + SINK(x[0]) |
| 57 | + |
| 58 | +def test_nested_list_display(): |
| 59 | + x = [* [SOURCE]] |
| 60 | + SINK(x[0]) |
| 61 | + |
| 62 | +# 6.2.6. Set displays |
| 63 | +def test_set_display(): |
| 64 | + x = {SOURCE} |
| 65 | + SINK(x.pop()) |
| 66 | + |
| 67 | +def test_set_comprehension(): |
| 68 | + x = {SOURCE for y in [3]} |
| 69 | + SINK(x.pop()) |
| 70 | + |
| 71 | +def test_nested_set_display(): |
| 72 | + x = {* {SOURCE}} |
| 73 | + SINK(x.pop()) |
| 74 | + |
| 75 | +# 6.2.7. Dictionary displays |
| 76 | +def test_dict_display(): |
| 77 | + x = {"s": SOURCE} |
| 78 | + SINK(x["s"]) |
| 79 | + |
| 80 | +def test_dict_comprehension(): |
| 81 | + x = {y: SOURCE for y in ["s"]} |
| 82 | + SINK(x["s"]) |
| 83 | + |
| 84 | +def test_nested_dict_display(): |
| 85 | + x = {** {"s": SOURCE}} |
| 86 | + SINK(x["s"]) |
| 87 | + |
| 88 | +# 6.2.8. Generator expressions |
| 89 | +def test_generator(): |
| 90 | + x = (SOURCE for y in [3]) |
| 91 | + SINK([*x][0]) |
17 | 92 |
|
18 | 93 | # List taken from https://docs.python.org/3/reference/expressions.html |
19 | 94 | # 6. Expressions |
|
0 commit comments