コード例 #1
0
ファイル: test_transaction.py プロジェクト: amolenaar/gaphor
    def test_transaction_rollback(self):
        """Test rolling back a transaction."""

        tx = Transaction()

        self.assertTrue(tx._stack, "Transaction has no stack")
        self.assertEqual(1, len(begins), "Incorrect number of TrasactionBegin events")
        self.assertEqual(
            0, len(commits), "Incorrect number of TransactionCommit events"
        )
        self.assertEqual(
            0, len(rollbacks), "Incorrect number of TransactionRollback events"
        )

        tx.rollback()

        self.assertEqual(1, len(begins), "Incorrect number of TrasactionBegin events")
        self.assertEqual(
            0, len(commits), "Incorrect number of TransactionCommit events"
        )
        self.assertEqual(
            1, len(rollbacks), "Incorrect number of TransactionRollback events"
        )

        self.assertFalse(tx._stack, "Transaction stack is not empty")
コード例 #2
0
ファイル: test_transaction.py プロジェクト: amolenaar/gaphor
    def test_transaction_commit(self):
        """Test committing a transaction."""

        tx = Transaction()

        self.assertTrue(tx._stack, "Transaction has no stack")
        self.assertEqual(1, len(begins), "Incorrect number of TrasactionBegin events")
        self.assertEqual(
            0, len(commits), "Incorrect number of TransactionCommit events"
        )
        self.assertEqual(
            0, len(rollbacks), "Incorrect number of TransactionRollback events"
        )

        tx.commit()

        self.assertEqual(1, len(begins), "Incorrect number of TrasactionBegin events")
        self.assertEqual(
            1, len(commits), "Incorrect number of TransactionCommit events"
        )
        self.assertEqual(
            0, len(rollbacks), "Incorrect number of TransactionRollback events"
        )
        self.assertFalse(tx._stack, "Transaction stack is not empty")

        try:
            tx.commit()
        except TransactionError:
            pass
        else:
            self.fail("Commit should not have succeeded")
コード例 #3
0
def test_actions(event_manager, undo_manager):
    undone = [0]

    def undo_action(undone=undone):
        undone[0] = 1
        undo_manager.add_undo_action(redo_action)

    def redo_action(undone=undone):
        undone[0] = -1
        undo_manager.add_undo_action(undo_action)

    tx = Transaction(event_manager)
    undo_manager.add_undo_action(undo_action)
    assert undo_manager._current_transaction
    assert undo_manager.can_undo()
    assert len(undo_manager._current_transaction._actions) == 1

    tx.commit()

    undo_manager.undo_transaction()
    assert not undo_manager.can_undo(), undo_manager._undo_stack
    assert undone[0] == 1, undone

    undone[0] = 0

    assert undo_manager.can_redo(), undo_manager._redo_stack

    undo_manager.redo_transaction()
    assert not undo_manager.can_redo()
    assert undo_manager.can_undo()
    assert undone[0] == -1, undone
コード例 #4
0
ファイル: diagrampage.py プロジェクト: Mitchell-boop/gaphor
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """
        Handle data dropped on the canvas.
        """
        if (data and data.get_format() == 8
                and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION):
            tool = self.toolbox.get_tool(data.get_data().decode())
            tool.create_item((x, y))
            context.finish(True, False, time)
        elif (data and data.get_format() == 8
              and info == DiagramPage.VIEW_TARGET_ELEMENT_ID):
            element_id = data.get_data().decode()
            element = self.element_factory.lookup(element_id)
            assert element

            item_class = get_diagram_item(type(element))
            if item_class:
                tx = Transaction(self.event_manager)
                item = self.diagram.create(item_class)
                assert item

                x, y = view.get_matrix_v2i(item).transform_point(x, y)
                item.matrix.translate(x, y)
                item.subject = element
                tx.commit()
                view.unselect_all()
                view.focused_item = item

            else:
                log.warning("No graphical representation for UML element %s" %
                            type(element).__name__)
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
コード例 #5
0
ファイル: test_transaction.py プロジェクト: dieterv/gaphor
    def test_transaction_stack(self):
        tx = Transaction()
        tx2 = Transaction()

        try:
            tx.commit()
        except TransactionError, e:
            self.assertEquals('Transaction on stack is not the transaction being closed.', str(e))
