code: def test_record_bad():
      # Tests that when we record a sequence of events, then
      # do something different on playback, the Record class catches it.
  
      # Record a sequence of events
      output = StringIO()
  
      recorder = Record(file_object=output, replay=False)
  
      num_lines = 10
  
      for i in xrange(num_lines):
          recorder.handle_line(str(i) + "\n")
  
      # Make sure that the playback functionality doesn't raise any errors
      # when we repeat some of them
      output_value = output.getvalue()
      output = StringIO(output_value)
  
      playback_checker = Record(file_object=output, replay=True)
  
      for i in xrange(num_lines // 2):
          playback_checker.handle_line(str(i) + "\n")
  
      # Make sure it raises an error when we deviate from the recorded sequence
      try:
          playback_checker.handle_line("0\n")
      except MismatchError:
          return
      raise AssertionError(
          "Failed to detect mismatch between recorded sequence "
          " and repetition of it."
      )
  
file_path: Theano/theano/tests/test_record.py
imports: from __future__ import absolute_import, print_function, division
  from theano.tests.record import Record, MismatchError, RecordMode
  from theano import function
  from six.moves import xrange, StringIO
  from theano.tensor import iscalar
label_desc: Use image node_id 2 for calling a global function with example usage: test_record_bad() without return types