diff -r bc3a34e47923 Lib/idlelib/IdleHistory.py --- a/Lib/idlelib/IdleHistory.py Sat Jul 13 04:05:42 2013 -0400 +++ b/Lib/idlelib/IdleHistory.py Thu Jul 18 15:46:29 2013 +0530 @@ -1,14 +1,16 @@ from idlelib.configHandler import idleConf + class History: - def __init__(self, text, output_sep = "\n"): + def __init__(self, text, output_sep="\n"): self.text = text self.history = [] self.history_prefix = None self.history_pointer = None self.output_sep = output_sep - self.cyclic = idleConf.GetOption("main", "History", "cyclic", 1, "bool") + self.cyclic = idleConf.GetOption("main", "History", "cyclic", + 1, "bool") text.bind("<>", self.history_prev) text.bind("<>", self.history_next) @@ -86,3 +88,10 @@ self.history.append(source) self.history_pointer = None self.history_prefix = None + +if __name__ == "__main__": + from test import support + support.use_resources = ['gui'] + import unittest + unittest.main('idlelib.idle_test.test_idlehistory', verbosity=2, + exit=False) diff -r bc3a34e47923 Lib/idlelib/idle_test/test_idlehistory.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/idle_test/test_idlehistory.py Thu Jul 18 15:46:29 2013 +0530 @@ -0,0 +1,86 @@ +import unittest +from test.support import requires + +from _tkinter import TclError +import tkinter as tk + +import idlelib.IdleHistory as ihis +from idlelib.idle_test.mock_tk import Text +from idlelib.configHandler import idleConf + + +class IdleHistoryMockTest(unittest.TestCase): + '''IdleHistory tests which can be done using mock_tk + ''' + + def setUp(self): + self.mytext = Text() + self.mytext.insert('1.0', " idlehistory test ") + self.myhistory = ihis.History(self.mytext) + + def TearDown(self): + self.mytext = None + self.myhistory = None + + def test_myhistory(self): + self.assertIs(self.myhistory.text, self.mytext) + self.assertEqual(self.myhistory.history, []) + self.assertIsNone(self.myhistory.history_prefix) + self.assertIsNone(self.myhistory.history_pointer) + self.assertEqual(self.myhistory.cyclic, idleConf.GetOption("main", + "History", + "cyclic", 1, + "bool")) + self.assertEqual(self.myhistory.output_sep, "\n") + + def test_duplicates_history_store(self): + # source having length less than 3 (after stripped) should be avoided + source = self.mytext.get('1.0', '1.4') + self.myhistory.history_store(source) + self.assertEqual(self.myhistory.history, []) + + def test_history_store(self): + source = self.mytext.get('1.0', '1.6') + self.myhistory.history_store(source) + self.assertEqual(self.myhistory.history, ['idle']) + + +class IdleHistoryTKTest(unittest.TestCase): + '''IdleHistory tests which needs TK + ''' + @classmethod + def setUpClass(cls): + requires('gui') + from tkinter import Tk, Text + cls.text = Text() + cls.text.insert('1.0', " idlehistory test") + cls.text.mark_set("iomark", "1.6") + cls.mytkhistory = ihis.History(cls.text) + try: + cls.root = Tk() + except TclError as msg: + raise unittest.SkipTest('TclError: %s' % msg) + + @classmethod + def tearDownClass(cls): + cls.root.destroy() + + def test_history_do_next(self): + ''' + Test history_do function for history_next call + deletes text from 'iomark' and inserts history_prefix + ''' + source = self.text.get("iomark", "end-1c") + self.mytkhistory.history_store(source) + self.text.mark_set("insert", "end-1c") + self.mytkhistory.history_prefix = "Done_history_test" + self.mytkhistory.history_pointer = 0 + self.mytkhistory.history_do(0) + self.assertEqual(self.mytkhistory.text.get('1.0', '1.24'), + " idleDone_history_test") + self.assertIsNone(self.mytkhistory.history_pointer) + self.assertIsNone(self.mytkhistory.history_prefix) + + +if __name__ == '__main__': + unittest.main(verbosity=2, exit=2)