Anonymous avatar Anonymous committed c2f97cb

Separated ropeide tests

Comments (0)

Files changed (48)

docs/dev/stories.txt

 * Generate ~/.rope graphically
 
 
-* ropemacs: auto-complete and show doc
+* ropemacs: auto-complete
+
+
+* ropemacs: previewing changes
 
 
 * ropemacs: showing refactoring progress

docs/dev/workingon.txt

+Plans For New Packages
+======================
+
+* Renaming `rope.ide` to `rope.contrib`
+* Renaming `rope.ui` to `ropeide`
+* Renaming ``rope.py`` to ``ropeide.py``
+* Renaming `rope.contrib.ropemacs` to `ropemacs`
+* Renaming ``~/.rope`` to ``~/.ropeide``
+* Three separate packages: rope, ropeide, ropemacs
+* Separating ropeide tests
+* Updating docs
+* Separating docs for different packages
+
+
 ropemacs Mode
 =============
 
 * Adding rope menu
+* Adding a patch for pymacs on python2.5
 * Specifying refactoring options
 * Only activating keybinding in python files
 * Updating docs

ropeidetest/__init__.py

+import unittest
+
+import ropeidetest.editortest
+import ropeidetest.fileeditortest
+import ropeidetest.coretest
+import ropeidetest.mockeditortest
+import ropeidetest.highlightertest
+import ropeidetest.searchertest
+import ropeidetest.statusbartest
+import ropeidetest.uihelperstest
+import ropeidetest.indentertest
+import ropeidetest.filltest
+import ropeidetest.formattertest
+import ropeidetest.notestest
+import ropeidetest.outlinetest
+import ropeidetest.spellcheckertest
+import ropeidetest.movementstest
+import ropeidetest.sorttest
+
+
+def suite():
+    result = unittest.TestSuite()
+    result.addTests(ropeidetest.mockeditortest.suite())
+    result.addTests(unittest.makeSuite(ropeidetest.fileeditortest.FileEditorTest))
+    result.addTests(unittest.makeSuite(ropeidetest.searchertest.SearchingTest))
+    result.addTests(unittest.makeSuite(ropeidetest.coretest.CoreTest))
+    result.addTests(ropeidetest.editortest.suite())
+    result.addTests(ropeidetest.highlightertest.suite())
+    result.addTests(unittest.makeSuite(ropeidetest.indentertest.PythonCodeIndenterTest))
+    result.addTests(unittest.makeSuite(ropeidetest.statusbartest.StatusBarTest))
+    result.addTests(unittest.makeSuite(ropeidetest.uihelperstest.UIHelpersTest))
+    result.addTests(unittest.makeSuite(ropeidetest.filltest.FillTest))
+    result.addTests(unittest.makeSuite(ropeidetest.formattertest.FormatterTest))
+    result.addTests(unittest.makeSuite(ropeidetest.notestest.AnnotationsTest))
+    result.addTests(unittest.makeSuite(ropeidetest.outlinetest.OutlineTest))
+    result.addTests(ropeidetest.movementstest.suite())
+    result.addTests(unittest.makeSuite(ropeidetest.sorttest.SortScopesTest))
+    return result
+
+
+if __name__ == '__main__':
+    runner = unittest.TextTestRunner()
+    runner.run(suite())

ropeidetest/coretest.py

+import os
+import unittest
+
+from ropeide.core import Core, RopeError
+from ropetest import testutils
+
+
+class CoreTest(unittest.TestCase):
+
+    def setUp(self):
+        unittest.TestCase.setUp(self)
+        self.project_root = 'sample_project'
+        testutils.remove_recursively(self.project_root)
+        self._make_sample_project()
+        self.sample_file2 = 'samplefile2.txt'
+        self.core = Core.get_core()
+        self.core._init_x()
+        self.core._init_menus()
+        self.core.prefs.set('project_rope_folder', None)
+        self.core.open_project(self.project_root)
+        self.textEditor = self.core.open_file(self.sample_file)
+        self.project = self.core.get_open_project()
+
+    def _make_sample_project(self):
+        self.sample_file = 'sample_file.txt'
+        self.sample_path = os.path.join(self.project_root, 'sample_file.txt')
+        os.mkdir(self.project_root)
+        self.sample_folder = 'sample_folder'
+        os.mkdir(os.path.join(self.project_root, self.sample_folder))
+        sample = open(self.sample_path, 'w')
+        sample.write('sample text\n')
+        sample.close()
+
+    def tearDown(self):
+        self.core.close_project()
+        testutils.remove_recursively(self.project_root)
+        unittest.TestCase.tearDown(self)
+
+    def test_opening_files(self):
+        self.assertEquals('sample text\n',
+                          self.textEditor.get_editor().get_text())
+
+    def test_active_editor(self):
+        self.assertEquals(self.textEditor, self.core.get_active_editor())
+        newEditor = self.core.open_file(self.sample_file)
+        self.assertEquals(newEditor, self.core.get_active_editor())
+
+    def test_saving(self):
+        self.textEditor.get_editor().set_text('another text')
+        self.core.save_active_editor()
+
+    def test_error_when_opening_a_non_existent_file(self):
+        try:
+            self.core.open_file(self.sample_file2)
+            self.fail('Should have thrown exception; file doesn\'t exist')
+        except RopeError:
+            pass
+
+    def test_making_new_files(self):
+        editor = self.core.create_file(self.sample_file2)
+        editor.get_editor().set_text('file2')
+        editor.save()
+
+    def test_error_when_making_already_existent_file(self):
+        try:
+            editor = self.core.create_file(self.sample_file)
+            self.fail('Show have throws exception; file already exists')
+        except RopeError:
+            pass
+
+    def test_creating_folders(self):
+        self.core.create_folder('SampleFolder')
+
+    def test_not_reopening_editors(self):
+        editor1 = self.core.open_file(self.sample_file)
+        editor2 = self.core.open_file(self.sample_file)
+        self.assertTrue(editor1 is editor2)
+
+    def test_closing_editor(self):
+        editor = self.core.open_file(self.sample_file)
+        self.assertEquals(self.core.get_active_editor(), editor)
+        self.core.close_active_editor()
+        self.assertNotEquals(self.core.get_active_editor(), editor)
+
+    def test_closing_the_last_editor(self):
+        self.core.close_active_editor()
+        self.assertTrue(self.core.get_active_editor() is None)
+
+    def test_switching_active_editor(self):
+        parent = self.project.root;
+        parent.create_file('file1.txt')
+        parent.create_file('file2.txt')
+        editor1 = self.core.open_file('file1.txt')
+        editor2 = self.core.open_file('file2.txt')
+        self.assertEquals(editor2, self.core.get_active_editor())
+        self.core.switch_active_editor()
+        self.assertEquals(editor1, self.core.get_active_editor())
+
+    def test_saving_all(self):
+        self.textEditor.get_editor().set_text('another text')
+        text_editor2 = self.core.create_file(self.sample_file2)
+        text_editor2.get_editor().set_text('another text')
+        file1 = self.project.get_resource(self.sample_file)
+        file2 = self.project.get_resource(self.sample_file)
+        self.core.save_all_editors()
+        self.assertEquals('another text', file1.read())
+        self.assertEquals('another text', file2.read())
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/editortest.py

