<s> import unittest <EOL> from idlelib import FormatParagraph as fp <EOL> from idlelib . EditorWindow import EditorWindow <EOL> from Tkinter import Tk , Text , TclError <EOL> from test . test_support import requires <EOL> class Is_Get_Test ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> test_comment = '<STR_LIT>' <EOL> test_nocomment = '<STR_LIT>' <EOL> trailingws_comment = '<STR_LIT>' <EOL> leadingws_comment = '<STR_LIT>' <EOL> leadingws_nocomment = '<STR_LIT>' <EOL> def test_is_all_white ( self ) : <EOL> self . assertTrue ( fp . is_all_white ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( fp . is_all_white ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( fp . is_all_white ( self . test_comment ) ) <EOL> def test_get_indent ( self ) : <EOL> Equal = self . assertEqual <EOL> Equal ( fp . get_indent ( self . test_comment ) , '<STR_LIT>' ) <EOL> Equal ( fp . get_indent ( self . trailingws_comment ) , '<STR_LIT>' ) <EOL> Equal ( fp . get_indent ( self . leadingws_comment ) , '<STR_LIT:U+0020>' ) <EOL> Equal ( fp . get_indent ( self . leadingws_nocomment ) , '<STR_LIT:U+0020>' ) <EOL> def test_get_comment_header ( self ) : <EOL> Equal = self . assertEqual <EOL> Equal ( fp . get_comment_header ( self . test_comment ) , '<STR_LIT:#>' ) <EOL> Equal ( fp . get_comment_header ( self . trailingws_comment ) , '<STR_LIT:#>' ) <EOL> Equal ( fp . get_comment_header ( self . leadingws_comment ) , '<STR_LIT>' ) <EOL> Equal ( fp . get_comment_header ( self . leadingws_nocomment ) , '<STR_LIT:U+0020>' ) <EOL> Equal ( fp . get_comment_header ( self . test_nocomment ) , '<STR_LIT>' ) <EOL> class FindTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> from idlelib . idle_test . mock_tk import Text <EOL> cls . text = Text ( ) <EOL> def runcase ( self , inserttext , stopline , expected ) : <EOL> text = self . text <EOL> text . insert ( '<STR_LIT:1.0>' , inserttext ) <EOL> for line in range ( <NUM_LIT:1> , stopline ) : <EOL> linelength = int ( text . index ( "<STR_LIT>" % line ) . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> ] ) <EOL> for col in ( <NUM_LIT:0> , linelength // <NUM_LIT:2> , linelength ) : <EOL> tempindex = "<STR_LIT>" % ( line , col ) <EOL> self . assertEqual ( fp . find_paragraph ( text , tempindex ) , expected ) <EOL> text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> def test_find_comment ( self ) : <EOL> comment = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:3> , ( '<STR_LIT:1.0>' , '<STR_LIT>' , '<STR_LIT:#>' , comment [ <NUM_LIT:0> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:4> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:#>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:4> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:#>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:#>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> comment = ( <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" ) <EOL> self . runcase ( comment , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:#>' , comment [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> def test_find_paragraph ( self ) : <EOL> teststring = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' ) <EOL> self . runcase ( teststring , <NUM_LIT:4> , ( '<STR_LIT:1.0>' , '<STR_LIT>' , '<STR_LIT>' , teststring [ <NUM_LIT:0> : <NUM_LIT> ] ) ) <EOL> teststring = ( <EOL> "<STR_LIT:\n>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' ) <EOL> self . runcase ( teststring , <NUM_LIT:5> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , teststring [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> teststring = ( <EOL> '<STR_LIT:\n>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' ) <EOL> self . runcase ( teststring , <NUM_LIT:5> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:U+0020>' , teststring [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> teststring = ( <EOL> '<STR_LIT:\n>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' ) <EOL> self . runcase ( teststring , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , teststring [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> teststring = ( <EOL> '<STR_LIT:\n>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' ) <EOL> self . runcase ( teststring , <NUM_LIT:3> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:U+0020>' , teststring [ <NUM_LIT:1> : <NUM_LIT> ] ) ) <EOL> class ReformatFunctionTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_reformat_paragrah ( self ) : <EOL> Equal = self . assertEqual <EOL> reform = fp . reformat_paragraph <EOL> hw = "<STR_LIT>" <EOL> Equal ( reform ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) , '<STR_LIT:U+0020>' ) <EOL> Equal ( reform ( "<STR_LIT>" , <NUM_LIT:20> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:1> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:6> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:7> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:12> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT> ) , "<STR_LIT>" ) <EOL> hw = "<STR_LIT>" <EOL> Equal ( reform ( hw , <NUM_LIT:1> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:6> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:7> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT:12> ) , "<STR_LIT>" ) <EOL> Equal ( reform ( hw , <NUM_LIT> ) , "<STR_LIT>" ) <EOL> class ReformatCommentTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_reformat_comment ( self ) : <EOL> Equal = self . assertEqual <EOL> test_string = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> result = fp . reformat_comment ( test_string , <NUM_LIT> , "<STR_LIT:U+0020>" ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> Equal ( result , expected ) <EOL> test_comment = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> result = fp . reformat_comment ( test_comment , <NUM_LIT> , "<STR_LIT:#>" ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> Equal ( result , expected ) <EOL> class FormatClassTest ( unittest . TestCase ) : <EOL> def test_init_close ( self ) : <EOL> instance = fp . FormatParagraph ( '<STR_LIT>' ) <EOL> self . assertEqual ( instance . editwin , '<STR_LIT>' ) <EOL> instance . close ( ) <EOL> self . assertEqual ( instance . editwin , None ) <EOL> class TextWrapper : <EOL> def __init__ ( self , master ) : <EOL> self . text = Text ( master = master ) <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . text , name ) <EOL> def undo_block_start ( self ) : pass <EOL> def undo_block_stop ( self ) : pass <EOL> class Editor : <EOL> def __init__ ( self , root ) : <EOL> self . text = TextWrapper ( root ) <EOL> get_selection_indices = EditorWindow . get_selection_indices . im_func <EOL> class FormatEventTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> test_string = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> multiline_test_string = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> multiline_test_comment = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> requires ( '<STR_LIT>' ) <EOL> cls . root = Tk ( ) <EOL> editor = Editor ( root = cls . root ) <EOL> cls . text = editor . text . text <EOL> cls . formatter = fp . FormatParagraph ( editor ) . format_paragraph_event <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . root . destroy ( ) <EOL> del cls . root <EOL> del cls . text <EOL> del cls . formatter <EOL> def test_short_line ( self ) : <EOL> self . text . insert ( '<STR_LIT:1.0>' , "<STR_LIT>" ) <EOL> self . formatter ( "<STR_LIT>" ) <EOL> self . assertEqual ( self . text . get ( '<STR_LIT:1.0>' , '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> self . text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> def test_long_line ( self ) : <EOL> text = self . text <EOL> text . insert ( '<STR_LIT:1.0>' , self . test_string ) <EOL> text . mark_set ( '<STR_LIT>' , '<STR_LIT:1.0>' ) <EOL> self . formatter ( '<STR_LIT>' , limit = <NUM_LIT> ) <EOL> result = text . get ( '<STR_LIT:1.0>' , '<STR_LIT>' ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result , expected ) <EOL> text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> text . insert ( '<STR_LIT:1.0>' , self . test_string ) <EOL> text . tag_add ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . formatter ( '<STR_LIT>' , limit = <NUM_LIT> ) <EOL> result = text . get ( '<STR_LIT:1.0>' , '<STR_LIT>' ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result , expected ) <EOL> text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> def test_multiple_lines ( self ) : <EOL> text = self . text <EOL> text . insert ( '<STR_LIT:1.0>' , self . multiline_test_string ) <EOL> text . tag_add ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . formatter ( '<STR_LIT>' , limit = <NUM_LIT> ) <EOL> result = text . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result , expected ) <EOL> text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> def test_comment_block ( self ) : <EOL> text = self . text <EOL> text . insert ( '<STR_LIT:1.0>' , self . multiline_test_comment ) <EOL> self . formatter ( '<STR_LIT>' , limit = <NUM_LIT> ) <EOL> result = text . get ( '<STR_LIT:1.0>' , '<STR_LIT>' ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result , expected ) <EOL> text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> text . insert ( '<STR_LIT:1.0>' , self . multiline_test_comment ) <EOL> text . tag_add ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . formatter ( '<STR_LIT>' , limit = <NUM_LIT> ) <EOL> result = text . get ( '<STR_LIT:1.0>' , '<STR_LIT>' ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result , expected ) <EOL> text . delete ( '<STR_LIT:1.0>' , '<STR_LIT:end>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( verbosity = <NUM_LIT:2> , exit = <NUM_LIT:2> ) </s>
