def test_grouping_with_namespace(self):
        """Test adding an use case to a subsystem (with namespace)
        """
        namespace = NamespaceModel(self.element_factory)
        s = self.create(items.SubsystemItem, uml2.Component)
        uc = self.create(items.UseCaseItem, uml2.UseCase)

        # manipulate namespace
        c = self.element_factory.create(uml2.Class)
        attribute = self.element_factory.create(uml2.Property)
        c.ownedAttribute = attribute

        self.group(s, uc)
        self.assertEquals(1, len(uc.subject.subject))
        self.assertTrue(s.subject.namespace is not uc.subject)
Exemple #2
0
    def construct(self):
        self._ui_id = self.ui_manager.add_ui_from_string(self._menu_xml)

        model = NamespaceModel(self.element_factory)
        view = NamespaceView(model, self.element_factory)
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolled_window.set_shadow_type(gtk.SHADOW_IN)
        scrolled_window.add(view)
        scrolled_window.show()
        view.show()

        view.connect_after('event-after', self._on_view_event)
        view.connect('row-activated', self._on_view_row_activated)
        view.connect_after('cursor-changed', self._on_view_cursor_changed)
        view.connect('destroy', self._on_view_destroyed)
        self._namespace = view
        self.expand_root_nodes()

        return scrolled_window
Exemple #3
0
    def test_all(self):
        factory = Application.get_service('element_factory')

        m = factory.create(uml2.Package)
        m.name = 'm'
        a = factory.create(uml2.Package)
        a.name = 'a'
        a.package = m
        assert a.package is m
        assert a in m.ownedMember
        assert a.namespace is m

        b = factory.create(uml2.Package)
        b.name = 'b'
        b.package = a
        assert b in a.ownedMember
        assert b.namespace is a

        c = factory.create(uml2.Class)
        c.name = 'c'
        c.package = b
        d = factory.create(uml2.Class)
        d.name = 'd'
        d.package = a
        e = factory.create(uml2.Class)
        e.name = 'e'
        e.package = b

        assert c in b.ownedMember
        assert c.namespace is b
        assert d in a.ownedMember
        assert d.namespace is a
        assert e in b.ownedMember
        assert e.namespace is b

        ns = NamespaceModel(factory)

        # We have a model loaded. Use it!
        factory.notify_model()

        print('---')
        print(ns.root)
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 0, 0), ns.path_from_element(b)
        assert ns.path_from_element(c) == (0, 0, 0, 0)
        assert ns.path_from_element(d) == (0, 0, 1)
        assert ns.path_from_element(e) == (0, 0, 0, 1)

        return


        print('--- del.b.ownedClassifier[c]')
        del b.ownedClassifier[c]
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 0, 0)
        assert ns.path_from_element(d) == (0, 0, 1)
        assert ns.path_from_element(e) == (0, 0, 0, 0), ns.path_from_element(e)
        try:
            ns.path_from_element(c)
        except AttributeError:
            pass # Yes, should raise an exception
        else:
            assert ns.path_from_element(c) is not None

        print('--- c.package = a')
        c.package = a
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 0, 0)
        assert ns.path_from_element(c) == (0, 0, 1)
        assert ns.path_from_element(d) == (0, 0, 2)
        assert ns.path_from_element(e) == (0, 0, 0, 0)

        print('--- b.package = m')
        b.package = m
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 1)
        assert ns.path_from_element(c) == (0, 0, 0)
        assert ns.path_from_element(d) == (0, 0, 1)
        assert ns.path_from_element(e) == (0, 1, 0)

        print('--- e.unlink()')
        e.unlink()
        ns.dump()

        print('--- a.unlink()')
#        def on_unlink(name, element):
#            print 'unlink: %s' % element.name
#        a.connect('__unlink__', on_unlink, a)
#        b.connect('__unlink__', on_unlink, b)
#        c.connect('__unlink__', on_unlink, c)
#        d.connect('__unlink__', on_unlink, d)
#
        a.unlink()
        ns.dump()
        print('--- TODO: e.relink()')

        print(uml2.Class.package)
        print(uml2.Package.ownedClassifier)
Exemple #4
0
    def test(self):
        factory = Application.get_service('element_factory')

        ns = NamespaceModel(factory)

        m = factory.create(uml2.Package)
        m.name = 'm'
        assert m in ns._nodes
        assert ns.path_from_element(m) == (1,)
        assert ns.element_from_path((1,)) is m

        a = factory.create(uml2.Package)
        a.name = 'a'
        assert a in ns._nodes
        assert a in ns._nodes[None]
        assert m in ns._nodes
        assert ns.path_from_element(a) == (1,), ns.path_from_element(a)
        assert ns.path_from_element(m) == (2,), ns.path_from_element(m)

        a.package = m
        assert a in ns._nodes
        assert a not in ns._nodes[None]
        assert a in ns._nodes[m]
        assert m in ns._nodes
        assert a.package is m
        assert a in m.ownedMember
        assert a.namespace is m
        assert ns.path_from_element(a) == (1, 0), ns.path_from_element(a)

        c = factory.create(uml2.Class)
        c.name = 'c'
        assert c in ns._nodes
        assert ns.path_from_element(c) == (1,), ns.path_from_element(c)
        assert ns.path_from_element(m) == (2,), ns.path_from_element(m)
        assert ns.path_from_element(a) == (2, 0), ns.path_from_element(a)

        c.package = m
        assert c in ns._nodes
        assert c not in ns._nodes[None]
        assert c in ns._nodes[m]

        c.package = a
        assert c in ns._nodes
        assert c not in ns._nodes[None]
        assert c not in ns._nodes[m]
        assert c in ns._nodes[a]

        c.unlink()
        assert c not in ns._nodes
        assert c not in ns._nodes[None]
        assert c not in ns._nodes[m]
        assert c not in ns._nodes[a]
