From e5b96589d2c9f763b6ecb6825baea60f90de82e7 Mon Sep 17 00:00:00 2001 From: Rebecca Breu <rebecca@rbreu.de> Date: Tue, 28 Nov 2023 21:51:35 +0100 Subject: [PATCH] Fix unit tests --- beeref/items.py | 2 +- tests/items/test_textitem.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/beeref/items.py b/beeref/items.py index be4b5ce..99ba528 100644 --- a/beeref/items.py +++ b/beeref/items.py @@ -553,10 +553,10 @@ def exit_edit_mode(self, commit=True): # reset selection: self.setTextCursor(QtGui.QTextCursor(self.document())) self.setTextInteractionFlags(Qt.TextInteractionFlag.NoTextInteraction) + self.scene().edit_item = None if commit: self.scene().undo_stack.push( commands.ChangeText(self, self.toPlainText(), self.old_text)) - self.scene().edit_item = None if not self.toPlainText().strip(): logger.debug('Removing empty text item') self.scene().undo_stack.push( diff --git a/tests/items/test_textitem.py b/tests/items/test_textitem.py index e0e9f0c..607a216 100644 --- a/tests/items/test_textitem.py +++ b/tests/items/test_textitem.py @@ -244,6 +244,8 @@ def test_exit_edit_mode_when_text_empty(view): assert view.scene.edit_item is None +@patch('PyQt6.QtGui.QTextCursor') +@patch('beeref.items.BeeTextItem.setTextCursor') def test_exit_edit_mode_when_commit_false(setcursor_mock, cursor_mock, view): item = BeeTextItem('foo bar') item.edit_mode = True @@ -258,7 +260,7 @@ def test_exit_edit_mode_when_commit_false(setcursor_mock, cursor_mock, view): cursor_mock.assert_called_once_with(item.document()) setcursor_mock.assert_called_once_with(cursor_mock.return_value) assert view.scene.edit_item is None - assert item.toPlaintText() == 'old' + assert item.toPlainText() == 'old' @patch('PyQt6.QtWidgets.QGraphicsTextItem.keyPressEvent')