def test_insert_from(): comp = Computation() comp.add_node("a") comp.add_node("b", lambda a: a + 1, serialize=False) comp.add_node("c", lambda b: b + 1) comp.insert("a", 1) comp2 = comp.copy() comp.compute_all() assert comp.state("a") == States.UPTODATE assert comp.state("b") == States.UPTODATE assert comp.state("c") == States.UPTODATE assert comp.value("a") == 1 assert comp.value("b") == 2 assert comp.value("c") == 3 assert comp2.state("a") == States.UPTODATE assert comp2.state("b") == States.COMPUTABLE assert comp2.state("c") == States.STALE assert comp2.value("a") == 1 comp2.insert_from(comp, ['a', 'c']) assert comp.state("a") == States.UPTODATE assert comp.state("b") == States.UPTODATE assert comp.state("c") == States.UPTODATE assert comp.value("a") == 1 assert comp.value("b") == 2 assert comp.value("c") == 3 assert comp2.state("a") == States.UPTODATE assert comp2.state("b") == States.COMPUTABLE assert comp2.state("c") == States.UPTODATE assert comp2.value("a") == 1 assert comp2.value("c") == 3
def test_copy_2(): comp = Computation() comp.add_node('a') comp.add_node('b', lambda a: a + 1) comp.insert('a', 1) comp2 = comp.copy() assert comp2['a'] == (States.UPTODATE, 1) assert comp2.state('b') == States.COMPUTABLE comp2.compute_all() assert comp['a'] == (States.UPTODATE, 1) assert comp.state('b') == States.COMPUTABLE assert comp2['a'] == (States.UPTODATE, 1) assert comp2['b'] == (States.UPTODATE, 2)
def test_copy(): comp = Computation() comp.add_node("a") comp.add_node("b", lambda a: a + 1) comp.insert("a", 1) comp.compute_all() assert comp.state("a") == States.UPTODATE assert comp.state("b") == States.UPTODATE assert comp.value("a") == 1 assert comp.value("b") == 2 comp2 = comp.copy() comp2.insert("a", 5) comp2.compute_all() assert comp2.state("a") == States.UPTODATE assert comp2.state("b") == States.UPTODATE assert comp2.value("a") == 5 assert comp2.value("b") == 6 assert comp.state("a") == States.UPTODATE assert comp.state("b") == States.UPTODATE assert comp.value("a") == 1 assert comp.value("b") == 2