Skip to content

Commit

Permalink
Merge from 5.x: PR #17106
Browse files Browse the repository at this point in the history
Fixes #17102
Fixes #17101
Fixes #17100
  • Loading branch information
ccordoba12 committed Dec 28, 2021
2 parents f945b95 + 863a6d4 commit 2dfb483
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ def test_change_cwd_dbg(main_window, qtbot):

@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(os.name == 'nt' or PY2, reason="It times out sometimes")
@pytest.mark.skipif(os.name == 'nt', reason="Times out sometimes")
def test_varexp_magic_dbg(main_window, qtbot):
"""Test that %varexp is working while debugging."""
nsb = main_window.variableexplorer.current_widget()
Expand All @@ -1874,7 +1874,7 @@ def test_varexp_magic_dbg(main_window, qtbot):
qtbot.mouseClick(debug_button, Qt.LeftButton)

# Get to an object that can be plotted
for _ in range(2):
for _ in range(3):
with qtbot.waitSignal(shell.executed):
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
Expand Down
2 changes: 1 addition & 1 deletion spyder/config/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'autopep8': {
'enabled': True
},
'black': {
'pylsp_black': {
'enabled': False
},
'yapf': {
Expand Down
5 changes: 5 additions & 0 deletions spyder/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,14 @@ def add(modname, package_name, features, required_version,
"""Add Spyder dependency"""
global DEPENDENCIES
for dependency in DEPENDENCIES:
# Avoid showing an unnecessary error when running our tests.
if running_in_ci() and 'spyder_boilerplate' in modname:
continue

if dependency.modname == modname:
raise ValueError(
f"Dependency has already been registered: {modname}")

DEPENDENCIES += [Dependency(modname, package_name, features,
required_version,
installed_version, kind)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,17 @@ def generate_python_config(self):

# Autoformatting configuration
formatter = self.get_conf('formatting')
formatter = 'pyls_black' if formatter == 'black' else formatter
formatters = ['autopep8', 'yapf', 'pyls_black']
formatter = 'pylsp_black' if formatter == 'black' else formatter
formatters = ['autopep8', 'yapf', 'pylsp_black']
formatter_options = {
fmt: {
'enabled': fmt == formatter
}
for fmt in formatters
}

if formatter == 'pyls_black':
formatter_options['pyls_black']['line_length'] = cs_max_line_length
if formatter == 'pylsp_black':
formatter_options['pylsp_black']['line_length'] = cs_max_line_length

# PyLS-Spyder configuration
group_cells = self.get_conf(
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/editor/widgets/tests/assets/yapf_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# %% functions
def d():

def inner():
return 2

Expand Down
2 changes: 2 additions & 0 deletions spyder/plugins/editor/widgets/tests/assets/yapf_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# %% functions
def d():

def inner():
return 2

Expand Down Expand Up @@ -43,6 +44,7 @@ def c():

# %% classes
class Class1:

def __init__(self):
super(Class1, self).__init__()
self.x = 2
Expand Down
13 changes: 11 additions & 2 deletions spyder/plugins/editor/widgets/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Third party imports
import pytest
import yapf

# Qt imports
from qtpy.QtGui import QTextCursor
Expand All @@ -31,6 +32,14 @@
)
)

yapf = pytest.param(
'yapf',
marks=pytest.mark.skipif(
yapf.__version__ < '0.32.0',
reason='Older versions produce different outputs'
)
)


def get_formatter_values(formatter, range_fmt=False):
suffix = 'range' if range_fmt else 'result'
Expand All @@ -48,7 +57,7 @@ def get_formatter_values(formatter, range_fmt=False):

@pytest.mark.slow
@pytest.mark.order(1)
@pytest.mark.parametrize('formatter', [autopep8, 'yapf', 'black'])
@pytest.mark.parametrize('formatter', [autopep8, yapf, 'black'])
def test_document_formatting(formatter, completions_codeeditor, qtbot):
"""Validate text autoformatting via autopep8, yapf or black."""
code_editor, completion_plugin = completions_codeeditor
Expand Down Expand Up @@ -82,7 +91,7 @@ def test_document_formatting(formatter, completions_codeeditor, qtbot):
@pytest.mark.slow
@pytest.mark.order(1)
@pytest.mark.parametrize(
'formatter', [autopep8, 'yapf', 'black'])
'formatter', [autopep8, yapf, 'black'])
def test_document_range_formatting(formatter, completions_codeeditor, qtbot):
"""Validate text range autoformatting."""
code_editor, completion_plugin = completions_codeeditor
Expand Down
17 changes: 14 additions & 3 deletions spyder/plugins/editor/widgets/tests/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ def test_update_warnings_after_closequotes(qtbot, completions_codeeditor_linting
editor, _ = completions_codeeditor_linting
editor.textCursor().insertText("print('test)\n")

expected = [['EOL while scanning string literal', 1]]
if sys.version_info >= (3, 10):
expected = [['unterminated string literal (detected at line 1)', 1]]
else:
expected = [['EOL while scanning string literal', 1]]

# Notify changes.
with qtbot.waitSignal(editor.completions_response_signal, timeout=30000):
Expand Down Expand Up @@ -306,8 +309,16 @@ def test_update_warnings_after_closebrackets(qtbot, completions_codeeditor_linti
editor, _ = completions_codeeditor_linting
editor.textCursor().insertText("print('test'\n")

expected = [['unexpected EOF while parsing', 1],
['E901 TokenError: EOF in multi-line statement', 2]]
if sys.version_info >= (3, 10):
expected = [
["'(' was never closed", 1],
['E901 TokenError: EOF in multi-line statement', 2]
]
else:
expected = [
['unexpected EOF while parsing', 1],
['E901 TokenError: EOF in multi-line statement', 2]
]

# Notify changes.
with qtbot.waitSignal(editor.completions_response_signal, timeout=30000):
Expand Down

0 comments on commit 2dfb483

Please sign in to comment.