1import unittest 2import idlelib.RstripExtension as rs 3from idlelib.idle_test.mock_idle import Editor 4 5class rstripTest(unittest.TestCase): 6 7 def test_rstrip_line(self): 8 editor = Editor() 9 text = editor.text 10 do_rstrip = rs.RstripExtension(editor).do_rstrip 11 12 do_rstrip() 13 self.assertEqual(text.get('1.0', 'insert'), '') 14 text.insert('1.0', ' ') 15 do_rstrip() 16 self.assertEqual(text.get('1.0', 'insert'), '') 17 text.insert('1.0', ' \n') 18 do_rstrip() 19 self.assertEqual(text.get('1.0', 'insert'), '\n') 20 21 def test_rstrip_multiple(self): 22 editor = Editor() 23 # Uncomment following to verify that test passes with real widgets. 24## from idlelib.EditorWindow import EditorWindow as Editor 25## from tkinter import Tk 26## editor = Editor(root=Tk()) 27 text = editor.text 28 do_rstrip = rs.RstripExtension(editor).do_rstrip 29 30 original = ( 31 "Line with an ending tab \n" 32 "Line ending in 5 spaces \n" 33 "Linewithnospaces\n" 34 " indented line\n" 35 " indented line with trailing space \n" 36 " ") 37 stripped = ( 38 "Line with an ending tab\n" 39 "Line ending in 5 spaces\n" 40 "Linewithnospaces\n" 41 " indented line\n" 42 " indented line with trailing space\n") 43 44 text.insert('1.0', original) 45 do_rstrip() 46 self.assertEqual(text.get('1.0', 'insert'), stripped) 47 48if __name__ == '__main__': 49 unittest.main(verbosity=2, exit=False) 50