code: def test_in_order_compound_finalize(model=None):
      """
      Test the Finalize transition is only legal at the end of a sequence
      """
      if model is None:
          model = SimpleModel(
              transition_scheme=TransitionScheme.IN_ORDER_COMPOUND
          )
  
      state = build_initial_state(model)[0]
  
      finalize = parse_transitions.Finalize("ROOT")
  
      shift = parse_transitions.Shift()
      assert shift.is_legal(state, model)
      assert not finalize.is_legal(state, model)
      state = shift.apply(state, model)
  
      open_transition = parse_transitions.OpenConstituent("NP")
      assert open_transition.is_legal(state, model)
      assert not finalize.is_legal(state, model)
      state = open_transition.apply(state, model)
      assert state.num_opens == 1
  
      assert shift.is_legal(state, model)
      assert not finalize.is_legal(state, model)
      state = shift.apply(state, model)
      assert shift.is_legal(state, model)
      assert not finalize.is_legal(state, model)
      state = shift.apply(state, model)
  
      close_transition = parse_transitions.CloseConstituent()
      assert close_transition.is_legal(state, model)
      state = close_transition.apply(state, model)
      assert state.num_opens == 0
      assert not close_transition.is_legal(state, model)
      assert finalize.is_legal(state, model)
  
      state = finalize.apply(state, model)
      assert not finalize.is_legal(state, model)
      tree = model.get_top_constituent(state.constituents)
      assert tree.label == "ROOT"
  
imports: import pytest
  from stanza.models.constituency import parse_transitions
  from stanza.models.constituency.base_model import SimpleModel, UNARY_LIMIT
  from stanza.models.constituency.parse_transitions import TransitionScheme, Shift, CloseConstituent, OpenConstituent
  from stanza.tests import *
label_desc: Use image node_id 13 for calling a global function with example usage: test_in_order_compound_finalize(model) without return types