code: def test_topsorted_layers_error_if_cycle(self):
      nodes = [
          Node("A", [], ["B", "E"]),
          Node("B", ["A", "D"], ["C"]),
          Node("C", ["B"], ["D"]),
          Node("D", ["C"], ["B"]),
          Node("E", ["A"], []),
      ]
      node_map = {node.name: node for node in nodes}
      with self.assertRaisesRegex(
          topsort.InvalidDAGError, "Cycle detected."
      ):
          topsort.topsorted_layers(
              nodes,
              get_node_id_fn=lambda n: n.name,
              get_parent_nodes=(
                  lambda n: [
                      node_map[name] for name in n.upstream_nodes
                  ]
              ),
              get_child_nodes=(
                  lambda n: [
                      node_map[name] for name in n.downstream_nodes
                  ]
              ),
          )
  
file_path: tfx/tfx/utils/topsort_test.py
imports: import attr
  import tensorflow
  from tfx.utils import topsort
label_desc: Use image node_id 2 for calling the TopsortTest obj's underlying member method code with example usage: obj.test_topsorted_layers_error_if_cycle() without return types