Total Complexity | 16 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | from py14.tracer import value_type, value_expr, decltype, is_list, is_recursive |
||
14 | class TestValueType: |
||
15 | def test_direct_assignment(self): |
||
16 | source = parse("x = 3") |
||
17 | x = source.body[0] |
||
18 | t = value_type(x) |
||
19 | assert t == "3" |
||
20 | |||
21 | def test_assign_name(self): |
||
22 | source = parse( |
||
23 | "x = 3", |
||
24 | "y = x", |
||
25 | ) |
||
26 | y = source.body[1] |
||
27 | t = value_type(y) |
||
28 | assert t == "x" |
||
29 | |||
30 | def test_assign_function(self): |
||
31 | source = parse( |
||
32 | "x = 3", |
||
33 | "y = foo(x)", |
||
34 | ) |
||
35 | y = source.body[1] |
||
36 | t = value_type(y) |
||
37 | assert t == "foo(x)" |
||
38 | |||
39 | def test_list_assignment_with_default_values(self): |
||
40 | source = parse( |
||
41 | "x = 3", |
||
42 | "results = [x]", |
||
43 | ) |
||
44 | results = source.body[1] |
||
45 | t = value_type(results) |
||
46 | assert t == "x" |
||
47 | |||
48 | def test_list_assignment_with_function_call_as_value(self): |
||
49 | source = parse( |
||
50 | "x = 3", |
||
51 | "results = [foo(x)]", |
||
52 | ) |
||
53 | results = source.body[1] |
||
54 | t = value_type(results) |
||
55 | assert t == "foo(x)" |
||
56 | |||
57 | def test_list_assignment_based_on_later_append(self): |
||
58 | source = parse( |
||
59 | "x = 3", |
||
60 | "results = []", |
||
61 | "results.append(x)", |
||
62 | ) |
||
63 | add_list_calls(source) |
||
64 | results = source.body[1] |
||
65 | t = value_type(results) |
||
66 | assert t == "3" |
||
67 | |||
68 | def test_list_assignment_with_append_unknown_value(self): |
||
69 | source = parse( |
||
70 | "results = []", |
||
71 | "x = 3", |
||
72 | "results.append(x)", |
||
73 | ) |
||
74 | add_list_calls(source) |
||
75 | results = source.body[0] |
||
76 | t = value_type(results) |
||
77 | assert t == "3" |
||
78 | |||
79 | def test_global_list_assignment_with_later_append(self): |
||
80 | source = parse( |
||
81 | "results = []", |
||
82 | "def add_x():", |
||
83 | " results.append(2)", |
||
84 | ) |
||
85 | add_list_calls(source) |
||
86 | results = source.body[0] |
||
87 | t = value_type(results) |
||
88 | assert t == "2" |
||
89 | |||
152 |