コード例 #6
0
    def on_drag_data_received(self, context, x, y, selection, info, time):
        """
        Drop the data send by on_drag_data_get().
        """
        #print 'data-received', NamespaceView.TARGET_ELEMENT_ID, 'in', context.targets
        self.emit_stop_by_name('drag-data-received')
        if 'gaphor/element-id' in context.targets:
            #print 'drag_data_received'
            n, p = selection.data.split('#')
            drop_info = self.get_dest_row_at_pos(x, y)
        else:
            drop_info = None

        if drop_info:
            model = self.get_model()
            element = self.factory.lookup(n)
            path, position = drop_info
            iter = model.get_iter(path)
            dest_element = model.get_value(iter, 0)
            assert dest_element
            # Add the item to the parent if it is dropped on the same level,
            # else add it to the item.
            if position in (gtk.TREE_VIEW_DROP_BEFORE,
                            gtk.TREE_VIEW_DROP_AFTER):
                parent_iter = model.iter_parent(iter)
                if parent_iter is None:
                    dest_element = None
                else:
                    dest_element = model.get_value(parent_iter, 0)

            try:
                # Check if element is part of the namespace of dest_element:
                ns = dest_element
                while ns:
                    if ns is element:
                        raise AttributeError
                    ns = ns.namespace

                # Set package. This only works for classifiers, packages and
                # diagrams. Properties and operations should not be moved.
                tx = Transaction()
                if dest_element is None:
                    del element.package
                else:
                    element.package = dest_element
                tx.commit()

            except AttributeError as e:
                #log.info('Unable to drop data', e)
                context.drop_finish(False, time)
            else:
                context.drop_finish(True, time)
                # Finally let's try to select the element again.
                path = model.path_from_element(element)
                if len(path) > 1:
                    self.expand_row(path[:-1], False)
                selection = self.get_selection()
                selection.select_path(path)
コード例 #7
0
ファイル: namespace.py プロジェクト: Nyox/gaphor
    def on_drag_data_received(self, context, x, y, selection, info, time):
        """
        Drop the data send by on_drag_data_get().
        """
        #print 'data-received', NamespaceView.TARGET_ELEMENT_ID, 'in', context.targets
        self.emit_stop_by_name('drag-data-received')
        if 'gaphor/element-id' in context.targets:
            #print 'drag_data_received'
            n, p = selection.data.split('#')
            drop_info = self.get_dest_row_at_pos(x, y)
        else:
            drop_info = None

        if drop_info:
            model = self.get_model()
            element = self.factory.lookup(n)
            path, position = drop_info
            iter = model.get_iter(path)
            dest_element = model.get_value(iter, 0)
            assert dest_element
            # Add the item to the parent if it is dropped on the same level,
            # else add it to the item.
            if position in (gtk.TREE_VIEW_DROP_BEFORE, gtk.TREE_VIEW_DROP_AFTER):
                parent_iter = model.iter_parent(iter)
                if parent_iter is None:
                    dest_element = None
                else:
                    dest_element = model.get_value(parent_iter, 0)

            try:
                # Check if element is part of the namespace of dest_element:
                ns = dest_element
                while ns:
                    if ns is element:
                        raise AttributeError
                    ns = ns.namespace

                # Set package. This only works for classifiers, packages and
                # diagrams. Properties and operations should not be moved.
                tx = Transaction()
                if dest_element is None:
                    del element.package
                else:
                    element.package = dest_element
                tx.commit()

            except AttributeError, e:
                #log.info('Unable to drop data', e)
                context.drop_finish(False, time)
            else:
                context.drop_finish(True, time)
                # Finally let's try to select the element again.
                path = model.path_from_element(element)
                if len(path) > 1:
                    self.expand_row(path[:-1], False)
                selection = self.get_selection()
                selection.select_path(path)
コード例 #8
0
ファイル: test_transaction.py プロジェクト: Nyox/gaphor
    def test_transaction_stack(self):
        """Test the transaction stack."""
        
        tx1 = Transaction()
        tx2 = Transaction()

        try:
            tx1.commit()
        except TransactionError, e:
            pass
