diff -r dbdb6f7f9a1a Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py Sun Jun 30 18:37:51 2013 -0400 +++ b/Lib/idlelib/FormatParagraph.py Mon Jul 01 12:05:16 2013 -0400 @@ -149,3 +149,8 @@ m = re.match(r"^(\s*#*)", line) if m is None: return "" return m.group(1) + +if __name__ == "__main__": + import unittest + unittest.main('idlelib.idle_test.test_formatparagraph.py', verbosity=2, + exit=False) diff -r dbdb6f7f9a1a Lib/idlelib/idle_test/mock_editorwindow.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/idle_test/mock_editorwindow.py Mon Jul 01 12:05:16 2013 -0400 @@ -0,0 +1,62 @@ +"""Classes that replace the editorwindow gui objects used by an object being tested. +""" + +class Text: + '''this is a mock class for Text which is used by editor window the + only methods that function are get, setText, and insert''' + data = "# hello world" + + def __init__(self): + self.data = "# hello world" + + def getText(self): + return self.data + + def get(self, start, end): + return self.data + + def setText(self, text): + self.data = text + + def index(self, typeOfIndex): + pass + + def tag_remove(self, selection_type, start, end): + '''this function does nothing, it just pretends to remove the selection''' + pass + + def mark_set(self, select_type, start): + '''this function does nothing, it just pretends to set the selection''' + pass + + def undo_block_start(self): + '''this function does nothing, it just pretends to undo block start''' + pass + + def delete(self, start, end): + '''this function does nothing, it just pretends to delete text from + editor window''' + pass + + def insert(self, start, newdata): + '''this function does nothing, it just pretends to insert text''' + self.data = newdata + + def undo_block_stop(self): + '''this function does nothing, it just pretends to undo block stop''' + pass + + def see(self, typeOfSee): + '''this function does nothing, it just pretends to see''' + pass + + +class EditorWindow: + '''this is a mock class for editor window, currently it only supports testing + for test_formatparagraph.py''' + text = Text() + + def get_selection_indices(): + first = 2 + last = 3 + return first, last diff -r dbdb6f7f9a1a Lib/idlelib/idle_test/test_formatparagraph.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/idle_test/test_formatparagraph.py Mon Jul 01 12:05:16 2013 -0400 @@ -0,0 +1,25 @@ +import unittest +from idlelib import FormatParagraph as format_paragraph +from idlelib.idle_test.mock_editorwindow import EditorWindow + +class TestFormatParagraph(unittest.TestCase): + + def test_reformat_paragrah(self): + '''tests the basic reformat_paragraph function without the editor window''' + reformat_result = format_paragraph.reformat_paragraph("# hello world" + , 8) + reformat_expected_result = ("# hello\nworld") + self.assertEqual(reformat_result, reformat_expected_result) + + def test_format_paragraph_event(self): + self.dummy_editor_window = EditorWindow + self.dummy_editor_window.text.setText(" \"\"\"this is a test of a reformat for a triple quoted string will it reformat to less than 80 characters for me?\"\"\"") + self.fp = format_paragraph.FormatParagraph(self.dummy_editor_window) + self.fp.format_paragraph_event('ParameterDoesNothing') + reformat_result = self.dummy_editor_window.text.getText() + reformat_expected_result = (" \"\"\"this is a test of a reformat for a triple quoted string will\n it reformat to less than 80 characters for me?\"\"\"") + self.assertEqual(reformat_result, reformat_expected_result) + + +if __name__ == '__main__': + unittest.main(verbosity=2, exit=2)