+import unittest
+import Tkinter
+
+from ropeidetest.mockeditortest import (GraphicalEditorFactory,
+                                        get_sample_editingcontext)
+from ropeide.indenter import PythonCodeIndenter
+from ropeide import editor
+
+
+class GraphicalEditorTest(unittest.TestCase):
+    """This class only tests features that are specific to GraphicalEditor;
+    see mockeditortest
+    """
+
+    __factory = GraphicalEditorFactory(Tkinter.Frame())
+
+    def setUp(self):
+        unittest.TestCase.setUp(self)
+        self.editor = self.__factory.create(get_sample_editingcontext())
+        self.editor.set_text('sample text')
+
+    def tearDown(self):
+        unittest.TestCase.tearDown(self)
+
+    def test_move_next_word(self):
+        self.editor.next_word()
+        self.assertEquals(' ', self.editor.get(), 'Expected <%c> but was <%c>' % (' ', self.editor.get()))
+
+    def test_move_next_word_on_spaces(self):
+        self.editor.next_word()
+        self.editor.insert(self.editor.get_end(), ' and\n')
+        self.editor.next_word()
+        self.assertEquals(' ', self.editor.get())
+        self.editor.next_word()
+        self.assertEquals('\n', self.editor.get())
+
+    def test_next_word_on_end(self):
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_end(), self.editor.get_insert())
+
+    def test_next_word_on_new_line(self):
+        self.editor.set_insert(self.editor.get_relative(self.editor.get_end(), -1))
+        self.editor.insert(self.editor.get_end(), '\non a new line')
+        self.editor.next_word()
+        self.assertEquals('\n', self.editor.get())
+
+    def test_next_word_on_new_line(self):
+        self.editor.set_text('hello \n world\n')
+        self.editor.next_word()
+        self.editor.next_word()
+        self.assertEquals('\n', self.editor.get(), self.editor.get())
+
+    def test_next_one_character_word(self):
+        self.editor.set_text('1 2\n')
+        self.editor.next_word()
+        self.assertEquals(' ', self.editor.get())
+        self.editor.next_word()
+        self.assertEquals('\n', self.editor.get())
+
+    def test_prev_word_on_the_begining(self):
+        self.editor.prev_word()
+        self.assertEquals('s', self.editor.get())
+
+    def test_prev_word(self):
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.prev_word()
+        self.assertEquals('t', self.editor.get())
+        self.editor.prev_word()
+        self.assertEquals('s', self.editor.get())
+
+    def test_prev_word_on_the_middle_of_a_word(self):
+        self.editor.set_insert(self.editor.get_relative(self.editor.get_end(), -2))
+        self.editor.prev_word()
+        self.assertEquals('t', self.editor.get())
+
+    def test_prev_one_character_word(self):
+        self.editor.set_text('1 2 3')
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.prev_word()
+        self.assertEquals('3', self.editor.get())
+        self.editor.prev_word()
+        self.assertEquals('2', self.editor.get())
+        self.editor.prev_word()
+        self.assertEquals('1', self.editor.get())
+
+    def test_deleting_next_word(self):
+        self.editor.delete_next_word()
+        self.assertEquals(' text', self.editor.get_text())
+
+    def test_deleting_next_word_in_the_middle(self):
+        self.editor.set_insert(self.editor.get_index(2))
+        self.editor.delete_next_word()
+        self.assertEquals('sa text', self.editor.get_text())
+
+    def test_deleting_prev_word(self):
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.delete_prev_word()
+        self.assertEquals('sample ', self.editor.get_text(), self.editor.get_text())
+
+    def test_deleting_prev_word_in_the_middle(self):
+        self.editor.set_insert(self.editor.get_relative(self.editor.get_end(), -2))
+        self.editor.delete_prev_word()
+        self.assertEquals('sample xt', self.editor.get_text(), self.editor.get_text())
+
+    def test_deleting_prev_word_at_the_beginning(self):
+        self.editor.set_insert(self.editor.get_index(3))
+        self.editor.delete_prev_word()
+        self.assertEquals('ple text', self.editor.get_text(), self.editor.get_text())
+
+    def test_next_word_stopping_at_underline(self):
+        self.editor.set_text('sample_text')
+        self.editor.set_insert(self.editor.get_start())
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_underline(self):
+        self.editor.set_text('sample_text')
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(7), self.editor.get_insert())
+
+    def test_next_word_stopping_at_end_of_line_preceded_by_a_space(self):
+        self.editor.set_text('sampleText ')
+        self.editor.set_insert(self.editor.get_index(6))
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(10), self.editor.get_insert())
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(11), self.editor.get_insert())
+
+    def test_next_word_stopping_at_capitals1(self):
+        self.editor.set_text('sampleText')
+        self.editor.set_insert(self.editor.get_start())
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_next_word_stopping_at_capitals2(self):
+        self.editor.set_text('sampleText')
+        self.editor.set_insert(self.editor.get_index(6))
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_end(), self.editor.get_insert())
+
+    def test_next_word_stopping_at_capitals3(self):
+        self.editor.set_text('MyHTTPClient')
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(2), self.editor.get_insert())
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_next_word_stopping_at_capitals4(self):
+        self.editor.set_text('INSERT')
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_end(), self.editor.get_insert())
+
+    def test_next_word_stopping_at_capitals5(self):
+        self.editor.set_text('INSERT ')
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_next_word_stopping_at_capitals6(self):
+        self.editor.set_text(' Hello')
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals(self):
+        self.editor.set_text('sampleText')
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals2(self):
+        self.editor.set_text('sampleText')
+        self.editor.set_insert(self.editor.get_index(7))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals3(self):
+        self.editor.set_text('MyHTTPText')
+        self.editor.set_insert(self.editor.get_index(6))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(2), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals4(self):
+        self.editor.set_text('INSERT')
+        self.editor.set_insert(self.editor.get_end())
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_start(), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals5(self):
+        self.editor.set_text(' INSERT')
+        self.editor.set_insert(self.editor.get_index(4))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(1), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals6(self):
+        self.editor.set_text('AClass')
+        self.editor.set_insert(self.editor.get_index(4))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(1), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_capitals7(self):
+        self.editor.set_text('MyClass')
+        self.editor.set_insert(self.editor.get_index(2))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(0), self.editor.get_insert())
+
+    def test_next_word_stopping_at_end_of_line(self):
+        self.editor.set_text('sample \n   text')
+        self.editor.set_insert(self.editor.get_index(6))
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(7), self.editor.get_insert())
+
+    def test_next_word_stopping_at_start_of_line(self):
+        self.editor.set_text('sample \n   text')
+        self.editor.set_insert(self.editor.get_index(7))
+        self.editor.next_word()
+        self.assertEquals(self.editor.get_index(8), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_end_of_line(self):
+        self.editor.set_text('sample \n   text')
+        self.editor.set_insert(self.editor.get_index(9))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(8), self.editor.get_insert())
+
+    def test_prev_word_stopping_at_start_of_line(self):
+        self.editor.set_text('sample \n   text')
+        self.editor.set_insert(self.editor.get_index(8))
+        self.editor.prev_word()
+        self.assertEquals(self.editor.get_index(7), self.editor.get_insert())
+
+    def test_upper_next_word(self):
+        self.editor.set_text('sample text')
+        self.editor.set_insert(self.editor.get_index(1))
+        self.editor.upper_next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+        self.assertEquals('sAMPLE text', self.editor.get_text())
+
+    def test_lower_next_word(self):
+        self.editor.set_text('SAMPLE TEXT')
+        self.editor.set_insert(self.editor.get_index(1))
+        self.editor.lower_next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+        self.assertEquals('Sample TEXT', self.editor.get_text())
+
+    def test_capitalize_next_word(self):
+        self.editor.set_text('sample text')
+        self.editor.set_insert(self.editor.get_index(1))
+        self.editor.capitalize_next_word()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+        self.assertEquals('sAmple text', self.editor.get_text())
+
+    def test_capitalize_next_word_after_spaces(self):
+        self.editor.set_text(' text')
+        self.editor.capitalize_next_word()
+        self.assertEquals(' Text', self.editor.get_text())
+
+    def test_going_to_the_start(self):
+        self.editor.set_insert(self.editor.get_index(3))
+        self.editor.goto_start()
+        self.assertEquals(self.editor.get_start(), self.editor.get_insert())
+
+    def test_going_to_the_end(self):
+        self.editor.set_insert(self.editor.get_index(3))
+        self.editor.goto_end()
+        self.assertEquals(self.editor.get_end(), self.editor.get_insert())
+
+    def test_undo(self):
+        self.editor.saving_editor()
+        self.editor.insert(self.editor.get_end(), '.')
+        self.assertEquals('sample text.', self.editor.get_text())
+        self.editor.undo()
+        self.assertEquals('sample text', self.editor.get_text(),self.editor.get_text())
+
+    def test_redo(self):
+        self.editor.saving_editor()
+        self.editor.insert(self.editor.get_end(), '.')
+        self.editor.undo()
+        self.editor.redo()
+        self.assertEquals('sample text.', self.editor.get_text(),self.editor.get_text())
+
+    def test_nothing_to_undo(self):
+        self.editor.undo()
+        self.editor.undo()
+        self.editor.undo()
+
+    def test_nothing_to_redo(self):
+        self.editor.redo()
+
+    def test_copying(self):
+        self.editor.set_mark()
+        self.editor.goto_end()
+        self.editor.copy_region()
+        self.editor.paste()
+        self.assertEquals('sample textsample text', self.editor.get_text())
+
+    def test_copying_in_the_middle(self):
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_end()
+        self.editor.copy_region()
+        self.editor.goto_start()
+        self.editor.paste()
+        self.assertEquals(' textsample text', self.editor.get_text())
+
+    def test_cutting(self):
+        self.editor.set_mark()
+        self.editor.next_word()
+        self.editor.cut_region()
+        self.assertEquals(' text', self.editor.get_text())
+        self.editor.paste()
+        self.assertEquals('sample text', self.editor.get_text())
+
+    def test_kill_line(self):
+        self.editor.set_text('sample\n text')
+        self.editor.set_insert(self.editor.get_index(1))
+        self.editor.kill_line()
+        self.assertEquals('s\n text', self.editor.get_text())
+        self.editor.kill_line()
+        self.assertEquals('s text', self.editor.get_text())
+        self.editor.kill_line()
+        self.assertEquals('s', self.editor.get_text())
+
+    def test_mark_not_set(self):
+        self.editor.cut_region()
+        self.editor.copy_region()
+        self.assertEquals('sample text', self.editor.get_text())
+
+    def test_clear_mark(self):
+        self.editor.set_mark()
+        self.editor.next_word()
+        self.editor.clear_mark()
+        self.editor.cut_region()
+        self.assertEquals('sample text', self.editor.get_text())
+
+    def test_when_insert_while_mark_precedes(self):
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_start()
+        self.editor.cut_region()
+        self.assertEquals(' text', self.editor.get_text())
+
+    def test_swap_mark_and_insert(self):
+        self.editor.set_mark()
+        self.editor.next_word()
+        self.editor.swap_mark_and_insert()
+        self.assertEquals(self.editor.get_start(), self.editor.get_insert())
+        self.editor.cut_region()
+        self.assertEquals(' text', self.editor.get_text())
+
+    def test_no_mark_swap_mark_and_insert(self):
+        self.editor.swap_mark_and_insert()
+        self.assertEquals('sample text', self.editor.get_text())
+
+    def test_swap_mark_and_insert_while_insert_precedes(self):
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_start()
+        self.editor.swap_mark_and_insert()
+        self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
+        self.editor.cut_region()
+        self.assertEquals(' text', self.editor.get_text())
+
+    def test_insert_tab(self):
+        self.editor.set_text('')
+        self.editor.insert_tab()
+        self.assertEquals((' ' * 4), self.editor.get_text())
+        self.editor.insert_tab(self.editor.get_end())
+        self.assertEquals((' ' * 8), self.editor.get_text())
+
+    def test_current_line_number(self):
+        self.assertEquals(1, self.editor.get_current_line_number())
+        self.editor.set_text('sample\n text \n end')
+        self.editor.set_insert(self.editor.get_index(9))
+        self.assertEquals(2, self.editor.get_current_line_number())
+        self.editor.set_insert(self.editor.get_end())
+        self.assertEquals(3, self.editor.get_current_line_number())
+
+    def test_resetting_undo_after_set_text(self):
+        self.editor.set_text('sample text')
+        self.editor.undo()
+        self.editor.undo()
+        self.assertEquals('sample text', self.editor.get_text())
+
+    def test_get_current_offset(self):
+        self.editor.set_text('sample text')
+        self.editor.set_insert(self.editor.get_start())
+        self.assertEquals(0, self.editor.get_current_offset())
+        self.editor.set_insert(self.editor.get_end())
+        self.assertEquals(11, self.editor.get_current_offset())
+
+    def test_get_current_offset_multiline(self):
+        self.editor.set_text('sample text\n another text \n and yet another')
+        self.editor.set_insert(self.editor.get_index(20))
+        self.assertEquals(20, self.editor.get_current_offset())
+        self.editor.set_insert(self.editor.get_index(30))
+        self.assertEquals(30, self.editor.get_current_offset())
+        self.editor.set_insert(self.editor.get_index(40))
+        self.assertEquals(40, self.editor.get_current_offset())
+
+    def test_after_indenting_insert_position(self):
+        self.editor.set_indenter(PythonCodeIndenter(self.editor))
+        self.editor.set_text("print 'hello'\n        print 'hello'\n")
+        self.editor.set_insert(self.editor.get_index(15))
+        self.editor.correct_line_indentation()
+        self.assertEquals(self.editor.get_index(14), self.editor.get_insert())
+
+    def test_after_indenting_insert_position2(self):
+        self.editor.set_indenter(PythonCodeIndenter(self.editor))
+        self.editor.set_text("def f():\n        print 'hello'\n")
+        self.editor.set_insert(self.editor.get_index(9))
+        self.editor.correct_line_indentation()
+        self.assertEquals(self.editor.get_index(13), self.editor.get_insert())
+
+    def test_after_indenting_insert_position3(self):
+        self.editor.set_indenter(PythonCodeIndenter(self.editor))
+        self.editor.set_text("def f():\n        print 'hello'\n")
+        self.editor.set_insert(self.editor.get_index(22))
+        self.editor.correct_line_indentation()
+        self.assertEquals(self.editor.get_index(18), self.editor.get_insert())
+
+    def test_goto_definition(self):
+        self.editor.set_text('\ndef a_func():\n    pass\na_func()\n')
+        self.editor.goto_line(2)
+        self.assertEquals(2, self.editor.get_current_line_number())
+
+    def test_yanking(self):
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_end()
+        self.editor.copy_region()
+        self.editor.goto_start()
+        self.editor.paste()
+        self.assertEquals(' textsample text', self.editor.get_text())
+
+
+class TextChangeInspectorTest(unittest.TestCase):
+
+    __factory = GraphicalEditorFactory(Tkinter.Frame())
+
+    def setUp(self):
+        super(TextChangeInspectorTest, self).setUp()
+        editor = TextChangeInspectorTest.__factory.create(get_sample_editingcontext())
+        self.text = editor.text
+        self.change_inspector = editor.change_inspector
+
+    def tearDown(self):
+        super(TextChangeInspectorTest, self).tearDown()
+
+    def test_is_changed(self):
+        self.text.insert('insert', 'sample text')
+        self.assertTrue(self.change_inspector.is_changed())
+        self.change_inspector.clear_changed()
+        self.assertFalse(self.change_inspector.is_changed())
+
+    def test_get_changed_region_after_inserts(self):
+        self.text.insert('insert', 'sample text')
+        self.change_inspector.clear_changed()
+        self.text.insert('1.3', 'a')
+        self.assertEquals(('1.3', '1.4'), self.change_inspector.get_changed_region())
+        self.text.insert('1.6', 'a')
+        self.assertEquals(('1.3', '1.7'), self.change_inspector.get_changed_region())
+
+    def test_get_changed_region_after_inserts2(self):
+        self.text.insert('insert', 'sample text')
+        self.change_inspector.clear_changed()
+        self.text.insert('1.3', 'a')
+        self.text.insert('1.2', 'aa')
+        self.assertEquals(('1.2', '1.6'), self.change_inspector.get_changed_region())
+
+    def test_get_changed_region_after_deletes(self):
+        self.text.insert('insert', 'sample text')
+        self.change_inspector.clear_changed()
+        self.text.delete('1.3', '1.4')
+        self.assertEquals(('1.3', '1.3'), self.change_inspector.get_changed_region())
+        self.text.delete('1.5', '1.6')
+        self.assertEquals(('1.3', '1.5'), self.change_inspector.get_changed_region())
+
+    def test_get_changed_region_after_deletes2(self):
+        self.text.insert('insert', 'sample text')
+        self.change_inspector.clear_changed()
+        self.text.delete('1.5', '1.6')
+        self.text.delete('1.1', '1.2')
+        self.assertEquals(('1.1', '1.4'), self.change_inspector.get_changed_region())
+
+
+class KillRingManagerTest(unittest.TestCase):
+
+    def setUp(self):
+        super(KillRingManagerTest, self).setUp()
+        self.ring = editor.KillRingManager()
+
+    def tearDown(self):
+        super(KillRingManagerTest, self).tearDown()
+
+    def test_empty_ring(self):
+        self.assertTrue(self.ring.yank(1) is None)
+
+    def test_trivial_yanking(self):
+        self.ring.killed('x')
+        self.ring.killed('y')
+        self.assertEquals('x', self.ring.yank(1))
+
+    def test_yanking_direction(self):
+        self.ring.killed('x')
+        self.ring.killed('y')
+        self.ring.killed('z')
+        self.assertEquals('y', self.ring.yank(1))
+        self.assertEquals('x', self.ring.yank(2))
+        self.assertEquals('z', self.ring.yank(3))
+
+    def test_yanking_the_last_element(self):
+        self.ring.killed('x')
+        self.ring.killed('y')
+        self.assertEquals('y', self.ring.yank(2))
+
+    def test_only_one_entry(self):
+        self.ring.killed('x')
+        self.assertEquals('x', self.ring.yank(1))
+
+    def test_unclear_conditions2(self):
+        ring = editor.KillRingManager(limit=2)
+        ring.killed('1')
+        ring.killed('2')
+        ring.killed('3')
+        self.assertEquals('3', ring.yank(2))
+
+
+def suite():
+    result = unittest.TestSuite()
+    result.addTests(unittest.makeSuite(GraphicalEditorTest))
+    result.addTests(unittest.makeSuite(TextChangeInspectorTest))
+    result.addTests(unittest.makeSuite(KillRingManagerTest))
+    return result
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/fileeditortest.py