コード例 #9
0
ファイル: test_transaction.py プロジェクト: xqbumu/gaphor
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()

        try:
            tx1.commit()
        except TransactionError, e:
            pass
コード例 #10
0
def test_transaction_stack(event_manager):
    """Test the transaction stack."""

    tx1 = Transaction(event_manager)
    tx2 = Transaction(event_manager)

    with pytest.raises(TransactionError):
        tx1.commit()

    tx2.rollback()
    tx1.rollback()
コード例 #11
0
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()

        try:
            tx1.commit()
        except TransactionError as e:
            pass
        else:
            self.fail('Commit should not have succeeded')
コード例 #12
0
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()  # tx2 is used despite warnings

        try:
            tx1.commit()
        except TransactionError:
            pass
        else:
            self.fail('Commit should not have succeeded')
コード例 #13
0
ファイル: namespace.py プロジェクト: weizx208/gaphor
    def on_drag_data_received(self, context, x, y, selection, info, time):
        """
        Drop the data send by on_drag_data_get().
        """
        self.stop_emission_by_name("drag-data-received")
        if info == NamespaceView.TARGET_ELEMENT_ID:
            n, _p = selection.get_data().decode().split("#")
            drop_info = self.get_dest_row_at_pos(x, y)
        else:
            drop_info = None

        if drop_info:
            model = self.get_model()
            element = self.factory.lookup(n)
            path, position = drop_info
            iter = model.get_iter(path)
            dest_element = model.get_value(iter, 0)
            assert dest_element
            # Add the item to the parent if it is dropped on the same level,
            # else add it to the item.
            if position in (
                Gtk.TreeViewDropPosition.BEFORE,
                Gtk.TreeViewDropPosition.AFTER,
            ):
                parent_iter = model.iter_parent(iter)
                if parent_iter is None:
                    dest_element = None
                else:
                    dest_element = model.get_value(parent_iter, 0)

            try:
                # Check if element is part of the namespace of dest_element:
                ns = dest_element
                while ns:
                    if ns is element:
                        raise AttributeError
                    ns = ns.namespace

                # Set package. This only works for classifiers, packages and
                # diagrams. Properties and operations should not be moved.
                tx = Transaction()
                if dest_element is None:
                    del element.package
                else:
                    element.package = dest_element
                tx.commit()

            except AttributeError as e:
                log.info("Unable to drop data %s" % e)
                context.finish(False, False, time)
            else:
                context.finish(True, True, time)
コード例 #14
0
ファイル: test_transaction.py プロジェクト: dieterv/gaphor
    def test_transaction_rollback(self):
        tx = Transaction()
        self.assertTrue(tx._stack)
        self.assertEquals(1, len(begins))
        self.assertEquals(0, len(commits))
        self.assertEquals(0, len(rollbacks))

        tx.rollback()
        self.assertEquals(1, len(begins))
        self.assertEquals(0, len(commits))
        self.assertEquals(1, len(rollbacks))

        self.assertFalse(tx._stack)
