blob: c02362bc21b13a94237649dfd647054611640afa [file] [log] [blame]
trace = stacktrace()
def test_add_edge_ok():
g = new_graph()
k1 = g.key('t1', 'id1')
k2 = g.key('t1', 'id2')
g.add_edge(parent=k1, child=k2)
g.add_node(k1, {})
g.add_node(k2, {})
# Can be successfully finalized.
assert.true(g.finalize() == [])
def test_edge_redeclaration():
g = new_graph()
k1 = g.key('t1', 'id1')
k2 = g.key('t1', 'id2')
g.add_edge(parent=k1, child=k2, title='blah')
# Redeclaring is fine.
g.add_edge(parent=k1, child=k2, title='blah')
# Using a different title is fine too.
g.add_edge(parent=k1, child=k2, title='zzz')
def test_cycle_detection():
g = new_graph()
edge = lambda par, ch: g.add_edge(g.key('t', par), g.key('t', ch))
edge('1', '2')
edge('2', '3')
edge('1', '3')
edge('3', '4')
assert.fails(lambda: edge('4', '1'), 'introduces a cycle')
def test_dangling_edges():
g = new_graph()
exists = g.key('t', 'exists')
g.add_node(exists, {})
miss = lambda id: g.key('t', str(id))
g.add_edge(miss(0), miss(1), title='edge1')
g.add_edge(miss(2), exists, title='edge2')
g.add_edge(exists, miss(3), title='edge3')
errs = g.finalize()
assert.eq(errs, [
'relation "edge1": refers to t("0") and t("1"), neither is defined',
't("exists") in "edge2" refers to undefined t("2")',
't("exists") in "edge3" refers to undefined t("3")',