go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/lucicfg/graph/testdata/finalization.star (about)

     1  def test_finalization():
     2      g = new_graph()
     3      k1 = g.key("t1", "id1")
     4      k2 = g.key("t1", "id2")
     5      k3 = g.key("t1", "id3")
     6  
     7      # Before the finalization the graph can be modified.
     8      g.add_node(k1)
     9      g.add_node(k2)
    10      g.add_edge(k1, k2)
    11  
    12      # But not queried.
    13      assert.fails(lambda: g.node(k1), "cannot query a graph under construction")
    14      assert.fails(lambda: g.children(k1), "cannot query a graph under construction")
    15      assert.fails(lambda: g.descendants(k1), "cannot query a graph under construction")
    16  
    17      # Can be finalized. Refinalizing is noop.
    18      assert.eq(g.finalize(), [])
    19      assert.eq(g.finalize(), [])
    20  
    21      # The graph is no longer mutable.
    22      assert.fails(lambda: g.add_node(k3), "cannot modify a finalized graph")
    23      assert.fails(lambda: g.add_edge(k1, k3), "cannot modify a finalized graph")
    24  
    25      # But is it queryable now.
    26      assert.true(g.node(k1) != None)
    27      assert.eq(g.children(k1), [g.node(k2)])
    28      assert.eq(g.descendants(k1), [g.node(k1), g.node(k2)])
    29  
    30  test_finalization()