コード例 #15
0
ファイル: diagrampage.py プロジェクト: amolenaar/gaphor
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """
        Handle data dropped on the canvas.
        """
        if (
            data
            and data.get_format() == 8
            and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION
        ):
            tool = self.toolbox.get_tool(data.get_data().decode())
            tool.create_item((x, y))
            context.finish(True, False, time)
        elif (
            data
            and data.get_format() == 8
            and info == DiagramPage.VIEW_TARGET_ELEMENT_ID
        ):
            print("drag_data_received:", data.get_data(), info)
            n, p = data.get_data().decode().split("#")
            element = self.element_factory.lookup(n)
            assert element

            # TODO: use adapters to execute code below

            q = type(element)
            if p:
                q = q, p
            item_class = get_diagram_item(q)
            if isinstance(element, UML.Diagram):
                self.action_manager.execute("OpenModelElement")
            elif item_class:
                tx = Transaction()
                item = self.diagram.create(item_class)
                assert item

                x, y = view.get_matrix_v2i(item).transform_point(x, y)
                item.matrix.translate(x, y)
                item.subject = element
                tx.commit()
                view.unselect_all()
                view.focused_item = item

            else:
                log.warning(
                    "No graphical representation for UML element %s"
                    % type(element).__name__
                )
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
コード例 #16
0
ファイル: test_undomanager.py プロジェクト: vitornat/gaphor
    def test_transactions(self):

        event_manager = EventManager()
        undo_manager = UndoManager(event_manager)

        assert not undo_manager._current_transaction

        # undo_manager.begin_transaction()
        tx = Transaction(event_manager)

        # assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction

        current = undo_manager._current_transaction
        # undo_manager.begin_transaction()
        tx2 = Transaction(event_manager)
        # assert undo_manager._transaction_depth == 2
        # assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        # undo_manager.commit_transaction()
        tx2.commit()

        # assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        # undo_manager.commit_transaction()
        tx.commit()
        # assert undo_manager._transaction_depth == 0
        assert undo_manager._current_transaction is None

        undo_manager.shutdown()
コード例 #17
0
 def _text_edited(self, cell, path_str, new_text):
     """
     The text has been edited. This method updates the data object.
     Note that 'path_str' is a string where the fields are separated by
     colons ':', like this: '0:1:1'. We first turn them into a tuple.
     """
     try:
         model = self.get_property('model')
         iter = model.get_iter_from_string(path_str)
         element = model.get_value(iter, 0)
         tx = Transaction()
         element.name = new_text
         tx.commit()
     except Exception as e:
         log.error('Could not create path from string "%s"' % path_str)
コード例 #18
0
ファイル: namespace.py プロジェクト: Nyox/gaphor
 def _text_edited(self, cell, path_str, new_text):
     """
     The text has been edited. This method updates the data object.
     Note that 'path_str' is a string where the fields are separated by
     colons ':', like this: '0:1:1'. We first turn them into a tuple.
     """
     try:
         model = self.get_property('model')
         iter = model.get_iter_from_string(path_str)
         element = model.get_value(iter, 0)
         tx = Transaction()
         element.name = new_text
         tx.commit()
     except Exception, e:
         log.error('Could not create path from string "%s"' % path_str)
コード例 #19
0
    def test_transaction(self):
        """Test basic transaction functionality."""

        tx = Transaction()
        tx.rollback()

        tx = Transaction()
        tx.commit()
コード例 #20
0
ファイル: undomanager.py プロジェクト: gitter-badger/dabbler
    def undo_transaction(self):
        if not self._undo_stack:
            return

        if self._current_transaction:
            log.warning('Trying to undo a transaction, while in a transaction')
            self.commit_transaction()
        transaction = self._undo_stack.pop()

        # Store stacks
        undo_stack = list(self._undo_stack)
        redo_stack = list(self._redo_stack)
        self._undo_stack = []

        try:
            with Transaction():
                transaction.execute()
        finally:
            # Restore stacks and put latest tx on the redo stack
            self._redo_stack = redo_stack
            if self._undo_stack:
                self._redo_stack.extend(self._undo_stack)
            self._undo_stack = undo_stack

        while len(self._redo_stack) > self._stack_depth:
            del self._redo_stack[0]

        self.component_registry.handle(UndoManagerStateChanged(self))
        self._action_executed()
コード例 #21
0
    def undo_transaction(self):
        if not self._undo_stack:
            return

        if self._current_transaction:
            logger.warning("Trying to undo a transaction, while in a transaction")
            self.commit_transaction()
        transaction = self._undo_stack.pop()

        # Store stacks
        undo_stack = list(self._undo_stack)
        redo_stack = list(self._redo_stack)
        self._undo_stack = []

        try:
            with Transaction(self.event_manager):
                transaction.execute()
        finally:
            # Restore stacks and put latest tx on the redo stack
            self._redo_stack = redo_stack
            if self._undo_stack:
                self._redo_stack.extend(self._undo_stack)
            self._undo_stack = undo_stack

        while len(self._redo_stack) > self._stack_depth:
            del self._redo_stack[0]

        self._action_executed()
