From 2b737f570909252e440dcf7f7d32fbacd3712b26 Mon Sep 17 00:00:00 2001 From: Julian Gilbey Date: Wed, 10 Jan 2024 15:01:20 +0000 Subject: [PATCH] Fix some tests failing on Python 3.12 (#21688) --- spyder/plugins/editor/tests/test_plugin.py | 8 ++------ .../plugins/editor/widgets/tests/test_warnings.py | 14 ++++++++++++-- .../objectexplorer/tests/test_objectexplorer.py | 2 +- spyder/widgets/tests/test_reporterror.py | 7 +++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/spyder/plugins/editor/tests/test_plugin.py b/spyder/plugins/editor/tests/test_plugin.py index 59123b524cc..1c1f68d4e1a 100644 --- a/spyder/plugins/editor/tests/test_plugin.py +++ b/spyder/plugins/editor/tests/test_plugin.py @@ -143,12 +143,8 @@ def test_renamed_tree(editor_plugin, mocker): editor.renamed_tree('/test/directory', '/test/dir') assert editor.renamed.call_count == 3 - assert editor.renamed.called_with(source='/test/directory/file1.py', - dest='test/dir/file1.py') - assert editor.renamed.called_with(source='/test/directory/file2.txt', - dest='test/dir/file2.txt') - assert editor.renamed.called_with(source='/test/directory/file4.rst', - dest='test/dir/file4.rst') + editor.renamed.assert_called_with(source='/test/directory/file4.rst', + dest='/test/dir/file4.rst') def test_no_template(editor_plugin): diff --git a/spyder/plugins/editor/widgets/tests/test_warnings.py b/spyder/plugins/editor/widgets/tests/test_warnings.py index 663bbf55fc5..2a57e7a7af9 100644 --- a/spyder/plugins/editor/widgets/tests/test_warnings.py +++ b/spyder/plugins/editor/widgets/tests/test_warnings.py @@ -263,7 +263,12 @@ def test_update_warnings_after_closequotes(qtbot, completions_codeeditor_linting editor, _ = completions_codeeditor_linting editor.textCursor().insertText("print('test)\n") - if sys.version_info >= (3, 10): + if sys.version_info >= (3, 12): + expected = [ + ['unterminated string literal (detected at line 1)', 1], + ['E901 TokenError: unterminated string literal (detected at line 1)', 1] + ] + elif sys.version_info >= (3, 10): expected = [['unterminated string literal (detected at line 1)', 1]] else: expected = [['EOL while scanning string literal', 1]] @@ -302,7 +307,12 @@ def test_update_warnings_after_closebrackets(qtbot, completions_codeeditor_linti editor, _ = completions_codeeditor_linting editor.textCursor().insertText("print('test'\n") - if sys.version_info >= (3, 10): + if sys.version_info >= (3, 12): + expected = [ + ["'(' was never closed", 1], + ['E901 TokenError: unexpected EOF in multi-line statement', 1] + ] + elif sys.version_info >= (3, 10): expected = [ ["'(' was never closed", 1], ['E901 TokenError: EOF in multi-line statement', 2] diff --git a/spyder/plugins/variableexplorer/widgets/objectexplorer/tests/test_objectexplorer.py b/spyder/plugins/variableexplorer/widgets/objectexplorer/tests/test_objectexplorer.py index 06d03bc484e..d80fdb87397 100644 --- a/spyder/plugins/variableexplorer/widgets/objectexplorer/tests/test_objectexplorer.py +++ b/spyder/plugins/variableexplorer/widgets/objectexplorer/tests/test_objectexplorer.py @@ -110,7 +110,7 @@ def error_attribute(self): ([1, 3, 4, 'kjkj', None], [45, 48]), ({1, 2, 1, 3, None, 'A', 'B', 'C', True, False}, [54, 57]), (1.2233, [57, 59]), - (np.random.rand(10, 10), [166, 162]), + (np.random.rand(10, 10), [162, 167]), (datetime.date(1945, 5, 8), [43, 48]) ]) def test_objectexplorer_collection_types(objectexplorer, params): diff --git a/spyder/widgets/tests/test_reporterror.py b/spyder/widgets/tests/test_reporterror.py index 67647d410bc..0f81d1847f6 100644 --- a/spyder/widgets/tests/test_reporterror.py +++ b/spyder/widgets/tests/test_reporterror.py @@ -95,7 +95,6 @@ def test_report_issue_url(monkeypatch): target_url_base = __project_url__ + '/issues/new' MockQDesktopServices = MagicMock() - mockQDesktopServices_instance = MockQDesktopServices() attr_to_patch = ('spyder.widgets.reporterror.QDesktopServices') monkeypatch.setattr(attr_to_patch, MockQDesktopServices) @@ -103,14 +102,14 @@ def test_report_issue_url(monkeypatch): target_url = QUrl(target_url_base + '?body=' + body) SpyderErrorDialog.open_web_report(body=body, title=None) assert MockQDesktopServices.openUrl.call_count == 1 - mockQDesktopServices_instance.openUrl.called_with(target_url) + MockQDesktopServices.openUrl.assert_called_with(target_url) # Test when body != None and title != None target_url = QUrl(target_url_base + '?body=' + body + "&title=" + title) - SpyderErrorDialog.open_web_report(body=body, title=None) + SpyderErrorDialog.open_web_report(body=body, title=title) assert MockQDesktopServices.openUrl.call_count == 2 - mockQDesktopServices_instance.openUrl.called_with(target_url) + MockQDesktopServices.openUrl.assert_called_with(target_url) def test_render_issue():