+import unittest
+
+import Tkinter
+
+from ropeide.editor import *
+from ropeide.fileeditor import *
+from ropetest import testutils
+from ropeidetest.mockeditortest import get_sample_editingcontext
+
+
+class FileEditorTest(unittest.TestCase):
+
+    def setUp(self):
+        unittest.TestCase.setUp(self)
+        self.project_root = 'sample_project'
+        self.project = testutils.sample_project(self.project_root)
+        self._make_sample_project()
+        self.fileName = self.sample_file
+        get_sample_editingcontext()
+        self.editor = FileEditor(self.project, self.project.get_resource(self.fileName),
+                                 GraphicalEditorFactory(Tkinter.Frame()))
+
+    def _make_sample_project(self):
+        self.sample_file = 'sample_file.txt'
+        self.sample_path = os.path.join(self.project_root, 'sample_file.txt')
+        sample = open(self.sample_path, 'w')
+        sample.write('sample text\n')
+        sample.close()
+
+    def tearDown(self):
+        testutils.remove_project(self.project)
+        unittest.TestCase.tearDown(self)
+
+    def test_creation(self):
+        self.assertEquals('sample text\n',
+                          self.editor.get_editor().get_text())
+
+    def test_saving(self):
+        self.editor.get_editor().set_text('another text')
+        self.editor.save()
+        self.assertEquals('another text', self.project.get_resource(self.fileName).read())
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/filltest.py