コード例 #22
0
def test_transaction_rollback(event_manager):
    """Test rolling back a transaction."""

    tx = Transaction(event_manager)

    assert tx._stack, "Transaction has no stack"
    assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
    assert 0 == len(commits), "Incorrect number of TransactionCommit events"
    assert 0 == len(rollbacks), "Incorrect number of TransactionRollback events"

    tx.rollback()

    assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
    assert 0 == len(commits), "Incorrect number of TransactionCommit events"
    assert 1 == len(rollbacks), "Incorrect number of TransactionRollback events"

    assert not tx._stack, "Transaction stack is not empty"
コード例 #23
0
ファイル: diagrampage.py プロジェクト: taroyuyu/gaphor
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """Handle data dropped on the diagram."""
        if (data and data.get_format() == 8
                and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION):
            tool_def = self.get_tool_def(data.get_data().decode())
            with Transaction(self.event_manager):
                create_item(view, tool_def.item_factory, x, y)
            context.finish(True, False, time)
        elif (data and data.get_format() == 8
              and info == DiagramPage.VIEW_TARGET_ELEMENT_ID):
            element_id = data.get_data().decode()
            element = self.element_factory.lookup(element_id)
            assert element

            if not isinstance(
                    element,
                (UML.Classifier, UML.Package, UML.Property)) or isinstance(
                    element, UML.Association):
                self.event_manager.handle(
                    Notification(
                        gettext(
                            "Drag to diagram is (temporarily) limited to Classifiers, Packages, and Properties, not {type}."
                        ).format(type=type(element).__name__)))
                context.finish(True, False, time)
                return

            item_class = get_diagram_item(type(element))
            if item_class:
                with Transaction(self.event_manager):
                    item = self.diagram.create(item_class)
                    assert item

                    x, y = view.get_matrix_v2i(item).transform_point(x, y)
                    item.matrix.translate(x, y)
                    item.subject = element

                view.selection.unselect_all()
                view.selection.focused_item = item

            else:
                log.warning(
                    f"No graphical representation for element {type(element).__name__}"
                )
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
コード例 #24
0
def test_transaction_context(event_manager):
    """Test the transaction context manager."""

    with Transaction(event_manager) as tx:

        assert isinstance(tx, Transaction), "Context is not a Transaction instance"
        assert Transaction._stack, "Transaction instance has no stack inside a context"

    assert not Transaction._stack, "Transaction stack should be empty"
コード例 #25
0
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()

        try:
            self.assertRaises(TransactionError, tx1.commit)
        finally:
            tx2.rollback()
            tx1.rollback()
コード例 #26
0
ファイル: test_transaction.py プロジェクト: xqbumu/gaphor
    def test_transaction_context_error(self):
        """Test the transaction context manager with errors."""

        try:
            with Transaction():
                raise TypeError('transaction error')
        except TypeError, e:
            self.assertEquals(
                'transaction error', str(e),
                'Transaction context manager did no raise correct exception')
コード例 #27
0
ファイル: test_undomanager.py プロジェクト: vitornat/gaphor
    def test_redo_stack(self):
        from gaphor.core.modeling import Element

        event_manager = EventManager()
        undo_manager = UndoManager(event_manager)
        element_factory = ElementFactory(event_manager)

        undo_manager.begin_transaction()

        p = element_factory.create(Element)

        assert undo_manager._current_transaction
        assert undo_manager._current_transaction._actions
        assert undo_manager.can_undo()

        undo_manager.commit_transaction()
        assert undo_manager.can_undo()
        assert element_factory.size() == 1, element_factory.size()

        with Transaction(event_manager):
            element_factory.create(Element)

        assert undo_manager.can_undo()
        assert not undo_manager.can_redo()
        assert element_factory.size() == 2

        undo_manager.undo_transaction()
        assert undo_manager.can_undo()
        assert 1 == len(undo_manager._undo_stack)
        assert 1 == len(undo_manager._redo_stack)
        assert undo_manager.can_redo()
        assert element_factory.size() == 1

        undo_manager.undo_transaction()
        assert not undo_manager.can_undo()
        assert undo_manager.can_redo()
        assert 0 == len(undo_manager._undo_stack)
        assert 2 == len(undo_manager._redo_stack)
        # assert element_factory.size() == 0

        undo_manager.redo_transaction()
        assert 1 == len(undo_manager._undo_stack)
        assert 1 == len(undo_manager._redo_stack)
        assert undo_manager.can_undo()
        assert undo_manager.can_redo()
        assert element_factory.size() == 1

        undo_manager.redo_transaction()
        assert undo_manager.can_undo()
        assert not undo_manager.can_redo()
        assert element_factory.size() == 2

        assert p in element_factory.lselect()

        undo_manager.shutdown()
