class_docstr: These tests were added to check that the libedit emulation on OSX and the
  "real" readline have the same interface for history manipulation. That's
  why the tests cover only a small subset of the interface.
class_docstr_tok: ["These","tests","were","added","to","check","that","the","libedit","emulation","on","OSX","and","the","''","real","''","readline","have","the","same","interface","for","history","manipulation",".","That's","why","the","tests","cover","only","a","small","subset","of","the","interface","."]
code: def test_write_read_append(self):
      hfile = tempfile.NamedTemporaryFile(delete=False)
      hfile.close()
      hfilename = hfile.name
      self.addCleanup(unlink, hfilename)
  
      # test write-clear-read == nop
      readline.clear_history()
      readline.add_history("first line")
      readline.add_history("second line")
      readline.write_history_file(hfilename)
  
      readline.clear_history()
      self.assertEqual(readline.get_current_history_length(), 0)
  
      readline.read_history_file(hfilename)
      self.assertEqual(readline.get_current_history_length(), 2)
      self.assertEqual(readline.get_history_item(1), "first line")
      self.assertEqual(readline.get_history_item(2), "second line")
  
      # test append
      readline.append_history_file(1, hfilename)
      readline.clear_history()
      readline.read_history_file(hfilename)
      self.assertEqual(readline.get_current_history_length(), 3)
      self.assertEqual(readline.get_history_item(1), "first line")
      self.assertEqual(readline.get_history_item(2), "second line")
      self.assertEqual(readline.get_history_item(3), "second line")
  
      # test 'no such file' behaviour
      os.unlink(hfilename)
      try:
          readline.append_history_file(1, hfilename)
      except FileNotFoundError:
          pass  # Some implementations return this error (libreadline).
      else:
          os.unlink(hfilename)  # Some create it anyways (libedit).
          # If the file wasn't created, unlink will fail.
      # We're just testing that one of the two expected behaviors happens
      # instead of an incorrect error.
  
      # write_history_file can create the target
      readline.write_history_file(hfilename)
  
imports: import locale
  import os
  import sys
  import tempfile
  import textwrap
  import unittest
  from test.support import verbose
  from test.support.import_helper import import_module
  from test.support.os_helper import unlink, temp_dir, TESTFN
  from test.support.pty_helper import run_pty
  from test.support.script_helper import assert_python_ok
label_desc: Use image node_id 2 for calling the TestHistoryManipulation obj's underlying member method code with example usage: obj.test_write_read_append() without return types