code: def test_ancestors():
      graph = DiGraph()
  
      with pytest.raises(NodeNotFoundError):
          graph.ancestors(0)
  
      # Case 1:
      #  +--> [1] --> [3] --> [5]
      #  |                     ^
      # [0]                    |
      #  |                     |
      #  +--> [2] --> [4] -----+
      for node in range(6):
          graph.add_node(node)
  
      graph.add_edge(0, 1)
      graph.add_edge(1, 3)
      graph.add_edge(3, 5)
  
      graph.add_edge(0, 2)
      graph.add_edge(2, 4)
      graph.add_edge(4, 5)
  
      assert graph.ancestors(0) == set()
      assert graph.ancestors(4) == {0, 2}
      assert graph.ancestors(5) == {0, 1, 2, 3, 4}
  
      # Case 2:
      #  [0] --> [1] --> [4]
      #           ^       ^
      #           |       |
      #   + ------+       |
      #   |               |
      #  [2] --> [3] -----+
      graph = DiGraph()
      for node in range(5):
          graph.add_node(node)
  
      graph.add_edge(0, 1)
      graph.add_edge(1, 4)
  
      graph.add_edge(2, 1)
      graph.add_edge(2, 3)
      graph.add_edge(3, 4)
  
      assert graph.ancestors(0) == set()
      assert graph.ancestors(1) == {0, 2}
      assert graph.ancestors(3) == {2}
      assert graph.ancestors(4) == {0, 1, 2, 3}
  
file_path: baikal/tests/_core/test_digraph.py
imports: import pytest
  from baikal._core.digraph import DiGraph, NodeNotFoundError, CyclicDiGraphError
label_desc: Use image node_id 10 for calling a global function with example usage: test_ancestors() without return types