コード例 #28
0
    def test_redo_stack(self):
        from gaphor.UML.element import Element

        undo_manager = UndoManager()
        undo_manager.init(Application)
        undo_manager.begin_transaction()
        ef = self.element_factory
        ef.flush()

        p = ef.create(Element)

        assert undo_manager._current_transaction
        assert undo_manager._current_transaction._actions
        assert undo_manager.can_undo()

        undo_manager.commit_transaction()
        assert undo_manager.can_undo()
        assert ef.size() == 1, ef.size()

        with Transaction():
            q = ef.create(Element)

        assert undo_manager.can_undo()
        assert not undo_manager.can_redo()
        assert ef.size() == 2

        undo_manager.undo_transaction()
        assert undo_manager.can_undo()
        self.assertEqual(1, len(undo_manager._undo_stack))
        self.assertEqual(1, len(undo_manager._redo_stack))
        assert undo_manager.can_redo()
        assert ef.size() == 1

        undo_manager.undo_transaction()
        assert not undo_manager.can_undo()
        assert undo_manager.can_redo()
        self.assertEqual(0, len(undo_manager._undo_stack))
        self.assertEqual(2, len(undo_manager._redo_stack))
        # assert ef.size() == 0

        undo_manager.redo_transaction()
        self.assertEqual(1, len(undo_manager._undo_stack))
        self.assertEqual(1, len(undo_manager._redo_stack))
        assert undo_manager.can_undo()
        assert undo_manager.can_redo()
        assert ef.size() == 1

        undo_manager.redo_transaction()
        assert undo_manager.can_undo()
        assert not undo_manager.can_redo()
        assert ef.size() == 2

        assert p in ef.lselect()

        undo_manager.shutdown()
コード例 #29
0
ファイル: diagrampage.py プロジェクト: paulopperman/gaphor
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """
        Handle data dropped on the canvas.
        """
        if (data and data.get_format() == 8
                and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION):
            tool = self.toolbox.get_tool(data.get_data().decode())
            tool.create_item((x, y))
            context.finish(True, False, time)
        elif (data and data.get_format() == 8
              and info == DiagramPage.VIEW_TARGET_ELEMENT_ID):
            print("drag_data_received:", data.get_data(), info)
            n, p = data.get_data().decode().split("#")
            element = self.element_factory.lookup(n)
            assert element

            # TODO: use adapters to execute code below

            q = type(element)
            if p:
                q = q, p
            item_class = get_diagram_item(q)
            if isinstance(element, UML.Diagram):
                self.action_manager.execute("OpenModelElement")
            elif item_class:
                tx = Transaction()
                item = self.diagram.create(item_class)
                assert item

                x, y = view.get_matrix_v2i(item).transform_point(x, y)
                item.matrix.translate(x, y)
                item.subject = element
                tx.commit()
                view.unselect_all()
                view.focused_item = item

            else:
                log.warning("No graphical representation for UML element %s" %
                            type(element).__name__)
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
コード例 #30
0
def test_transaction_commit_after_rollback(event_manager):
    """Test committing one transaction after rolling back another
    transaction."""

    tx1 = Transaction(event_manager)
    tx2 = Transaction(event_manager)

    tx2.rollback()
    tx1.commit()

    assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
    assert 0 == len(commits), "Incorrect number of TransactionCommit events"
    assert 1 == len(rollbacks), "Incorrect number of TransactionRollback events"
