def test_ensure_flag(): proxies = [random_proxies() for _ in range(3)] G = EntityGraph() G.add_proxies(proxies) G.ensure_flag(test=True) for node in G.nodes(): assert node.has_flags(test=True)
def test_get_nodes(): proxies = [random_proxies() for _ in range(10)] G = EntityGraph() G.add_proxies(proxies) G.ensure_flag(test=True) G.get_node_by_proxy(proxies[0]).set_flags(test=False) G.get_node_by_proxy(proxies[1]).set_flags(test=None) G.merge_proxies(*proxies[2:]) assert len(list(G.proxies())) == 10 assert len(list(G.proxies(test=True))) == 8 assert len(list(G.proxies(test=False))) == 1 assert len(list(G.proxies(test=None))) == 1 assert len(list(G.nodes())) == 3 assert len(list(G.nodes(test=True))) == 1 assert len(list(G.nodes(test=False))) == 1 assert len(list(G.nodes(test=None))) == 1
def test_merge(): proxies = [random_proxies() for _ in range(3)] edges = [ create_link([proxies[2]], [proxies[1]]), create_link([proxies[0]], [proxies[2]]), create_link([proxies[1]], [proxies[2]]), ] G = EntityGraph() G.add_proxies(proxies) G.add_proxies(edges) G.merge_proxies(proxies[0], proxies[1]) node = G.get_node_by_proxy(proxies[0]) assert len(list(G.nodes())) == 5 assert len(node.parts) == 2 assert len(G.get_node_in_edges(node)) == 1 assert len(G.get_node_out_edges(node)) == 2