<s> import unittest <EOL> from pyface . action . api import Action , ActionItem , ActionManager , Group , MenuManager , MenuBarManager <EOL> from pyface . tasks . action . api import GroupSchema , MenuSchema , MenuBarSchema , SchemaAddition <EOL> from pyface . tasks . action . task_action_manager_builder import TaskActionManagerBuilder <EOL> from pyface . tasks . api import Task <EOL> class ActionManagerBuilderTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in xrange ( <NUM_LIT:1> , <NUM_LIT:7> ) : <EOL> action_id = '<STR_LIT>' % i <EOL> setattr ( self , action_id , Action ( id = action_id , name = '<STR_LIT>' % i ) ) <EOL> def assertActionElementsEqual ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> children1 = children2 = [ ] <EOL> self . assertEquals ( type ( first ) , type ( second ) ) <EOL> self . assertEquals ( first . id , second . id ) <EOL> if isinstance ( first , ActionItem ) : <EOL> self . assertEquals ( first . action . name , second . action . name ) <EOL> elif isinstance ( first , ActionManager ) : <EOL> if not isinstance ( first , MenuBarManager ) : <EOL> self . assertEquals ( first . name , second . name ) <EOL> children1 , children2 = first . groups , second . groups <EOL> elif isinstance ( first , Group ) : <EOL> self . assertEquals ( first . separator , second . separator ) <EOL> children1 , children2 = first . items , second . items <EOL> self . assertEquals ( len ( children1 ) , len ( children2 ) ) <EOL> for i in xrange ( len ( children1 ) ) : <EOL> self . assertActionElementsEqual ( children1 [ i ] , children2 [ i ] ) <EOL> def test_simple_menu_bar ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( self . action1 , self . action2 , id = '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> MenuSchema ( self . action3 , self . action4 , id = '<STR_LIT>' , name = '<STR_LIT>' ) ) <EOL> builder = TaskActionManagerBuilder ( task = Task ( menu_bar = schema ) ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( MenuManager ( self . action1 , self . action2 , <EOL> id = '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> MenuManager ( self . action3 , self . action4 , <EOL> id = '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_additions_menu_bar ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) ) <EOL> extras = [ SchemaAddition ( factory = lambda : self . action3 , <EOL> before = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action4 , <EOL> before = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action5 , <EOL> path = '<STR_LIT>' ) ] <EOL> builder = TaskActionManagerBuilder ( task = Task ( menu_bar = schema , <EOL> extra_actions = extras ) ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( MenuManager ( Group ( self . action3 , self . action4 , <EOL> self . action1 , self . action2 , <EOL> self . action5 , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_extra_menu ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> ) <EOL> extra_menu = MenuSchema ( <EOL> GroupSchema ( self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' , <EOL> ) <EOL> extra_actions = [ <EOL> SchemaAddition ( path = '<STR_LIT>' , <EOL> factory = lambda : extra_menu , <EOL> id = '<STR_LIT>' ) , <EOL> ] <EOL> builder = TaskActionManagerBuilder ( <EOL> task = Task ( menu_bar = schema , extra_actions = extra_actions ) <EOL> ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( <EOL> MenuManager ( Group ( self . action1 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> MenuManager ( Group ( self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' <EOL> ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_merging_redundant_items ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' , id = '<STR_LIT>' ) <EOL> ) <EOL> extra_menu = MenuSchema ( <EOL> GroupSchema ( self . action2 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' , <EOL> id = '<STR_LIT>' , <EOL> ) <EOL> extra_actions = [ <EOL> SchemaAddition ( path = '<STR_LIT>' , <EOL> factory = lambda : extra_menu , <EOL> id = '<STR_LIT>' ) , <EOL> ] <EOL> builder = TaskActionManagerBuilder ( <EOL> task = Task ( menu_bar = schema , extra_actions = extra_actions ) <EOL> ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( <EOL> MenuManager ( Group ( self . action1 , self . action2 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' <EOL> ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_unwanted_merge ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' ) <EOL> ) <EOL> extra_menu = MenuSchema ( <EOL> GroupSchema ( self . action2 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' <EOL> ) <EOL> extra_actions = [ <EOL> SchemaAddition ( path = '<STR_LIT>' , <EOL> factory = lambda : extra_menu , <EOL> id = '<STR_LIT>' ) , <EOL> ] <EOL> builder = TaskActionManagerBuilder ( <EOL> task = Task ( menu_bar = schema , extra_actions = extra_actions ) <EOL> ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( <EOL> MenuManager ( Group ( self . action1 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' , id = '<STR_LIT>' ) , <EOL> MenuManager ( Group ( self . action2 , id = '<STR_LIT>' ) , <EOL> name = '<STR_LIT>' , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' <EOL> ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_merging_items_with_same_id_but_different_class ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> ) <EOL> extra_group = GroupSchema ( self . action2 , id = '<STR_LIT>' ) <EOL> extra_actions = [ <EOL> SchemaAddition ( path = '<STR_LIT>' , <EOL> factory = ( lambda : extra_group ) , <EOL> id = '<STR_LIT>' ) , <EOL> ] <EOL> builder = TaskActionManagerBuilder ( <EOL> task = Task ( menu_bar = schema , extra_actions = extra_actions ) <EOL> ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( <EOL> MenuManager ( Group ( self . action1 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> Group ( self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' <EOL> ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_merging_redundant_items_that_are_not_schemas ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuManager ( Group ( self . action1 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> ) <EOL> extra_menu = MenuSchema ( <EOL> GroupSchema ( self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' , <EOL> ) <EOL> extra_actions = [ <EOL> SchemaAddition ( path = '<STR_LIT>' , <EOL> factory = lambda : extra_menu , <EOL> id = '<STR_LIT>' ) , <EOL> ] <EOL> builder = TaskActionManagerBuilder ( <EOL> task = Task ( menu_bar = schema , extra_actions = extra_actions ) <EOL> ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( <EOL> MenuManager ( Group ( self . action1 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> MenuManager ( Group ( self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' <EOL> ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_absolute_ordering ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) ) <EOL> extras = [ SchemaAddition ( factory = lambda : self . action3 , <EOL> absolute_position = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action4 , <EOL> absolute_position = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action5 , <EOL> absolute_position = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) ] <EOL> builder = TaskActionManagerBuilder ( task = Task ( menu_bar = schema , <EOL> extra_actions = extras ) ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( MenuManager ( Group ( self . action4 , self . action5 , <EOL> self . action1 , self . action2 , <EOL> self . action3 , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> def test_absolute_and_before_after ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = MenuBarSchema ( <EOL> MenuSchema ( GroupSchema ( self . action1 , self . action2 , id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) ) <EOL> extras = [ SchemaAddition ( factory = lambda : self . action3 , <EOL> id = '<STR_LIT>' , <EOL> after = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action4 , <EOL> after = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action5 , <EOL> id = '<STR_LIT>' , <EOL> absolute_position = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) , <EOL> SchemaAddition ( factory = lambda : self . action6 , <EOL> absolute_position = '<STR_LIT>' , <EOL> before = '<STR_LIT>' , <EOL> path = '<STR_LIT>' ) <EOL> ] <EOL> builder = TaskActionManagerBuilder ( task = Task ( menu_bar = schema , <EOL> extra_actions = extras ) ) <EOL> actual = builder . create_menu_bar_manager ( ) <EOL> desired = MenuBarManager ( MenuManager ( Group ( self . action1 , self . action2 , <EOL> self . action3 , self . action4 , <EOL> self . action6 , self . action5 , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) , <EOL> id = '<STR_LIT>' ) <EOL> self . assertActionElementsEqual ( actual , desired ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
