code: def test_topological_sort(edges):
      tr = Trace()
      for n1, n2 in edges:
          tr.add_edge(n1, n2)
      top_sort = tr.topological_sort()
  
      # check all nodes are accounted for exactly once
      expected_nodes = set().union(*edges)
      assert len(top_sort) == len(expected_nodes)
      assert set(top_sort) == expected_nodes
  
      # check no edge ordering is violated
      ranks = {n: rank for rank, n in enumerate(top_sort)}
      for n1, n2 in edges:
          assert ranks[n1] < ranks[n2]
  
imports: import itertools
  import pytest
  from pyro.poutine import Trace
  from tests.common import assert_equal
label_desc: Use image node_id 1 for calling a global function with example usage: test_topological_sort(edges) without return types