Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Fix some tests failing on Python 3.12 #21692

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions spyder/plugins/editor/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,36 @@ def test_renamed_tree(editor_plugin, mocker):
editor = editor_plugin
mocker.patch.object(editor, 'get_filenames')
mocker.patch.object(editor, 'renamed')
editor.get_filenames.return_value = ['/test/directory/file1.py',
'/test/directory/file2.txt',
'/home/spyder/testing/file3.py',
'/test/directory/file4.rst']

editor.renamed_tree('/test/directory', '/test/dir')
if os.name == "nt":
filenames = [r'C:\test\directory\file1.py',
r'C:\test\directory\file2.txt',
r'C:\home\spyder\testing\file3.py',
r'C:\test\directory\file4.rst']
expected = [r'C:\test\dir\file1.py',
r'C:\test\dir\file2.txt',
r'C:\home\spyder\testing\file3.py',
r'C:\test\dir\file4.rst']
sourcedir = r'C:\test\directory'
destdir = r'C:\test\dir'
else:
filenames = ['/test/directory/file1.py',
'/test/directory/file2.txt',
'/home/spyder/testing/file3.py',
'/test/directory/file4.rst']
expected = ['/test/dir/file1.py',
'/test/dir/file2.txt',
'/home/spyder/testing/file3.py',
'/test/dir/file4.rst']
sourcedir = '/test/directory'
destdir = '/test/dir'

editor.get_filenames.return_value = filenames

editor.renamed_tree(sourcedir, destdir)
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')
for file in [0, 1, 3]:
editor.renamed.assert_any_call(source=filenames[file],
dest=expected[file])


def test_no_template(editor_plugin):
Expand Down
14 changes: 12 additions & 2 deletions spyder/plugins/editor/widgets/tests/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions spyder/widgets/tests/test_reporterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,21 @@ 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)

# Test when body != None, i.e. when auto-submitting error to Github
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():
Expand Down
Loading