コード例 #31
0
ファイル: test_transaction.py プロジェクト: dieterv/gaphor
    def test_transaction_commit(self):
        tx = Transaction()
        self.assertTrue(tx._stack)
        self.assertEquals(1, len(begins))
        self.assertEquals(0, len(commits))
        self.assertEquals(0, len(rollbacks))

        tx.commit()
        self.assertEquals(1, len(begins))
        self.assertEquals(1, len(commits))
        self.assertEquals(0, len(rollbacks))

        self.assertFalse(tx._stack)

        try:
            tx.commit()
        except TransactionError:
            pass # ok
        else:
            assert False, 'should not be reached'
コード例 #32
0
def test_no_value_change_if_not_in_transaction(event_manager, element_factory,
                                               undo_manager):
    class A(Element):
        attr = attribute("attr", bytes, default="default")

    with Transaction(event_manager):
        a = element_factory.create(A)

    with pytest.raises(NotInTransactionException):
        a.attr = "foo"

    assert a.attr == "default"
コード例 #33
0
    def test_transaction_context(self):
        """Test the transaction context manager."""

        with Transaction() as tx:
            self.assertTrue(isinstance(tx, Transaction),
                            'Context is not a Transaction instance')
            self.assertTrue(
                Transaction._stack,
                'Transaction instance has no stack inside a context')

        self.assertFalse(Transaction._stack,
                         'Transaction stack should be empty')
コード例 #34
0
ファイル: test_undomanager.py プロジェクト: Nyox/gaphor
    def test_transactions(self):

        undo_manager = UndoManager()
        undo_manager.init(None)

        assert not undo_manager._current_transaction

        #undo_manager.begin_transaction()
        tx = Transaction()

        #assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction

        current = undo_manager._current_transaction
        #undo_manager.begin_transaction()
        tx2 = Transaction()
        #assert undo_manager._transaction_depth == 2
        #assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        #undo_manager.commit_transaction()
        tx2.commit()

        #assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        #undo_manager.commit_transaction()
        tx.commit()
        #assert undo_manager._transaction_depth == 0
        assert undo_manager._current_transaction is None

        undo_manager.shutdown()
コード例 #35
0
    def test_transaction_commit(self):
        """Test committing a transaction."""

        tx = Transaction(self.event_manager)

        assert tx._stack, "Transaction has no stack"
        assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
        assert 0 == len(
            commits), "Incorrect number of TransactionCommit events"
        assert 0 == len(
            rollbacks), "Incorrect number of TransactionRollback events"

        tx.commit()

        assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
        assert 1 == len(
            commits), "Incorrect number of TransactionCommit events"
        assert 0 == len(
            rollbacks), "Incorrect number of TransactionRollback events"
        assert not tx._stack, "Transaction stack is not empty"

        try:
            tx.commit()
        except TransactionError:
            pass
        else:
            self.fail("Commit should not have succeeded")
コード例 #36
0
ファイル: test_undomanager.py プロジェクト: amolenaar/gaphor
    def test_actions(self):
        undone = [0]

        def undo_action(undone=undone):
            # print 'undo_action called'
            undone[0] = 1
            undo_manager.add_undo_action(redo_action)

        def redo_action(undone=undone):
            # print 'redo_action called'
            undone[0] = -1
            undo_manager.add_undo_action(undo_action)

        undo_manager = UndoManager()
        undo_manager.init(Application)

        # undo_manager.begin_transaction()
        tx = Transaction()
        undo_manager.add_undo_action(undo_action)
        assert undo_manager._current_transaction
        assert undo_manager.can_undo()
        assert len(undo_manager._current_transaction._actions) == 1

        # undo_manager.commit_transaction()
        tx.commit()

        undo_manager.undo_transaction()
        assert not undo_manager.can_undo(), undo_manager._undo_stack
        assert undone[0] == 1, undone

        undone[0] = 0

        assert undo_manager.can_redo(), undo_manager._redo_stack

        undo_manager.redo_transaction()
        assert not undo_manager.can_redo()
        assert undo_manager.can_undo()
        assert undone[0] == -1, undone

        undo_manager.shutdown()
