def test_read_abspath(self): history.append('fred') history.append('wilma') history.write_file('my_history', raise_exc=True) history.clear() history.read_file(abspath('my_history'), raise_exc=True) self.assertEqual(len(history), 2)
def test_read_None_name(self): history.append('fred') history.append('wilma') history.write_file(self.histfile, raise_exc=True) history.clear() history.read_file(None, raise_exc=True) self.assertEqual(len(history), 2)
def test_write_bytes_name(self): history.append('fred') history.append('wilma') history.write_file(bytes('my_history', sys.getfilesystemencoding()), raise_exc=True) self.assertTrue(isfile('my_history'))
def test_read_tilde_expanded(self): history.append('fred') history.append('wilma') history.write_file(self.histfile, raise_exc=True) history.clear() history.read_file('~/.history', raise_exc=True) self.assertEqual(len(history), 2)
def test_read_bytes_name(self): history.append('fred') history.append('wilma') history.write_file(bytes('my_history', sys.getfilesystemencoding()), raise_exc=True) history.clear() history.read_file(bytes('my_history', sys.getfilesystemencoding()), raise_exc=True) self.assertEqual(len(history), 2)
def test_append_relative(self): history.write_file('my_history', raise_exc=True) history.append('fred') history.append('wilma') history.append_file(2, 'my_history') history.clear() history.read_file('my_history', raise_exc=True) self.assertEqual(len(history), 2)
def test_write_file_truncates_file(self): history.append('fred') history.append('wilma') history.append('pebbles') history.max_file = 2 history.write_file('my_history', raise_exc=True) history.clear() history.read_file('my_history', raise_exc=True) self.assertEqual(len(history), 2) self.assertEqual(history[0], 'wilma') self.assertEqual(history[1], 'pebbles')
def postloop(self): """Called when the :meth:`~kmd.Kmd.cmdloop` method is exited. Resets the readline completer and saves the history file. Note that :meth:`~kmd.Kmd.postloop` is called even if :meth:`~kmd.Kmd.cmdloop` exits with an exception! """ if self.use_rawinput: if self.history_file: history.write_file(self.history_file) if self.completekey: completer.reset()
def test_write_file_replaces_file(self): history.append('fred') history.append('wilma') history.write_file('my_history', raise_exc=True) history.clear() history.append('barney') history.append('betty') history.write_file('my_history', raise_exc=True) history.clear() history.read_file('my_history', raise_exc=True) self.assertEqual(len(history), 2) self.assertEqual(history[0], 'barney') self.assertEqual(history[1], 'betty')
def postloop(self): """Called when the :meth:`~kmd.Kmd.cmdloop` method is exited. Resets the readline completer and saves the history file. Note that :meth:`~kmd.Kmd.postloop` is called even if :meth:`~kmd.Kmd.cmdloop` exits with an exception! """ if self.use_rawinput: if self.history_file: history.write_file(self.history_file) if self.completekey: self.clear_hooks() history.clear()
def test_append_file_truncates_file(self): history.append('fred') history.append('wilma') history.append('pebbles') history.write_file('my_history', raise_exc=True) history.clear() history.append('barney') history.append('betty') history.append('bammbamm') history.max_file = 3 history.append_file(2, 'my_history') history.clear() history.read_file('my_history', raise_exc=True) self.assertEqual(len(history), 3) self.assertEqual(history[0], 'pebbles') self.assertEqual(history[1], 'betty') self.assertEqual(history[2], 'bammbamm')
def test_read_file_stifled(self): history.append('fred') history.append('wilma') history.append('barney') history.append('betty') history.append('pebbles') history.append('bammbamm') history.append('dino') self.assertEqual(len(history), 7) history.write_file('my_history', raise_exc=True) history.clear() history.max_entries = 5 history.read_file('my_history', raise_exc=True) self.assertEqual(history[0], 'barney') self.assertEqual(history[1], 'betty') self.assertEqual(history[2], 'pebbles') self.assertEqual(history[3], 'bammbamm') self.assertEqual(history[4], 'dino') self.assertEqual(len(history), 5)
def test_write_abspath(self): history.append('fred') history.append('wilma') history.write_file(abspath('my_history'), raise_exc=True) self.assertTrue(isfile(abspath('my_history'))) self.assertTrue(isfile('my_history'))
def test_read_empty_string(self): history.append('fred') history.append('wilma') history.write_file(self.histfile, raise_exc=True) history.clear() self.assertRaises(IOError, history.read_file, '', raise_exc=True)
def test_write_relative(self): history.append('fred') history.append('wilma') history.write_file('my_history', raise_exc=True) self.assertTrue(isfile('my_history'))
def test_write_tilde_expanded(self): history.append('fred') history.append('wilma') history.write_file('~/.history', raise_exc=True) self.assertTrue(isfile(self.histfile))
def test_write_None_name(self): history.append('fred') history.append('wilma') history.write_file(None, raise_exc=True) self.assertTrue(isfile(self.histfile))