| 168 | |
| 169 | |
| 170 | def test_fuse_keys(): |
| 171 | fuse = fuse2 # tests both `fuse` and `fuse_linear` |
| 172 | d = {"a": 1, "b": (inc, "a"), "c": (inc, "b")} |
| 173 | keys = ["b"] |
| 174 | assert fuse(d, keys, rename_keys=False) == with_deps( |
| 175 | {"b": (inc, 1), "c": (inc, "b")} |
| 176 | ) |
| 177 | assert fuse(d, keys, rename_keys=True) == with_deps( |
| 178 | {"a-b": (inc, 1), "c": (inc, "a-b"), "b": "a-b"} |
| 179 | ) |
| 180 | |
| 181 | d = { |
| 182 | "w": (inc, "x"), |
| 183 | "x": (inc, "y"), |
| 184 | "y": (inc, "z"), |
| 185 | "z": (add, "a", "b"), |
| 186 | "a": 1, |
| 187 | "b": 2, |
| 188 | } |
| 189 | keys = ["x", "z"] |
| 190 | assert fuse(d, keys, rename_keys=False) == with_deps( |
| 191 | {"w": (inc, "x"), "x": (inc, (inc, "z")), "z": (add, "a", "b"), "a": 1, "b": 2} |
| 192 | ) |
| 193 | assert fuse(d, keys, rename_keys=True) == with_deps( |
| 194 | { |
| 195 | "w": (inc, "y-x"), |
| 196 | "y-x": (inc, (inc, "z")), |
| 197 | "z": (add, "a", "b"), |
| 198 | "a": 1, |
| 199 | "b": 2, |
| 200 | "x": "y-x", |
| 201 | } |
| 202 | ) |
| 203 | |
| 204 | |
| 205 | def test_donot_substitute_same_key_multiple_times(): |