コード例 #37
0
    def test_actions(self):
        undone = [0]

        def undo_action(undone=undone):
            #print 'undo_action called'
            undone[0] = 1
            undo_manager.add_undo_action(redo_action)

        def redo_action(undone=undone):
            #print 'redo_action called'
            undone[0] = -1
            undo_manager.add_undo_action(undo_action)

        undo_manager = UndoManager()
        undo_manager.init(Application)

        #undo_manager.begin_transaction()
        tx = Transaction()
        undo_manager.add_undo_action(undo_action)
        assert undo_manager._current_transaction
        assert undo_manager.can_undo()
        assert len(undo_manager._current_transaction._actions) == 1

        #undo_manager.commit_transaction()
        tx.commit()

        undo_manager.undo_transaction()
        assert not undo_manager.can_undo(), undo_manager._undo_stack
        assert undone[0] == 1, undone

        undone[0] = 0

        assert undo_manager.can_redo(), undo_manager._redo_stack

        undo_manager.redo_transaction()
        assert not undo_manager.can_redo()
        assert undo_manager.can_undo()
        assert undone[0] == -1, undone

        undo_manager.shutdown()
コード例 #38
0
    def test_transaction_commit(self):
        """Test committing a transaction."""

        tx = Transaction()

        self.assertTrue(tx._stack, 'Transaction has no stack')
        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(0, len(rollbacks),
                          'Incorrect number of TransactionRollback events')

        tx.commit()

        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(1, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(0, len(rollbacks),
                          'Incorrect number of TransactionRollback events')
        self.assertFalse(tx._stack, 'Transaction stack is not empty')

        try:
            tx.commit()
        except TransactionError:
            pass
        else:
            self.fail('Commit should not have succeeded')
コード例 #39
0
ファイル: test_transaction.py プロジェクト: amolenaar/gaphor
    def test_transaction(self):
        """Test basic transaction functionality."""

        tx = Transaction()
        tx.rollback()

        tx = Transaction()
        tx.commit()
コード例 #40
0
    def test_transaction_rollback(self):
        """Test rolling back a transaction."""

        tx = Transaction()

        self.assertTrue(tx._stack, 'Transaction has no stack')
        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(0, len(rollbacks),
                          'Incorrect number of TransactionRollback events')

        tx.rollback()

        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(1, len(rollbacks),
                          'Incorrect number of TransactionRollback events')

        self.assertFalse(tx._stack, 'Transaction stack is not empty')
コード例 #41
0
    def test_transaction_commit_after_rollback(self):
        """Test committing one transaction after rolling back another
        transaction."""

        tx1 = Transaction()
        tx2 = Transaction()

        tx2.rollback()
        tx1.commit()

        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(1, len(rollbacks),
                          'Incorrect number of TransactionRollback events')
コード例 #42
0
    def redo_transaction(self):
        if not self._redo_stack:
            return

        transaction = self._redo_stack.pop()

        redo_stack = list(self._redo_stack)
        try:
            with Transaction(self.event_manager):
                transaction.execute()
        finally:
            self._redo_stack = redo_stack

        self._action_executed()
コード例 #43
0
ファイル: test_transaction.py プロジェクト: dieterv/gaphor
    def test_transaction_commit_after_rollback(self):
        tx = Transaction()
        tx2 = Transaction()

        tx2.rollback()

        tx.commit()
        self.assertEquals(1, len(begins))
        self.assertEquals(0, len(commits))
        self.assertEquals(1, len(rollbacks))
コード例 #44
0
ファイル: test_transaction.py プロジェクト: amolenaar/gaphor
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()

        try:
            self.assertRaises(TransactionError, tx1.commit)
        finally:
            tx2.rollback()
            tx1.rollback()
コード例 #45
0
ファイル: test_transaction.py プロジェクト: Nyox/gaphor
    def test_transaction_commit_after_rollback(self):
        """Test committing one transaction after rolling back another
        transaction."""
        
        tx1 = Transaction()
        tx2 = Transaction()

        tx2.rollback()
        tx1.commit()
        
        self.assertEquals(1, len(begins), 'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits), 'Incorrect number of TransactionCommit events')
        self.assertEquals(1, len(rollbacks), 'Incorrect number of TransactionRollback events')