-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_updated_symbols.py
54 lines (43 loc) · 1.51 KB
/
test_updated_symbols.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
import logging
from test.utils import make_flow_fixture
from ipyflow.data_model.symbol import Symbol
from ipyflow.singletons import flow
logging.basicConfig(level=logging.ERROR)
# Reset dependency graph before each test
# _flow_fixture, run_cell_ = make_flow_fixture(trace_messages_enabled=True)
_flow_fixture, run_cell_ = make_flow_fixture()
def updated_symbol_names():
return sorted(
[sym.readable_name for sym in flow().updated_symbols if not sym.is_anonymous]
)
def run_cell(cell):
# print()
# print('*******************************************')
# print('running', cell)
# print('*******************************************')
# print()
run_cell_(cell)
def test_simplest():
run_cell("a = 0")
assert updated_symbol_names() == ["a"]
run_cell("a += 1")
assert updated_symbol_names() == ["a"]
def test_dict_hierarchy():
run_cell("d = {}")
updated_sym_names = updated_symbol_names()
assert updated_sym_names == [
"d",
f"d.{Symbol.IPYFLOW_MUTATION_VIRTUAL_SYMBOL_NAME}",
], (
"got %s" % updated_sym_names
)
run_cell('d["foo"] = {}')
assert updated_symbol_names() == sorted(["d[foo]", "d"])
run_cell('d["foo"]["bar"] = []')
updated_sym_names = updated_symbol_names()
assert updated_sym_names == sorted(["d[foo][bar]", "d[foo]", "d"]), (
"got %s" % updated_sym_names
)
run_cell('d["foo"]["bar"] = 0')
assert updated_symbol_names() == sorted(["d[foo][bar]", "d[foo]", "d"])