+import unittest
+
+from ropeide import fill
+
+
+class FillTest(unittest.TestCase):
+
+    def setUp(self):
+        super(FillTest, self).setUp()
+        self.fill = fill.Fill(width=10)
+
+    def tearDown(self):
+        super(FillTest, self).tearDown()
+
+    def test_trivial_case(self):
+        self.assertEquals('', self.fill.fill(''))
+
+    def test_trivial_case2(self):
+        self.assertEquals('simple', self.fill.fill('simple'))
+
+    def test_trivial_case_for_multi_lines(self):
+        self.assertEquals('one two',
+                          self.fill.fill('one two'))
+
+    def test_folding_for_two_words(self):
+        self.assertEquals('simple\nparagraph',
+                          self.fill.fill('simple paragraph'))
+
+    def test_fixing_extra_spaces(self):
+        self.assertEquals('one two',
+                          self.fill.fill('one  two'))
+
+    def test_using_tabs(self):
+        self.assertEquals('simple\nparagraph',
+                          self.fill.fill('simple\tparagraph'))
+
+    def test_converting_tabs_to_spaces(self):
+        self.assertEquals('one two',
+                          self.fill.fill('one\ttwo'))
+
+    def test_joining_lines(self):
+        self.assertEquals('one two',
+                          self.fill.fill('one\ntwo'))
+
+    def test_indented_blocks(self):
+        self.assertEquals(' one two',
+                          self.fill.fill(' one two'))
+
+    def test_indented_broken_lines(self):
+        self.assertEquals(' simple\n block',
+                          self.fill.fill(' simple block'))
+
+    def test_fill_paragraph(self):
+        code = 'simple\nblock'
+        self.assertEquals(
+            (0, len(code), 'simple\nblock'),
+            self.fill.fill_paragraph('simple block', 0))
+
+    def test_fill_paragraph_multiple_paragraphs(self):
+        code = 'simple\n\nblock'
+        self.assertEquals(
+            (0, code.index('\n'), 'simple'),
+            self.fill.fill_paragraph(code, 0))
+
+    def test_fill_paragraph_multiple_paragraphs2(self):
+        code = 'simple\n\nblock'
+        self.assertEquals(
+            (code.index('block'), len(code), 'block'),
+            self.fill.fill_paragraph(code, len(code)))
+
+    def test_fill_paragraph_multiple_lists(self):
+        code = '* simple  block\n* main paragraph\n* another\n'
+        self.assertEquals(
+            (code.index('main') - 2, code.index('aph') + 3,
+             '* main\n  paragraph'),
+            self.fill.fill_paragraph(code, code.index('main')))
+
+    def test_fill_paragraph_multiple_lists2(self):
+        code = '* simple\n  block\n* main paragraph\n* another\n'
+        self.assertEquals(
+            (code.index('main') - 2, code.index('aph') + 3,
+             '* main\n  paragraph'),
+            self.fill.fill_paragraph(code, code.index('main')))
+
+    def test_when_dots_are_involved(self):
+        self.assertEquals('a b.  c d.',
+                          self.fill.fill('a b.  c d.'))
+
+    def test_when_non_end_line_dots_are_involved(self):
+        self.assertEquals('a b.c. d',
+                          self.fill.fill('a b.c. d'))
+
+    def test_when_end_line_dots_are_involved2(self):
+        self.assertEquals('a b.  c d.',
+                          self.fill.fill('a b.\nc d.'))
+
+    def test_handling_simple_unordered_lists(self):
+        self.assertEquals('* simple\n  paragraph',
+                          self.fill.fill('* simple paragraph'))
+
+    def test_handling_definition_lists(self):
+        self.assertEquals('name\n  value',
+                          self.fill.fill('name\n  value'))
+
+    def test_handling_simple_unordered_lists(self):
+        self.assertEquals('* simple\n  word in\n  list',
+                          self.fill.fill('* simple word\n  in list'))
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/formattertest.py

+import unittest
+
+from ropeide.formatter import Formatter
+
+
+class FormatterTest(unittest.TestCase):
+
+    def setUp(self):
+        super(FormatterTest, self).setUp()
+        self.formatter = Formatter()
+
+    def tearDown(self):
+        super(FormatterTest, self).tearDown()
+
+    def test_removing_extra_spaces(self):
+        formatted = self.formatter.format('  \n')
+        self.assertEquals('\n', formatted)
+
+    def test_removing_extra_spaces2(self):
+        formatted = self.formatter.format('def a_func():  \n    print(1)  \n  ')
+        self.assertEquals('def a_func():\n    print(1)\n', formatted)
+
+    def test_removing_extra_blank_lines2(self):
+        formatted = self.formatter.format('a = 1\n\n\n\nb = 2\nc=3\n\nd=4\n')
+        self.assertEquals('a = 1\n\n\nb = 2\nc=3\n\nd=4\n', formatted)
+
+    def test_removing_extra_blank_lines3(self):
+        formatted = self.formatter.format('\n\n\n\na = 1\n')
+        self.assertEquals('\n\na = 1\n', formatted)
+
+    def test_removing_extra_blank_lines_at_the_end_of_file(self):
+        formatted = self.formatter.format('\n\n\n')
+        self.assertEquals('\n', formatted)
+
+    def test_removing_extra_blank_lines_at_the_end_of_file2(self):
+        formatted = self.formatter.format('a = 1\n\n')
+        self.assertEquals('a = 1\n', formatted)
+
+    def test_inserting_new_line_at_the_end_of_file(self):
+        formatted = self.formatter.format('a = 1')
+        self.assertEquals('a = 1\n', formatted)
+
+    def xxx_test_formatting_simple_equality(self):
+        formatted = self.formatter.format('a_var       = 10\n')
+        self.assertEquals('a_var = 10\n', formatted)
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/highlightertest.py