Exemple #5
0
 def setUp(self):
     super(UndoRedoBugTestCase, self).setUp()
     self.undo_manager = self.get_service('undo_manager')
     self.namespace = NamespaceModel(self.element_factory)
Exemple #6
0
    def test(self):
        factory = Application.get_service('element_factory')

        ns = NamespaceModel(factory)

        m = factory.create(UML.Package)
        m.name = 'm'
        assert ns._nodes.has_key(m)
        assert ns.path_from_element(m) == (1,)
        assert ns.element_from_path((1,)) is m

        a = factory.create(UML.Package)
        a.name = 'a'
        assert a in ns._nodes
        assert a in ns._nodes[None]
        assert m in ns._nodes
        assert ns.path_from_element(a) == (1,), ns.path_from_element(a)
        assert ns.path_from_element(m) == (2,), ns.path_from_element(m)

        a.package = m
        assert a in ns._nodes
        assert a not in ns._nodes[None]
        assert a in ns._nodes[m]
        assert m in ns._nodes
        assert a.package is m
        assert a in m.ownedMember
        assert a.namespace is m
        assert ns.path_from_element(a) == (1, 0), ns.path_from_element(a)

        c = factory.create(UML.Class)
        c.name = 'c'
        assert c in ns._nodes
        assert ns.path_from_element(c) == (1,), ns.path_from_element(c)
        assert ns.path_from_element(m) == (2,), ns.path_from_element(m)
        assert ns.path_from_element(a) == (2, 0), ns.path_from_element(a)

        c.package = m
        assert c in ns._nodes
        assert c not in ns._nodes[None]
        assert c in ns._nodes[m]

        c.package = a
        assert c in ns._nodes
        assert c not in ns._nodes[None]
        assert c not in ns._nodes[m]
        assert c in ns._nodes[a]

        c.unlink()
        assert c not in ns._nodes
        assert c not in ns._nodes[None]
        assert c not in ns._nodes[m]
        assert c not in ns._nodes[a]
Exemple #7
0
    def test_all(self):
        factory = Application.get_service('element_factory')

        m = factory.create(UML.Package)
        m.name = 'm'
        a = factory.create(UML.Package)
        a.name = 'a'
        a.package = m
        assert a.package is m
        assert a in m.ownedMember
        assert a.namespace is m

        b = factory.create(UML.Package)
        b.name = 'b'
        b.package = a
        assert b in a.ownedMember
        assert b.namespace is a

        c = factory.create(UML.Class)
        c.name = 'c'
        c.package = b
        d = factory.create(UML.Class)
        d.name = 'd'
        d.package = a
        e = factory.create(UML.Class)
        e.name = 'e'
        e.package = b

        assert c in b.ownedMember
        assert c.namespace is b
        assert d in a.ownedMember
        assert d.namespace is a
        assert e in b.ownedMember
        assert e.namespace is b

        ns = NamespaceModel(factory)

        # We have a model loaded. Use it!
        factory.notify_model()

        print '---'
        print ns.root
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 0, 0), ns.path_from_element(b)
        assert ns.path_from_element(c) == (0, 0, 0, 0)
        assert ns.path_from_element(d) == (0, 0, 1)
        assert ns.path_from_element(e) == (0, 0, 0, 1)

        return


        print '--- del.b.ownedClassifier[c]'
        del b.ownedClassifier[c]
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 0, 0)
        assert ns.path_from_element(d) == (0, 0, 1)
        assert ns.path_from_element(e) == (0, 0, 0, 0), ns.path_from_element(e)
        try:
            ns.path_from_element(c)
        except AttributeError:
            pass # Yes, should raise an exception
        else:
            assert ns.path_from_element(c) is not None

        print '--- c.package = a'
        c.package = a
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 0, 0)
        assert ns.path_from_element(c) == (0, 0, 1)
        assert ns.path_from_element(d) == (0, 0, 2)
        assert ns.path_from_element(e) == (0, 0, 0, 0)

        print '--- b.package = m'
        b.package = m
        ns.dump()
        assert ns.path_from_element(m) == (0,)
        assert ns.path_from_element(a) == (0, 0)
        assert ns.path_from_element(b) == (0, 1)
        assert ns.path_from_element(c) == (0, 0, 0)
        assert ns.path_from_element(d) == (0, 0, 1)
        assert ns.path_from_element(e) == (0, 1, 0)

        print '--- e.unlink()'
        e.unlink()
        ns.dump()

        print '--- a.unlink()'
#        def on_unlink(name, element):
#            print 'unlink: %s' % element.name
#        a.connect('__unlink__', on_unlink, a)
#        b.connect('__unlink__', on_unlink, b)
#        c.connect('__unlink__', on_unlink, c)
#        d.connect('__unlink__', on_unlink, d)
#
        a.unlink()
        ns.dump()
        print '--- TODO: e.relink()'

        print UML.Class.package
        print UML.Package.ownedClassifier