code: def test_chain_idx():
      # dict
      d = {1: {2: 3}}
      ls = [1, [2], [None, [3]]]
      assert py_datastructures.chain_idx(d[1], [2]) == 3
      assert py_datastructures.chain_idx(d, [1, 2]) == 3
      with pytest.raises(KeyError):
          py_datastructures.chain_idx(d, [1, 3])
      with pytest.raises(KeyError):
          py_datastructures.chain_idx(d, [3])
  
      # list
      assert py_datastructures.chain_idx(ls, [0]) == 1
      assert py_datastructures.chain_idx(ls, [1]) == [2]
      assert py_datastructures.chain_idx(ls, [1, 0]) == 2
      assert py_datastructures.chain_idx(ls, [2, 0]) is None
      assert py_datastructures.chain_idx(ls, [2, 1, 0]) == 3
      with pytest.raises(TypeError):
          py_datastructures.chain_idx(ls, [0, 0, 0])
      with pytest.raises(IndexError):
          py_datastructures.chain_idx(ls, [1, 1])
  
file_path: jiant/tests/utils/python/test_datastructures.py
imports: import json
  import pytest
  from dataclasses import dataclass
  import jiant.utils.python.datastructures
label_desc: Use image node_id 2 for calling a global function with example usage: test_chain_idx() without return types