+import unittest
+
+from ropeide.highlighter import (PythonHighlighting, HighlightingStyle,
+                                 ReSTHighlighting, NoHighlighting)
+class HighlightTest(unittest.TestCase):
+
+    def setUp(self):
+        self.highlighting = PythonHighlighting()
+        unittest.TestCase.setUp(self)
+
+    def tearDown(self):
+        unittest.TestCase.tearDown(self)
+
+    def _assertOutcomesEquals(self, text, expected, not_expected=[], start=None, end=None):
+        if start is None:
+            start = 0
+        if end is None:
+            end = len(text)
+        highlights = []
+        for result in self.highlighting.highlights(text, start, end):
+            highlights.append(result)
+        for highlight in expected:
+            self.assertTrue(highlight in highlights)
+        for highlight in not_expected:
+            self.assertTrue(highlight not in highlights)
+
+    def testKeywordHighlighting(self):
+        text = 'def sample_function():\n    pass\n'
+        highs = [(0, 3, 'defkeyword'), (27, 31, 'keyword')]
+        self._assertOutcomesEquals(text, highs)
+
+    def testKeywordHighlighting2(self):
+        text = 'import re\nclass Test(object):\n    def f(self):\npass\n'
+        highs = [(0, 6, 'keyword'), (10, 15, 'defkeyword'),
+                 (34, 37, 'defkeyword'), (47, 51, 'keyword')]
+        self._assertOutcomesEquals(text, highs)
+
+    def testKeywordHighlighting3(self):
+        text = '   for x in range(10):'
+        highs = [(3, 6, 'keyword'), (9, 11, 'keyword')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_not_highlighting_keywords_when_partof_other_words(self):
+        text = 'class_'
+        not_highs = [(0, 5, 'keyword')]
+        self._assertOutcomesEquals(text, [], not_highs)
+
+    def test_not_highlighting_keywords_when_partof_other_words2(self):
+        text = 'in_for_class = def3 + _def + def_ + def_while'
+        not_highs = [(0, 2, 'keyword'), (3, 6, 'keyword'), (7, 12, 'keyword'),
+                     (0, 2, 'keyword'), (15, 18, 'keyword'), (29, 32, 'keyword'),
+                     (36, 39, 'keyword'), (40, 45, 'keyword')]
+        self._assertOutcomesEquals(text, [], not_highs)
+
+    def test_no_highlighting(self):
+        noHigh = NoHighlighting()
+        text = 'def sample_function():\n    pass\n'
+        expected = []
+        for result in noHigh.highlights(text, None, None):
+            self.assertEquals(expected[0], result)
+            del expected[0]
+        self.assertFalse(expected)
+
+    def test_get_styles(self):
+        self.assertEquals(True, 'keyword' in self.highlighting.get_styles())
+        self.assertTrue(isinstance(self.highlighting.get_styles()['keyword'], HighlightingStyle))
+
+    def test_following_keywords(self):
+        text = 'if not'
+        highs = [(0, 2, 'keyword'), (3, 6, 'keyword')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_keywords_in_strings(self):
+        text = 's = " def "'
+        not_highs = [(6, 9, 'keyword')]
+        self._assertOutcomesEquals(text, [], not_highs)
+
+    def test_function_definition(self):
+        text = 'def func(args):'
+        highs = [(0, 3, 'defkeyword'), (4, 8, 'definition')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_class_definition(self):
+        self.assertTrue('definition' in self.highlighting.get_styles())
+        text = 'class Sample(object):'
+        highs = [(0, 5, 'defkeyword'), (6, 12, 'definition')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_comments(self):
+        self.assertTrue('comment' in self.highlighting.get_styles())
+        text = 'a = 2 # Hello world\ntest = 12'
+        highs = [(6, 19, 'comment')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_long_strings(self):
+        self.assertTrue('string' in self.highlighting.get_styles())
+        text = "a = '''2 # multiline \n comments'''\nb = 2"
+        highs = [(4, 34, 'string')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_highlighting_a_part_of_editor(self):
+        text = 'print a\nprint b\nprint c'
+        highs = [(8, 13, 'keyword')]
+        not_highs = [(0, 5, 'keyword'), (16, 21, 'keyword')]
+        self._assertOutcomesEquals(text, highs, not_highs, start=8, end=15)
+
+    def test_highlighting_builtins(self):
+        self.assertTrue('builtin' in self.highlighting.get_styles())
+        text = 'a = None'
+        highs = [(4, 8, 'builtin')]
+        self._assertOutcomesEquals(text, highs)
+
+    def test_suspected_region_for_triples(self):
+        text = '"""\nhello\n"""'
+        suspected = self.highlighting.get_suspected_region_after_change(text, 11, 12)
+        self.assertEquals((0, len(text)), suspected)
+
+    def test_suspected_region_for_triples2(self):
+        text = '"""\nhello\n"""'
+        suspected = self.highlighting.get_suspected_region_after_change(text, 2, 3)
+        self.assertEquals((0, len(text)), suspected)
+
+
+class ReSTHighlightTest(unittest.TestCase):
+
+    def setUp(self):
+        self.highlighting = ReSTHighlighting()
+        unittest.TestCase.setUp(self)
+
+    def tearDown(self):
+        unittest.TestCase.tearDown(self)
+
+    def in_highlights(self, text, expected):
+        highlights = []
+        for result in self.highlighting.highlights(text, 0, len(text)):
+            highlights.append(result)
+        return expected in highlights
+
+    def test_highlighting_section_titles(self):
+        self.assertTrue('title' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('My Title\n========\n', (0, 8, 'title')))
+
+    def test_highlighting_section_titles2(self):
+        self.assertTrue(self.in_highlights('========\nMy Title\n========\n', (9, 17, 'title')))
+
+    def test_highlighting_section_titles3(self):
+        self.assertTrue(self.in_highlights('\nMy Title\n========\n', (1, 9, 'title')))
+
+    def test_list_signs(self):
+        self.assertTrue('listsign' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('* item # 1\n', (0, 1, 'listsign')))
+
+    def test_list_signs2(self):
+        self.assertTrue(self.in_highlights('- item # 1\n', (0, 1, 'listsign')))
+
+    def test_ordered_lists(self):
+        self.assertTrue(self.in_highlights('1. item # 1\n', (0, 2, 'listsign')))
+
+    def test_directives(self):
+        self.assertTrue('directive' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('.. note:: This is a note\n', (0, 9, 'directive')))
+
+    def test_emphasis(self):
+        self.assertTrue('emphasis' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('*important*', (0, 11, 'emphasis')))
+
+    def test_strong_emphasis(self):
+        self.assertTrue('strongemphasis' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('**important**', (0, 13, 'strongemphasis')))
+
+    def test_strong_emphasis(self):
+        self.assertTrue('literal' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('``rope``', (0, 8, 'literal')))
+
+    def test_interpreted(self):
+        self.assertTrue('interpreted' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('`rope`', (0, 6, 'interpreted')))
+
+    def test_pre_role(self):
+        self.assertTrue('pre_role' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights(':emphasis:`rope`', (0, 10, 'pre_role')))
+
+    def test_post_role(self):
+        self.assertTrue('post_role' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('`rope`:emphasis:', (6, 16, 'post_role')))
+
+    def test_hyperlink_target(self):
+        self.assertTrue('hyperlink_target' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('http://rope.sf.net/index.html',
+                                           (0, 29, 'hyperlink_target')))
+
+    def test_hyperlink(self):
+        self.assertTrue('hyperlink' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('rope_', (0, 5, 'hyperlink')))
+
+    def test_hyperlink2(self):
+        self.assertTrue(self.in_highlights('`rope homepage`_', (0, 16, 'hyperlink')))
+
+    def test_hyperlink3(self):
+        self.assertFalse(self.in_highlights('rope_homepage', (0, 5, 'hyperlink')))
+
+    def test_hyperlink4(self):
+        self.assertTrue(self.in_highlights('rope_homepage_', (0, 14, 'hyperlink')))
+
+    def test_hyperlink_in_multilines(self):
+        self.assertTrue(self.in_highlights('`rope\nhomepage`_', (0, 16, 'hyperlink')))
+
+    def test_hyperlink_definition(self):
+        self.assertTrue('hyperlink_definition' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights('.. _rope: http://rope.sf.net\n',
+                                           (0, 9, 'hyperlink_definition')))
+
+    def test_hyperlink_definition2(self):
+        self.assertTrue(self.in_highlights('.. _rope homepage: http://rope.sf.net\n',
+                                           (0, 18, 'hyperlink_definition')))
+
+    def test_highlights_in_lists(self):
+        self.assertTrue(self.in_highlights('* rope_\n', (2, 7, 'hyperlink')))
+
+    def test_highlights_in_lists2(self):
+        self.assertTrue(self.in_highlights('- `rope homepage`_::\n', (2, 18, 'hyperlink')))
+
+    def test_not_highlighting_hyperlinks_in_inline_literals(self):
+        self.assertFalse(self.in_highlights('``rope_``', (2, 7, 'hyperlink')))
+
+    def test_highlighting_fields(self):
+        self.assertTrue('field' in self.highlighting.get_styles())
+        self.assertTrue(self.in_highlights(':Age: 3 months', (0, 5, 'field')))
+
+    def test_escaping(self):
+        self.assertFalse(self.in_highlights('\\`Age\\` 3 months', (1, 7, 'interpreted')))
+
+    def test_back_quotes_inside_literals(self):
+        self.assertTrue(self.in_highlights('``a`b``', (0, 7, 'literal')))
+
+    def test_following_literals(self):
+        self.assertTrue(self.in_highlights('``a````b``', (0, 5, 'literal')))
+        self.assertTrue(self.in_highlights('``a````b``', (5, 10, 'literal')))
+
+    def test_suspected_region_for_quotes(self):
+        text = '=====\ntitle\n====='
+        suspected = self.highlighting.get_suspected_region_after_change(text, 15, 16)
+        self.assertEquals((0, len(text)), suspected)
+
+    def test_anonymous_hyperlinks(self):
+        self.assertTrue('anonymous_hyperlink' in self.highlighting.get_styles())
+        self.assertFalse(self.in_highlights('rope__', (0, 6, 'hyperlink')))
+        self.assertTrue(self.in_highlights('rope__', (0, 6, 'anonymous_hyperlink')))
+
+    def test_literals_in_titles(self):
+        self.assertTrue(self.in_highlights('``rope``\n--------', (0, 8, 'title')))
+
+    def test_dots_in_hyperlinks(self):
+        self.assertTrue(self.in_highlights('rope.rope_', (0, 10, 'hyperlink')))
+
+    def test_hyperlink_definition(self):
+        self.assertTrue('literal_block' in self.highlighting.get_styles())
+        code = 'here ::\n  line1\n    line2\nnormal\n'
+        self.assertTrue(self.in_highlights(code, (code.index('::'), code.index('normal'),
+                                                  'literal_block')))
+
+    def test_comments(self):
+        self.assertTrue('comment' in self.highlighting.get_styles())
+        code = '.. this is a comment\nnormal\n'
+        self.assertTrue(self.in_highlights(code, (0, code.index('normal'), 'comment')))
+
+    def test_comments2(self):
+        code = 'normal\n\n.. this is a comment\n indented\n  comments\nnormal\n'
+        self.assertTrue(self.in_highlights(code, (code.index('..'),
+                                                  code.rindex('normal'),
+                                                  'comment')))
+
+    def test_comments3(self):
+        code = 'normal\n\n..\n indented\n  comments\nnormal\n'
+        self.assertTrue(self.in_highlights(code, (code.index('..'),
+                                                  code.rindex('normal'),
+                                                  'comment')))
+
+    def test_comments4(self):
+        code = 'normal\n\n..\n indented\n\nnormal\n'
+        self.assertTrue(self.in_highlights(
+                        code, (code.index('..'),
+                               code.rindex('normal'), 'comment')))
+
+    def test_footnote(self):
+        self.assertTrue('footnote' in self.highlighting.get_styles())
+        code = '.. [2] this is a footnote\nnormal\n'
+        self.assertTrue(self.in_highlights(code, (0, code.index(']') + 2,
+                                                  'footnote')))
+
+    def test_footnote2(self):
+        code = 'normal\n\n.. [hey] this is a footnote\n indented\n  footnote\nnormal\n'
+        self.assertTrue(self.in_highlights(code, (code.index('..'),
+                                                  code.rindex(']') + 2,
+                                                  'footnote')))
+
+    def test_suspected_region_lists(self):
+        text = '* 0\n* 1\n* 2\n* 3\n'
+        suspected = self.highlighting.get_suspected_region_after_change(
+            text, text.index('2'), text.index('2') + 1)
+        self.assertEquals((text.index('* 1'), text.index('* 3') - 1), suspected)
+
+
+def suite():
+    result = unittest.TestSuite()
+    result.addTests(unittest.makeSuite(HighlightTest))
+    result.addTests(unittest.makeSuite(ReSTHighlightTest))
+    return result
+
+if __name__ == '__main__':
+    unittest.main()
+

ropeidetest/indentertest.py

+import unittest
+
+from ropeide.indenter import PythonCodeIndenter, NormalIndenter
+from ropeidetest.mockeditortest import MockEditorFactory
+
+
+class PythonCodeIndenterTest(unittest.TestCase):
+
+    __factory = MockEditorFactory()
+
+    def setUp(self):
+        unittest.TestCase.setUp(self)
+        self.editor = self.__factory.create()
+        self.indenter = PythonCodeIndenter(self.editor)
+
+    def tearDown(self):
+        unittest.TestCase.tearDown(self)
+
+    def test_python_indenter(self):
+        self.editor.set_text('print "hello"\n')
+        self.indenter.correct_indentation(0)
+        self.assertEquals('print "hello"\n', self.editor.get_text())
+
+    def test_indenting_lines_with_indented_previous_line(self):
+        self.editor.set_text('def f():\n    g()\nh()\n')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    g()\n    h()\n', self.editor.get_text())
+
+    def test_indenting_lines_with_indented_previous_line(self):
+        self.editor.set_text('def f():\n    g()\nh()\n')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    g()\n    h()\n', self.editor.get_text())
+
+    def test_indenting_lines_when_prev_line_ends_with_a_colon(self):
+        self.editor.set_text('def f():\ng()')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('def f():\n    g()', self.editor.get_text())
+
+    def test_empty_prev_line(self):
+        self.editor.set_text('    \nprint "hello"\n')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('    \nprint "hello"\n', self.editor.get_text())
+
+    def test_indenting_lines_with_indented_previous_line_with_empty_line(self):
+        self.editor.set_text('def f():\n    g()\n\nh()\n')
+        self.indenter.correct_indentation(4)
+        self.assertEquals('def f():\n    g()\n\n    h()\n', self.editor.get_text())
+
+    def test_indenting_lines_when_prev_line_ends_with_a_colon_with_empty_line(self):
+        self.editor.set_text('def f():\n\ng()')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n\n    g()', self.editor.get_text())
+
+    def test_indenting_lines_at_start(self):
+        self.editor.set_text('    g()\n')
+        self.indenter.correct_indentation(1)
+        self.assertEquals('g()\n', self.editor.get_text())
+
+    def test_indenting_lines_with_start_previous_line(self):
+        self.editor.set_text('\n    g()\n')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('\ng()\n', self.editor.get_text())
+
+    def test_deindenting_after_pass(self):
+        self.editor.set_text('def f():\n    pass\n    f()')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    pass\nf()', self.editor.get_text())
+
+    def test_explicit_line_continuation(self):
+        self.editor.set_text('c = a + \\\nb')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('c = a + \\\n    b', self.editor.get_text())
+
+    def test_returning_after_backslashes(self):
+        self.editor.set_text('c = \\\n    b\\\n+ a')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('c = \\\n    b\\\n    + a', self.editor.get_text())
+
+    def test_returning_after_backslashes2(self):
+        self.editor.set_text('c = \\\n    b\na')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('c = \\\n    b\na', self.editor.get_text())
+
+    def test_backslash_should_indent_relative_to_the_first_word(self):
+        self.editor.set_text('print a, \\\nb')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('print a, \\\n      b', self.editor.get_text())
+
+    def test_backslash_indenting_on_indented_blocks(self):
+        self.editor.set_text('def f():\n    c = a + \\\nb')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    c = a + \\\n        b', self.editor.get_text())
+
+    def test_backslash_indenting_on_indented_blocks2(self):
+        self.editor.set_text('def f():\n    print a, \\\nb')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    print a, \\\n          b', self.editor.get_text())
+
+    def test_deindenting_when_encountering_else(self):
+        self.editor.set_text('if True:\n    print "hello"\n    else:')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('if True:\n    print "hello"\nelse:', self.editor.get_text())
+
+    def test_deindenting_when_encountering_elif(self):
+        self.editor.set_text('if True:\n    print "hello"\n    elif False:')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('if True:\n    print "hello"\nelif False:', self.editor.get_text())
+
+    def test_deindenting_when_encountering_except(self):
+        self.editor.set_text('try:\n    print "hello"\n    except Exception:')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('try:\n    print "hello"\nexcept Exception:', self.editor.get_text())
+
+    def test_deindenting_when_encountering_finally(self):
+        self.editor.set_text('try:\n    print "hello"\n    finally:')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('try:\n    print "hello"\nfinally:', self.editor.get_text())
+
+    def test_deindenting_after_return(self):
+        self.editor.set_text('def f():\n    return "hello"\n    b\n')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    return "hello"\nb\n', self.editor.get_text())
+
+    def test_deindenting_after_raise(self):
+        self.editor.set_text('def f():\n    raise Exception()\n    b\n')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    raise Exception()\nb\n', self.editor.get_text())
+
+    def test_multiple_indents(self):
+        self.editor.set_text('def f():\n')
+        self.indenter.correct_indentation(2)
+        self.indenter.correct_indentation(2)
+        self.assertEquals('def f():\n    ', self.editor.get_text())
+
+    def test_implicit_continuation(self):
+        self.editor.set_text('def f(a,\nb):')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('def f(a,\n      b):', self.editor.get_text())
+
+    def test_double_parens(self):
+        self.editor.set_text('def f(a, (c, b),\ne):')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('def f(a, (c, b),\n      e):', self.editor.get_text())
+
+    def test_double_parens(self):
+        self.editor.set_text('def f(a, (c, \nb), e):')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('def f(a, (c, \n          b), e):', self.editor.get_text())
+
+    def test_implicit_continuation2(self):
+        self.editor.set_text('d = {"age" : 20, \n"name" : "Ali"}')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('d = {"age" : 20, \n     "name" : "Ali"}', self.editor.get_text())
+
+    def test_deindents_after_implicit_continuation(self):
+        self.editor.set_text('f(a,\n      b)\na = 10')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('f(a,\n      b)\na = 10', self.editor.get_text())
+
+    def test_deindents_after_implicit_continuation_after_double_parens(self):
+        self.editor.set_text('def f(a, (c, \nb), e):\na=b')
+        self.indenter.correct_indentation(2)
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f(a, (c, \n          b), e):\n    a=b', self.editor.get_text())
+
+    def test_implicit_continuation_after_return(self):
+        self.editor.set_text('def f():\n    return (2,\n3)')
+        self.indenter.correct_indentation(3)
+        self.assertEquals('def f():\n    return (2,\n            3)', self.editor.get_text())
+
+    def test_implicit_continuation_after_dots(self):
+        self.editor.set_text('a_var.an_attr.\\\na_method()')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('a_var.an_attr.\\\n      a_method()', self.editor.get_text())
+
+    def test_deindenting_empty_lines(self):
+        self.editor.set_text('\n')
+        self.indenter.deindent(2)
+        self.assertEquals('\n', self.editor.get_text())
+
+    def test_deindenting_four_spaces(self):
+        self.editor.set_text('    print "hello"\n')
+        self.indenter.deindent(1)
+        self.assertEquals('print "hello"\n', self.editor.get_text())
+
+    def test_deindenting(self):
+        self.editor.set_text('def f()\n    print "hello"\n    def g():\n')
+        self.indenter.deindent(3)
+        self.assertEquals('def f()\n    print "hello"\ndef g():\n', self.editor.get_text())
+
+    def test_normal_indenter_indenting(self):
+        self.editor.set_text('a sample text')
+        indenter = NormalIndenter(self.editor)
+        indenter.indent(1)
+        self.assertEquals('    a sample text', self.editor.get_text())
+
+    def test_normal_indenter_deindenting(self):
+        self.editor.set_text('a sample \n        text')
+        indenter = NormalIndenter(self.editor)
+        indenter.deindent(2)
+        self.assertEquals('a sample \n    text', self.editor.get_text())
+
+    def test_indenting(self):
+        self.editor.set_text('print "a"')
+        self.indenter.indent(1)
+        self.assertEquals('    print "a"', self.editor.get_text())
+
+    def test_not_doing_anything_in_noraml_indenters_correct_indentation(self):
+        self.editor.set_text('a sample \ntext')
+        indenter = NormalIndenter(self.editor)
+        indenter.correct_indentation(2)
+        self.assertEquals('a sample \ntext', self.editor.get_text())
+
+    def test_inserting_tab(self):
+        self.editor.set_text('print "a"')
+        self.indenter.insert_tab(self.editor.get_end())
+        self.assertEquals('print "a"    ', self.editor.get_text())
+
+    def test_ignoring_parens_in_strings(self):
+        self.editor.set_text('print "("\na = 10')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('print "("\na = 10', self.editor.get_text())
+
+    def test_ignoring_parens_in_comments(self):
+        self.editor.set_text('# hello ( \na = 10')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('# hello ( \na = 10', self.editor.get_text())
+
+    def test_deindenting_after_implicit_continuation_after_return(self):
+        self.editor.set_text('def f():\n    return (2,\n            3)\na = 10')
+        self.indenter.correct_indentation(4)
+        self.assertEquals('def f():\n    return (2,\n            3)\na = 10',
+                          self.editor.get_text())
+
+    def test_ignoring_back_slash_in_comments(self):
+        self.editor.set_text('# hello \\\na = 10')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('# hello \\\na = 10', self.editor.get_text())
+
+    def test_entering_a_new_line(self):
+        self.editor.set_text('\n')
+        self.indenter.entering_new_line(0)
+        self.assertEquals('\n', self.editor.get_text())
+
+    def test_entering_a_new_line(self):
+        self.editor.set_text('def f():\n')
+        self.indenter.entering_new_line(2)
+        self.assertEquals('def f():\n    ', self.editor.get_text())
+
+    def test_entering_a_new_line2(self):
+        self.editor.set_text('def f():\n    print "hey"\n\n')
+        self.indenter.entering_new_line(4)
+        self.assertEquals('def f():\n    print "hey"\n\n', self.editor.get_text())
+
+    def test_line_breaks_after_open_parens(self):
+        self.editor.set_text('a_func(\narg)\n')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('a_func(\n    arg)\n', self.editor.get_text())
+
+    def test_line_breaks_after_equals(self):
+        self.editor.set_text('a_var = \\\nNone\n')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('a_var = \\\n    None\n', self.editor.get_text())
+
+    def test_indenting_a_line_like_the_previous_line(self):
+        self.editor.set_text('    line1\nline2')
+        indenter = NormalIndenter(self.editor)
+        indenter.correct_indentation(2)
+        self.assertEquals('    line1\n    line2', self.editor.get_text())
+
+    def test_indenting_the_first_line(self):
+        self.editor.set_text('    line1\n')
+        indenter = NormalIndenter(self.editor)
+        indenter.correct_indentation(1)
+        self.assertEquals('line1\n', self.editor.get_text())
+
+    # TODO: More work on the effects of current and previous lines
+    def xxx_test_else_after_break(self):
+        self.editor.set_text('for i in range(1):\n' +
+                             '    if True:\n' +
+                             '        break\n' +
+                             '    else:\n')
+        self.indenter.correct_indentation(4)
+        self.assertEquals('for i in range(1):\n' +
+                          '    if True:\n' +
+                          '        break\n' +
+                          '    else:\n',
+                          self.editor.get_text())
+
+    def test_line_break_after_inner_parens(self):
+        self.editor.set_text('a_func(a_func(\na_var)')
+        self.indenter.correct_indentation(2)
+        self.assertEquals('a_func(a_func(\n       a_var)', self.editor.get_text())
+
+
+if __name__ == '__main__':
+    unittest.main()
+

ropeidetest/mockeditor.py

+from ropeide.editor import EditorFactory
+
+
+class MockEditorFactory(EditorFactory):
+
+    def create(self, *args, **kws):
+        return MockEditor()
+
+class MockLineEditor(object):
+    def __init__(self, editor):
+        self.editor = editor
+
+    def get_line(self, number):
+        return self.editor.get_text().split('\n')[number - 1]
+
+    def length(self):
+        return len(self.editor.get_text().split('\n'))
+
+    def indent_line(self, line_number, count):
+        lines = self.editor.get_text().split('\n')
+        if count > 0:
+            lines[line_number - 1] = count * ' ' + lines[line_number - 1]
+        if count < 0:
+            lines[line_number - 1] = lines[line_number - 1][-count:]
+        self.editor.set_text('\n'.join(lines))
+
+
+class MockEditor(object):
+    '''A mock editor for testing editing commands'''
+    def __init__(self):
+        self.content = ''
+        self.insertIndex = MockTextIndex(self, 0)
+        self.status_bar_manager = None
+
+    def get_text(self):
+        return self.content
+
+    def set_text(self, text):
+        self.content = text
+
+    def get_start(self):
+        return MockTextIndex(self, 0)
+
+    def get_end(self):
+        return MockTextIndex(self, len(self.content))
+
+    def get_insert(self):
+        return self.insertIndex
+
+    def get_relative(self, index, offset):
+        newIndex = index._getIndex() + offset
+        if newIndex < 0:
+            newIndex = 0
+        if newIndex > len(self.content):
+            newIndex = len(self.content)
+        return MockTextIndex(self, newIndex)
+
+    def get_index(self, offset):
+        return self.get_relative(self.get_start(), offset)
+
+    def set_insert(self, index):
+        self.insertIndex = index
+
+    def get(self, start = None, end = None):
+        sindex = start
+        eindex = end
+        if sindex is None:
+            sindex = self.get_insert()
+        if eindex is None:
+            eindex = self.get_relative(sindex, 1)
+        if sindex == self.get_end():
+            return ''
+        else:
+            return self.content[sindex._getIndex():eindex._getIndex()]
+
+    def insert(self, textIndex, text):
+        self.content = self.content[0:textIndex._getIndex()] \
+            + text + self.content[textIndex._getIndex():]
+
+    def delete(self, start = None, end = None):
+        startIndex = self.insertIndex._getIndex()
+        if start is not None:
+            startIndex = start._getIndex()
+        endIndex = startIndex + 1
+        if end is not None:
+            endIndex = end._getIndex()
+        self.content = self.content[:startIndex] + self.content[endIndex:]
+
+    def highlight_match(self, match):
+        if not match:
+            return
+        if match.side == 'right':
+            self.insertIndex = match.end
+        else:
+            self.insertIndex = match.start
+
+    def search(self, keyword, start, case=True, forwards=True):
+        content = self.content
+        if not case:
+            content = self.content.lower()
+            keyword = keyword.lower()
+        try:
+            if forwards:
+                found = content.index(keyword, start._getIndex())
+            else:
+                found = content.rindex(keyword, 0, start._getIndex())
+            return MockTextIndex(self, found)
+        except ValueError:
+            return None
+
+    def line_editor(self):
+        return MockLineEditor(self)
+
+
+class MockTextIndex(object):
+    def __init__(self, editor, index):
+        self.editor = editor
+        self.index = index
+
+    def __cmp__(self, index):
+        assert self.editor == index.editor
+        return self.index - index.index
+
+    def _getIndex(self):
+        return self.index
+
+    def __str__(self):
+        return '<%s, %s>' % (self.__class__.__name__, str(self.index))
+

ropeidetest/mockeditortest.py

+import unittest
+
+from ropeide import editingcontexts
+from ropeide.editor import *
+from ropeidetest.mockeditor import *
+from ropeide import core
+
+
+class TextEditorTest(unittest.TestCase):
+
+    _editorFactory = None
+    def __init__(self, *args, **kws):
+        self.__factory = self.__class__._editorFactory
+        unittest.TestCase.__init__(self, *args, **kws)
+
+    def setUp(self):
+        unittest.TestCase.setUp(self)
+        self.editor = self.__factory.create(get_sample_editingcontext())
+        self.editor.set_text('sample text')
+
+    def tearDown(self):
+        unittest.TestCase.tearDown(self)
+
+    def testSetGetText(self):
+        self.assertEquals('sample text', self.editor.get_text())
+        self.editor.set_text('')
+        self.assertEquals('', self.editor.get_text())
+
+    def testTextIndices(self):
+        self.assertTrue(self.editor.get_start() < self.editor.get_end())
+        self.editor.set_text('')
+        self.assertEquals(self.editor.get_start(), self.editor.get_insert())
+        self.assertEquals(self.editor.get_insert(), self.editor.get_end())
+
+    def testTextIndicesMoving(self):
+        index = self.editor.get_insert()
+        newIndex = self.editor.get_relative(index, 2)
+        self.assertTrue(index < newIndex)
+        self.assertEquals(index, self.editor.get_relative(newIndex, -2))
+
+    def testTextIndicesMovingOutOfBounds(self):
+        index = self.editor.get_start()
+        self.assertEquals(self.editor.get_relative(index, 100), self.editor.get_end())
+        self.assertEquals(self.editor.get_relative(index, -100), self.editor.get_start())
+
+    def testAbsoluteTextIndicesMovingOutOfBounds(self):
+        index = self.editor.get_start()
+        self.assertEquals(self.editor.get_index(100), self.editor.get_end())
+        self.assertEquals(self.editor.get_index(-100), self.editor.get_start())
+
+    def testMovingInsertIndex(self):
+        self.assertEquals(self.editor.get_start(), self.editor.get_insert())
+        self.editor.set_insert(self.editor.get_index(3))
+        self.assertEquals(self.editor.get_index(3), self.editor.get_insert())
+
+    def testReading(self):
+        self.assertEquals('s', self.editor.get())
+
+    def testReadingAnyIndex(self):
+        self.assertEquals('a', self.editor.get(self.editor.get_index(1)))
+
+    def testReadingRanges(self):
+        self.assertEquals('sample', self.editor.get(self.editor.get_start(),
+                                                    self.editor.get_index(6)))
+
+    def testInsertingText(self):
+        self.editor.insert(self.editor.get_index(6), ' tricky')
+        self.assertEquals('sample tricky text', self.editor.get_text())
+
+    def testInsertingTextAtTheEnd(self):
+        self.editor.insert(self.editor.get_end(), ' note')
+        self.assertEquals('sample text note', self.editor.get_text())
+
+    def testInsertingTextAtTheBeginning(self):
+        self.editor.insert(self.editor.get_start(), 'new ')
+        self.assertEquals('new sample text', self.editor.get_text())
+
+    def testReadingAtTheEnd(self):
+        self.assertEquals('', self.editor.get(self.editor.get_end()))
+
+    def testMultiLineContent(self):
+        self.editor.insert(self.editor.get_end(), '\nanother piece of text')
+        self.assertEquals('sample text\nanother piece of text', self.editor.get_text())
+        self.assertEquals('text',
+                          self.editor.get(self.editor.get_relative(self.editor.get_end(), -4),
+                                          self.editor.get_end()))
+        self.assertEquals('a', self.editor.get(self.editor.get_index(12)))
+
+    def testDeleting(self):
+        self.editor.delete()
+        self.assertEquals('ample text', self.editor.get_text())
+        self.editor.set_insert(self.editor.get_index(3))
+        self.editor.delete()
+        self.editor.delete()
+        self.assertEquals('amp text', self.editor.get_text())
+
+    def testDeletingFromTheMiddle(self):
+        self.editor.delete(self.editor.get_index(1),
+                                self.editor.get_index(7))
+        self.assertEquals('stext', self.editor.get_text())
+        self.editor.delete(self.editor.get_index(2),
+                                self.editor.get_end())
+        self.assertEquals('st', self.editor.get_text())
+
+    def testDeletingFromTheEnd(self):
+        self.editor.delete(self.editor.get_end())
+        self.assertEquals('sample text', self.editor.get_text())
+
+    def testMultiLineDeleting(self):
+        self.editor.insert(self.editor.get_end(), '\nanother piece of text')
+        self.editor.delete(self.editor.get_index(11))
+        self.assertEquals('sample textanother piece of text', self.editor.get_text())
+
+    def test_searching(self):
+        found = self.editor.search('s', self.editor.get_insert())
+        self.assertEquals(self.editor.get_start(), found)
+
+    def test_searching_not_found(self):
+        found = self.editor.search('aa', self.editor.get_insert())
+        self.assertTrue(found is None)
+
+    def test_reverse_searching(self):
+        self.editor.set_insert(self.editor.get_index(len('sample text') - 1))
+        found = self.editor.search('te', self.editor.get_insert(), forwards=False)
+        self.assertEquals(self.editor.get_index(7), found)
+
+    def test_case_sensetivity(self):
+        self.editor.set_text('aAb')
+        self.assertTrue(self.editor.search('aB', self.editor.get_insert()) is None)
+        self.assertTrue(self.editor.search('aB', self.editor.get_insert(), case = False) is not None)
+
+    def test_simple_line_editor(self):
+        self.editor.set_text('line1')
+        line_editor = self.editor.line_editor()
+        self.assertEquals('line1', line_editor.get_line(1))
+
+    def test_line_editor_multiline(self):
+        self.editor.set_text('line1\nline2\nline3\n')
+        line_editor = self.editor.line_editor()
+        self.assertEquals('line1', line_editor.get_line(1))
+        self.assertEquals('line3', line_editor.get_line(3))
+        self.assertEquals('', line_editor.get_line(4))
+
+    def test_line_editor_indenting(self):
+        self.editor.set_text('line1\nline2\nline3\n')
+        line_editor = self.editor.line_editor()
+        line_editor.indent_line(2, 2)
+        self.assertEquals('  line2', line_editor.get_line(2))
+        self.assertEquals('line1\n  line2\nline3\n', self.editor.get_text())
+
+    def test_line_editor_indenting_with_negative_indent(self):
+        self.editor.set_text('line1\nline2\nline3\n')
+        line_editor = self.editor.line_editor()
+        line_editor.indent_line(2, -2)
+        self.assertEquals('ne2', line_editor.get_line(2))
+        self.assertEquals('line1\nne2\nline3\n', self.editor.get_text())
+
+    def test_line_editor_length(self):
+        self.editor.set_text('line1')
+        line_editor = self.editor.line_editor()
+        self.assertEquals(1, line_editor.length())
+
+
+def get_sample_editingcontext():
+    editingcontexts.init_contexts(core.get_core())
+    return editingcontexts.others
+
+
+def suite():
+    result = unittest.TestSuite()
+    import Tkinter
+    TextEditorTest._editorFactory = GraphicalEditorFactory(Tkinter.Frame())
+    result.addTests(unittest.makeSuite(TextEditorTest))
+    TextEditorTest._editorFactory = MockEditorFactory()
+    result.addTests(unittest.makeSuite(TextEditorTest))
+    return result
+
+
+if __name__ == '__main__':
+    runner = unittest.TextTestRunner()
+    runner.run(suite())
+

ropeidetest/movementstest.py

+import unittest
+import ropeide.movements
+
+
+class StatementsTest(unittest.TestCase):
+
+    def setUp(self):
+        super(StatementsTest, self).setUp()
+
+    def tearDown(self):
+        super(StatementsTest, self).tearDown()
+
+    def test_trivial_case(self):
+        statements = ropeide.movements.Statements('')
+        self.assertEquals(0, statements.next(0))
+
+    def test_real_statements(self):
+        code = 'a = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(code.index('\n'), statements.next(0))
+
+    def test_next_statement(self):
+        code = 'a = 1\nb = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(code.rindex('\n'),
+                          statements.next(code.index('\n')))
+
+    def test_trivial_prev(self):
+        statements = ropeide.movements.Statements('')
+        self.assertEquals(0, statements.prev(0))
+
+    def test_prev_statement_at_the_start(self):
+        code = 'a = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(0, statements.prev(0))
+
+    def test_prev_statement_at_the_start(self):
+        code = 'a = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(0, statements.prev(code.index('1')))
+
+    def test_prev_statement(self):
+        code = 'a = 1\nb = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(0, statements.prev(code.index('b')))
+        self.assertEquals(code.index('b'), statements.prev(code.rindex('1')))
+
+    def test_prev_statement_with_blank_lines(self):
+        code = 'a = 1\n\nb = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(0, statements.prev(code.index('b')))
+        self.assertEquals(code.index('b'), statements.prev(code.rindex('1')))
+
+    def test_prev_statement_with_indented_lines(self):
+        code = 'def f():\n    a = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(code.index('a'), statements.prev(len(code)))
+
+    def test_prev_statement_and_comments(self):
+        code = 'a = 1\n# ccc\nb = 1\n'
+        statements = ropeide.movements.Statements(code)
+        self.assertEquals(0, statements.prev(code.index('b')))
+
+
+class ScopesTest(unittest.TestCase):
+
+    def test_trivial_case(self):
+        code = ''
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(0, scopes.next(0))
+
+    def test_next_on_functions(self):
+        code = 'def f():\n    pass\n'
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(len(code) - 1, scopes.next(0))
+
+    def test_next_on_functions(self):
+        code = 'def f():\n    pass\n\ndef g():\n    pass\n'
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(code.index('\n\n'), scopes.next(0))
+        self.assertEquals(code.index('\n\n'), scopes.next(1))
+        self.assertEquals(len(code) - 1, scopes.next(code.index('g')))
+        self.assertEquals(len(code) - 1, scopes.next(code.index('\n\n')))
+
+    def test_trivial_prev(self):
+        code = ''
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(0, scopes.prev(0))
+
+    def test_prev_on_functions(self):
+        code = 'def f():\n    pass\n'
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(0, scopes.prev(10))
+        self.assertEquals(0, scopes.prev(len(code)))
+
+    def test_prev_on_functions(self):
+        code = 'def f():\n    pass\n\ndef g():\n    pass\n'
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(0, scopes.prev(code.index('()')))
+        self.assertEquals(code.index('def g'), scopes.prev(len(code)))
+
+    def test_prev_on_indented_functions(self):
+        code = 'class A(object):\n    def f():\n        pass\n\n\n' \
+               '    def g():\n        pass\n'
+        scopes = ropeide.movements.Scopes(code)
+        self.assertEquals(code.index('def f'),
+                          scopes.prev(code.index('def g')))
+
+
+def suite():
+    result = unittest.TestSuite()
+    result.addTests(unittest.makeSuite(StatementsTest))
+    result.addTests(unittest.makeSuite(ScopesTest))
+    return result
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/notestest.py

+import unittest
+from ropetest import testutils
+import ropeide.notes
+
+
+class AnnotationsTest(unittest.TestCase):
+
+    def setUp(self):
+        super(AnnotationsTest, self).setUp()
+        self.project = testutils.sample_project()
+        self.tags = ropeide.notes.Codetags()
+
+    def tearDown(self):
+        testutils.remove_project(self.project)
+        super(AnnotationsTest, self).tearDown()
+
+    def test_tags_empty_input(self):
+        self.assertEquals([], self.tags.tags(''))
+
+    def test_tags_trivial_case(self):
+        self.assertEquals([(1, 'TODO: todo')], self.tags.tags('# TODO: todo\n'))
+
+    def test_two_codetags(self):
+        self.assertEquals(
+            [(1, 'XXX: todo'), (3, 'FIXME: fix me')],
+             self.tags.tags('# XXX: todo\n\n# FIXME: fix me\n'))
+
+    def test_errors_empty_input(self):
+        errors = ropeide.notes.Errors()
+        self.assertEquals([], errors.errors(''))
+
+    def test_errors_trival_error(self):
+        errors = ropeide.notes.Errors()
+        self.assertEquals([(1, 'invalid syntax')],
+                          errors.errors('error input\n'))
+
+    def test_warnings_empty_input(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([], warnings.warnings(''))
+
+    def test_warnings_redefining_functions_in_global_scope(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([(3, 'Rebinding defined name <f>')],
+                          warnings.warnings('def f():\n    pass\nf = 1\n'))
+
+    def test_warnings_redefining_classes_in_global_scope(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([(3, 'Rebinding defined name <C>')],
+                          warnings.warnings('class C(object):\n    pass\nC = 1\n'))
+
+    def test_warnings_redefining_nested_scopes(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals(
+            [(4, 'Rebinding defined name <g>')], warnings.warnings(
+            'def f():\n    def g():\n        pass\n    g = 1\n'))
+
+    def test_warnings_not_redefining_in_nested_scopes(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([], warnings.warnings(
+                          'def f():\n    def g():\n        pass\ng = 1\n'))
+
+    def test_warnings_redefining_functions_by_functions(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([(3, 'Rebinding defined name <f>')],
+                          warnings.warnings('def f():\n    pass\n'
+                                            'def f():\n    pass\n'))
+
+    def test_self_assignment_warnings(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([(2, 'Assigning <a> to itself')],
+                          warnings.warnings('a = 1\na = a\n'))
+
+    def test_self_assignment_warnings(self):
+        warnings = ropeide.notes.Warnings()
+        self.assertEquals([(2, 'Assigning <a.b> to itself')],
+                          warnings.warnings('a = None\na.b = a.b\n'))
+
+
+if __name__ == '__main__':
+    unittest.main()

ropeidetest/outlinetest.py

+import unittest
+
+from ropeide.outline import PythonOutline
+from ropetest import testutils
+
+
+class OutlineTest(unittest.TestCase):
+
+    def setUp(self):
+        super(OutlineTest, self).setUp()
+        self.project = testutils.sample_project()
+        self.outline = PythonOutline(self.project)
+
+    def tearDown(self):
+        testutils.remove_project(self.project)
+        super(OutlineTest, self).tearDown()
+
+    def test_simple_outline(self):
+        nodes = self.outline.get_root_nodes('')
+        self.assertEquals(0, len(nodes))
+
+    def test_simple_outlines(self):
+        nodes = self.outline.get_root_nodes('def a_func():\n    pass\n')
+        self.assertEquals(1, len(nodes))
+        self.assertEquals('a_func', nodes[0].get_name())
+        self.assertEquals(1, nodes[0].get_line_number())
+        self.assertEquals(0, len(nodes[0].get_children()))
+
+    def test_nested_outlines(self):
+        nodes = self.outline.get_root_nodes('class Sample(object):\n    def a_method(self):\n        pass\n')
+        self.assertEquals(1, len(nodes))
+        self.assertEquals('Sample', nodes[0].get_name())
+        sample_class = nodes[0]
+        self.assertEquals(1, sample_class.get_line_number())
+        self.assertEquals(1, len(sample_class.get_children()))
+        a_method = sample_class.get_children()[0]
+        self.assertEquals('a_method', a_method.get_name())
+        self.assertEquals(2, a_method.get_line_number())
+
+    def test_sorting_by_line_number(self):
+        nodes = self.outline.get_root_nodes('def a_func2():\n    pass\ndef a_func1():\n    pass\n')
+        self.assertEquals('a_func2', nodes[0].get_name())
+        self.assertEquals('a_func1', nodes[1].get_name())
+
+    def test_not_showing_inherited_names(self):
+        src = 'class Base(object):\n    def a_method(self):\n        pass\n\n' + \
+              'class Derived(Base):\n    pass\n'
+        nodes = self.outline.get_root_nodes(src)