Changeset 1247

Show
Ignore:
Timestamp:
04/24/07 05:51:59 (1 year ago)
Author:
arj..@yirdis.nl
Message:

Updated some unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/actions/tests/test_itemactions.py

    r1239 r1247  
    22import unittest 
    33 
    4 from gaphor import resource, UML 
     4from gaphor import UML 
    55from gaphor.application import Application 
    66from gaphor.ui.mainwindow import MainWindow 
     
    1919 
    2020    def setUp(self): 
     21        Application.init() 
     22        self.main_window = Application.get_service('gui_manager').main_window 
     23        self.action_manager = Application.get_service('action_manager') 
    2124        self.diagram = UML.create(UML.Diagram) 
    2225        self.main_window.show_diagram(self.diagram) 
    23         Application.init() 
    24         self.main_window = Application.get_service('gui_manager').main_window 
    2526 
    2627        self.class_ = self.diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
     
    3233 
    3334    def _test_action(self, action_id): 
    34         action = self.main_window.get_action_pool().get_action(action_id) 
     35        action = self.action_manager.get_action(action_id) 
    3536        assert action is not None 
    3637        action.update() 
  • gaphor/trunk/gaphor/actions/tests/test_placementactions.py

    r1243 r1247  
    11 
    22import unittest 
    3 from gaphor import resource 
    43from gaphor.application import Application 
    5 #from gaphor.ui.mainwindow import MainWindow 
    64from gaphor.diagram.tool import PlacementTool 
    75from gaphor.actions import placementactions 
     
    1513class PlacementToolTestCase(unittest.TestCase): 
    1614 
    17 #    main_window = MainWindow() 
    18 #    try: 
    19 #        main_window.construct() 
    20 #    except: 
    21 #        pass 
    22  
    23     def setUp(self): 
     15    def __init__(self, arg2): 
     16        unittest.TestCase.__init__(self, arg2) 
    2417        Application.init() 
    2518        self.main_window = Application.get_service('gui_manager').main_window 
    2619 
    27     def tearDown(self): 
    28         Application.shutdown() 
     20#    def setUp(self): 
     21#       Application.init() 
     22#       self.main_window = Application.get_service('gui_manager').main_window 
     23 
     24#   def tearDown(self): 
     25#       Application.shutdown() 
    2926 
    3027    def do_test_placement(self, action): 
     
    8380        self.do_test_placement(placementactions.IncludePlacementAction()) 
    8481 
    85  
    8682    def test_artifact_placement(self): 
    8783        self.do_test_placement(placementactions.ArtifactPlacementAction()) 
  • gaphor/trunk/gaphor/adapters/tests/test_editor.py

    r1121 r1247  
    33from zope import component 
    44from gaphor import UML 
     5from gaphor.UML.elementfactory import ElementFactory 
    56from gaphor.diagram import items 
    67from gaphor.diagram.interfaces import IEditor 
     
    1213class EditorTestCase(TestCase): 
    1314 
     15    def setUp(self): 
     16        self.factory = ElementFactory() 
     17        self.factory.init(None) 
     18 
     19    def tearDown(self): 
     20        self.factory.shutdown() 
     21 
    1422    def test_association_editor(self): 
    15         diagram = UML.create(UML.Diagram) 
     23        diagram = self.factory.create(UML.Diagram) 
    1624        assoc = diagram.create(items.AssociationItem) 
    1725        adapter = IEditor(assoc) 
     
    2028 
    2129        # Intermezzo: connect the association between two classes 
    22         class1 = diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
    23         class2 = diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
     30        class1 = diagram.create(items.ClassItem, subject=self.factory.create(UML.Class)) 
     31        class2 = diagram.create(items.ClassItem, subject=self.factory.create(UML.Class)) 
     32        from gaphor.interfaces import IService 
     33        component.provideUtility(self.factory, IService, 'element_factory') 
     34 
    2435        from gaphor.diagram.interfaces import IConnect 
    2536        connector = component.queryMultiAdapter((class1, assoc), IConnect) 
     
    4556         
    4657    def test_objectnode_editor(self): 
    47         diagram = UML.create(UML.Diagram) 
    48         node = diagram.create(items.ObjectNodeItem, subject=UML.create(UML.ObjectNode)) 
     58        diagram = self.factory.create(UML.Diagram) 
     59        node = diagram.create(items.ObjectNodeItem, subject=self.factory.create(UML.ObjectNode)) 
    4960        diagram.canvas.update_now() 
    5061 
  • gaphor/trunk/gaphor/tests/test_application.py

    r1180 r1247  
    2121         
    2222        Application.load_services() 
     23        assert Application.get_service('undo_manager') 
     24        assert Application.get_service('plugin_manager') 
     25 
     26        # After that, services are also available as Utilities: 
    2327        assert component.queryUtility(IService, 'undo_manager') 
    2428        assert component.queryUtility(IService, 'plugin_manager') 
  • gaphor/trunk/gaphor/tests/test_storage.py

    r1121 r1247  
    1 """Unittest the storage and parser modules 
     1""" 
     2Unittest the storage and parser modules 
    23""" 
    34 
     
    56import unittest 
    67from gaphor import UML 
     8from gaphor.UML.elementfactory import ElementFactory 
     9from gaphor.application import Application 
    710from gaphor import storage 
    811from gaphor.misc.xmlwriter import XMLWriter 
     
    3033class StorageTestCase(unittest.TestCase): 
    3134 
     35    def setUp(self): 
     36        self.factory = ElementFactory() 
     37        self.factory.init(None) 
     38 
    3239    def tearDown(self): 
    33         UML.flush() 
     40        self.factory.flush() 
     41        self.factory.shutdown() 
    3442 
    3543    def test_save_uml(self): 
    3644        """Saving gaphor.UML model elements. 
    3745        """ 
    38         UML.create(UML.Package) 
    39         UML.create(UML.Diagram) 
    40         UML.create(UML.Comment) 
    41         UML.create(UML.Class) 
     46        self.factory.create(UML.Package) 
     47        self.factory.create(UML.Diagram) 
     48        self.factory.create(UML.Comment) 
     49        self.factory.create(UML.Class) 
    4250 
    4351        out = PseudoFile() 
    44         storage.save(XMLWriter(out)
     52        storage.save(XMLWriter(out), factory=self.factory
    4553        out.close() 
    4654 
     
    5462        """Save a diagranm item too. 
    5563        """ 
    56         diagram = UML.create(UML.Diagram) 
    57         diagram.create(items.CommentItem, subject=UML.create(UML.Comment)) 
     64        diagram = self.factory.create(UML.Diagram) 
     65        diagram.create(items.CommentItem, subject=self.factory.create(UML.Comment)) 
    5866 
    5967        out = PseudoFile() 
    60         storage.save(XMLWriter(out)
     68        storage.save(XMLWriter(out), factory=self.factory
    6169        out.close() 
    6270 
     
    7381        filename = '%s.gaphor' % __module__ 
    7482 
    75         UML.create(UML.Package) 
    76         UML.create(UML.Diagram) 
    77         UML.create(UML.Comment) 
    78         UML.create(UML.Class) 
     83        self.factory.create(UML.Package) 
     84        self.factory.create(UML.Diagram) 
     85        self.factory.create(UML.Comment) 
     86        self.factory.create(UML.Class) 
    7987  
    8088        fd = open(filename, 'w') 
    81         storage.save(XMLWriter(fd)
    82         fd.close() 
    83  
    84         UML.flush() 
    85         assert not list(UML.select()) 
    86  
    87         storage.load(filename
    88  
    89         assert len(UML.lselect()) == 4 
    90         assert len(UML.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
    91         assert len(UML.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
    92         assert len(UML.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
    93         assert len(UML.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
     89        storage.save(XMLWriter(fd), factory=self.factory
     90        fd.close() 
     91 
     92        self.factory.flush() 
     93        assert not list(self.factory.select()) 
     94 
     95        storage.load(filename, factory=self.factory
     96 
     97        assert len(self.factory.lselect()) == 4 
     98        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
     99        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
     100        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
     101        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
    94102         
    95103 
     
    100108        filename = '%s.gaphor' % __module__ 
    101109 
    102         UML.create(UML.Package) 
    103         diagram = UML.create(UML.Diagram) 
    104         diagram.create(items.CommentItem, subject=UML.create(UML.Comment)) 
    105         diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
    106         iface = diagram.create(items.InterfaceItem, subject=UML.create(UML.Interface)) 
     110        self.factory.create(UML.Package) 
     111        diagram = self.factory.create(UML.Diagram) 
     112        diagram.create(items.CommentItem, subject=self.factory.create(UML.Comment)) 
     113        diagram.create(items.ClassItem, subject=self.factory.create(UML.Class)) 
     114        iface = diagram.create(items.InterfaceItem, subject=self.factory.create(UML.Interface)) 
    107115        iface.subject.name = 'Circus' 
    108116        iface.matrix.translate(10, 10) 
    109117 
    110118        fd = open(filename, 'w') 
    111         storage.save(XMLWriter(fd)
    112         fd.close() 
    113  
    114         UML.flush() 
    115         assert not list(UML.select()) 
    116  
    117         storage.load(filename
    118  
    119         assert len(UML.lselect()) == 5 
    120         assert len(UML.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
    121         assert len(UML.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
    122         d = UML.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
    123         assert len(UML.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
    124         assert len(UML.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
    125         assert len(UML.lselect(lambda e: e.isKindOf(UML.Interface))) == 1 
    126  
    127         c = UML.lselect(lambda e: e.isKindOf(UML.Class))[0] 
     119        storage.save(XMLWriter(fd), factory=self.factory
     120        fd.close() 
     121 
     122        self.factory.flush() 
     123        assert not list(self.factory.select()) 
     124 
     125        storage.load(filename, factory=self.factory
     126 
     127        assert len(self.factory.lselect()) == 5 
     128        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
     129        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
     130        d = self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
     131        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
     132        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
     133        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Interface))) == 1 
     134 
     135        c = self.factory.lselect(lambda e: e.isKindOf(UML.Class))[0] 
    128136        assert c.presentation 
    129137        assert c.presentation[0].subject is c 
    130138        #assert c.presentation[0].subject.name.startwith('Class') 
    131139 
    132         iface = UML.lselect(lambda e: e.isKindOf(UML.Interface))[0] 
     140        iface = self.factory.lselect(lambda e: e.isKindOf(UML.Interface))[0] 
    133141        assert iface.name == 'Circus' 
    134142        assert len(iface.presentation) == 1 
     
    150158        filename = '%s.gaphor' % __module__ 
    151159 
    152         UML.create(UML.Package) 
    153         diagram = UML.create(UML.Diagram) 
    154         diagram.create(items.CommentItem, subject=UML.create(UML.Comment)) 
    155         c1 = diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
     160        self.factory.create(UML.Package) 
     161        diagram = self.factory.create(UML.Diagram) 
     162        diagram.create(items.CommentItem, subject=self.factory.create(UML.Comment)) 
     163        c1 = diagram.create(items.ClassItem, subject=self.factory.create(UML.Class)) 
    156164 
    157165        a = diagram.create(items.AssociationItem) 
     
    163171 
    164172        fd = open(filename, 'w') 
    165         storage.save(XMLWriter(fd)
    166         fd.close() 
    167  
    168         UML.flush() 
    169         assert not list(UML.select()) 
    170  
    171         storage.load(filename
    172  
    173         assert len(UML.lselect()) == 4 
    174         assert len(UML.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
    175         assert len(UML.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
    176         d = UML.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
    177         assert len(UML.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
    178         assert len(UML.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
    179         assert len(UML.lselect(lambda e: e.isKindOf(UML.Association))) == 0 
     173        storage.save(XMLWriter(fd), factory=self.factory
     174        fd.close() 
     175 
     176        self.factory.flush() 
     177        assert not list(self.factory.select()) 
     178 
     179        storage.load(filename, factory=self.factory
     180 
     181        assert len(self.factory.lselect()) == 4 
     182        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
     183        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
     184        d = self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
     185        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
     186        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
     187        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Association))) == 0 
    180188 
    181189        # Check load/save of other canvas items. 
     
    198206        filename = '%s_c.gaphor' % __module__ 
    199207 
    200         diagram = UML.create(UML.Diagram) 
    201         c1 = diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
    202         c2 = diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
     208        diagram = self.factory.create(UML.Diagram) 
     209        c1 = diagram.create(items.ClassItem, subject=self.factory.create(UML.Class)) 
     210        c2 = diagram.create(items.ClassItem, subject=self.factory.create(UML.Class)) 
    203211        c2.matrix.translate(200, 200) 
    204212        diagram.canvas.update_matrix(c2) 
     
    206214 
    207215        a = diagram.create(items.AssociationItem) 
     216 
     217        # Provide our element factory as Utility, since the connect adapters 
     218        # depend on it. 
     219        from gaphor.interfaces import IService 
     220        component.provideUtility(self.factory, IService, 'element_factory') 
    208221 
    209222        adapter = component.queryMultiAdapter((c1, a), IConnect) 
     
    227240 
    228241        fd = open(filename, 'w') 
    229         storage.save(XMLWriter(fd)
     242        storage.save(XMLWriter(fd), factory=self.factory
    230243        fd.close() 
    231244 
    232245        old_a_subject_id = a.subject.id 
    233246 
    234         UML.flush() 
    235         assert not list(UML.select()) 
    236  
    237         storage.load(filename
    238  
    239         assert len(UML.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
    240         d = UML.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
     247        self.factory.flush() 
     248        assert not list(self.factory.select()) 
     249 
     250        storage.load(filename, factory=self.factory
     251 
     252        assert len(self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
     253        d = self.factory.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
    241254        a = d.canvas.select(lambda e: isinstance(e, items.AssociationItem))[0] 
    242255        assert a.subject 
  • gaphor/trunk/gaphor/ui/stock.py

    r1239 r1247  
    126126 
    127127    filename = pkg_resources.resource_filename('gaphor', 'data/icons.xml') 
    128     if os.name == 'nt' and data_dir[1] == ':'
     128    if os.name == 'nt'
    129129        # Make the filename a full URL 
    130130        filename = 'file:' + filename.replace('\\\\', '/') 
  • gaphor/trunk/setup.py

    r1245 r1247  
    6363        # 'PyGTK >= 2.8.0', - Exclude, since it will not build anyway 
    6464        'decorator >= 2.0.1', 
    65         'gaphas >= 0.1.5', 
     65        'gaphas >= 0.1.5.dev-r1235', 
    6666        'zope.component >= 3.3.0', # - won't compile on windows. 
    6767        # Add dependency on zope.testing to work around bug in zope.component