code: def test_take_action_gives_correct_next_states_with_lambda_productions(
      self,
  ):
      # state.take_action() doesn't read or change these objects, it just passes them through, so
      # we'll use some sentinels to be sure of that.
      valid_actions = object()
      action_indices = object()
  
      state = GrammarState(
          ["t", "<s,d>"],
          {},
          valid_actions,
          action_indices,
          is_nonterminal,
      )
      next_state = state.take_action("<s,d> -> [lambda x, d]")
      expected_next_state = GrammarState(
          ["t", "d"],
          {("s", "x"): ["d"]},
          valid_actions,
          action_indices,
          is_nonterminal,
      )
      assert next_state.__dict__ == expected_next_state.__dict__
  
      state = expected_next_state
      next_state = state.take_action("d -> [<s,r>, d]")
      expected_next_state = GrammarState(
          ["t", "d", "<s,r>"],
          {("s", "x"): ["d", "<s,r>"]},
          valid_actions,
          action_indices,
          is_nonterminal,
      )
      assert next_state.__dict__ == expected_next_state.__dict__
  
      state = expected_next_state
      next_state = state.take_action("<s,r> -> [lambda y, r]")
      expected_next_state = GrammarState(
          ["t", "d", "r"],
          {("s", "x"): ["d", "r"], ("s", "y"): ["r"]},
          valid_actions,
          action_indices,
          is_nonterminal,
      )
      assert next_state.__dict__ == expected_next_state.__dict__
  
      state = expected_next_state
      next_state = state.take_action("r -> identity")
      expected_next_state = GrammarState(
          ["t", "d"],
          {("s", "x"): ["d"]},
          valid_actions,
          action_indices,
          is_nonterminal,
      )
      assert next_state.__dict__ == expected_next_state.__dict__
  
      state = expected_next_state
      next_state = state.take_action("d -> x")
      expected_next_state = GrammarState(
          ["t"], {}, valid_actions, action_indices, is_nonterminal
      )
      assert next_state.__dict__ == expected_next_state.__dict__
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/nn/decoding/grammar_state_test.py
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import pytest
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn.decoding import GrammarState
label_desc: Use image node_id 7 for calling the TestGrammarState obj's underlying member method code with example usage: obj.test_take_action_gives_correct_next_states_with_lambda_productions() without return types