spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.21k stars 1.59k forks source link

Another failing yapf test with 5.3.2: test_document_formatting #18763

Open juliangilbey opened 2 years ago

juliangilbey commented 2 years ago

Issue Report Checklist

Problem Description

Probably similarly to 895917a22892ffc0f7eae3e09d65262d9f95e08e, we have another failing yapf test:

_____________________ test_document_formatting[\r\n-yapf] ______________________

formatter = 'yapf', newline = '\r\n'
completions_codeeditor = (<spyder.plugins.editor.widgets.codeeditor.CodeEditor object at 0x7f2bb160de50>, <spyder.plugins.completion.plugin.CompletionPlugin object at 0x7f2bb15feaf0>)
qtbot = <pytestqt.qtbot.QtBot object at 0x7f2bb13c15e0>

    @pytest.mark.slow
    @pytest.mark.order(1)
    @pytest.mark.parametrize('formatter', [autopep8, yapf, black])
    @pytest.mark.parametrize('newline', ['\r\n', '\r', '\n'])
    def test_document_formatting(formatter, newline, completions_codeeditor,
                                 qtbot):
        """Validate text autoformatting via autopep8, yapf or black."""
        code_editor, completion_plugin = completions_codeeditor
        text, expected = get_formatter_values(formatter, newline)

        # Set formatter
        CONF.set(
            'completions',
            ('provider_configuration', 'lsp', 'values', 'formatting'),
            formatter
        )
        completion_plugin.after_configuration_update([])
        qtbot.wait(2000)

        # Set text in editor
        code_editor.set_text(text)

        # Assert eols are the expected ones
        assert code_editor.get_line_separator() == newline

        # Notify changes
        with qtbot.waitSignal(
                code_editor.completions_response_signal, timeout=30000):
            code_editor.document_did_change()

        # Perform formatting
        with qtbot.waitSignal(
                code_editor.completions_response_signal, timeout=30000):
            code_editor.format_document()

        # Wait for text to be formatted
        qtbot.wait(2000)

>       assert code_editor.get_text_with_eol() == expected
E       assert ('# -*- coding: utf-8 -*-\r\n'\n '"""\r\n'\n 'Spyder Editor\r\n'\n '\r\n'\n 'This is a temporary script file.\r\n'\n '"""\r\n'\n '\r\n'\n 'import os;import sys\r\n'\n '\r\n'\n '\r\n'\n '# %% functions\r\n'\n 'def d():\r\n'\n '    def inner():return 2\r\n'\n '    return inner\r\n'\n '# ---- func 1 and 2\r\n'\n 'def func1():\r\n'\n '    for i in range(3):\r\n'\n '        print(i)\r\n'\n 'def func2():\r\n'\n '    if True:\r\n'\n '        pass\r\n'\n '# ---- other functions\r\n'\n 'def a():\r\n'\n '    pass\r\n'\n 'def b():\r\n'\n '    pass\r\n'\n 'def c():\r\n'\n '    pass\r\n'\n '\r\n'\n '\r\n'\n '# %% classes\r\n'\n 'class Class1:\r\n'\n '    def __init__(self):\r\n'\n '        super(Class1, self).__init__()\r\n'\n '        self.x = 2\r\n'\n '\r\n'\n '    def method3(self):\r\n'\n '        pass\r\n'\n '\r\n'\n '    def method2(self):\r\n'\n '        pass\r\n'\n '\r\n'\n '    def method1(self):\r\n'\n '        pass\r\n') == ('# -*- coding: utf-8 -*-\r\n'\n '"""\r\n'\n 'Spyder Editor\r\n'\n '\r\n'\n 'This is a temporary script file.\r\n'\n '"""\r\n'\n '\r\n'\n 'import os\r\n'\n 'import sys\r\n'\n '\r\n'\n '\r\n'\n '# %% functions\r\n'\n 'def d():\r\n'\n '\r\n'\n '    def inner():\r\n'\n '        return 2\r\n'\n '\r\n'\n '    return inner\r\n'\n '\r\n'\n '\r\n'\n '# ---- func 1 and 2\r\n'\n 'def func1():\r\n'\n '    for i in range(3):\r\n'\n '        print(i)\r\n'\n '\r\n'\n '\r\n'\n 'def func2():\r\n'\n '    if True:\r\n'\n '        pass\r\n'\n '\r\n'\n '\r\n'\n '# ---- other functions\r\n'\n 'def a():\r\n'\n '    pass\r\n'\n '\r\n'\n '\r\n'\n 'def b():\r\n'\n '    pass\r\n'\n '\r\n'\n '\r\n'\n 'def c():\r\n'\n '    pass\r\n'\n '\r\n'\n '\r\n'\n '# %% classes\r\n'\n 'class Class1:\r\n'\n '\r\n'\n '    def __init__(self):\r\n'\n '        super(Class1, self).__init__()\r\n'\n '        self.x = 2\r\n'\n '\r\n'\n '    def method3(self):\r\n'\n '        pass\r\n'\n '\r\n'\n '    def method2(self):\r\n'\n '        pass\r\n'\n '\r\n'\n '    def method1(self):\r\n'\n '        pass\r\n')
E           # -*- coding: utf-8 -*-
E           """
E           Spyder Editor
E           
E           This is a temporary script file.
E           """
E           
E         + import os;import sys
E         - import os
E         - import sys
E           
E           
E           # %% functions
E           def d():
E         - 
E         -     def inner():
E         +     def inner():return 2
E         ?                 ++++++++
E         -         return 2
E         - 
E               return inner
E         - 
E         - 
E           # ---- func 1 and 2
E           def func1():
E               for i in range(3):
E                   print(i)
E         - 
E         - 
E           def func2():
E               if True:
E                   pass
E         - 
E         - 
E           # ---- other functions
E           def a():
E               pass
E         - 
E         - 
E           def b():
E               pass
E         - 
E         - 
E           def c():
E               pass
E           
E           
E           # %% classes
E           class Class1:
E         - 
E               def __init__(self):
E                   super(Class1, self).__init__()
E                   self.x = 2
E           
E               def method3(self):
E                   pass
E           
E               def method2(self):
E                   pass
E           
E               def method1(self):
E                   pass

spyder/plugins/editor/widgets/tests/test_formatting.py:115: AssertionError

and similarly for the other two line endings.

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0                 :  1.4.0 (OK)
chardet >=2.0.0                      :  4.0.0 (OK)
cloudpickle >=0.5.0                  :  2.0.0 (OK)
cookiecutter >=1.6.0                 :  1.7.3 (OK)
diff_match_patch >=20181111          :  20200713 (OK)
intervaltree >=3.0.2                 :  3.0.2 (OK)
IPython >=7.31.1                     :  7.31.1 (OK)
jedi >=0.17.2;<0.19.0                :  0.18.0 (OK)
jellyfish >=0.7                      :  0.8.9 (OK)
jsonschema >=3.2.0                   :  3.2.0 (OK)
keyring >=17.0.0                     :  23.7.0 (OK)
nbconvert >=4.0                      :  6.4.4 (OK)
numpydoc >=0.6.0                     :  1.3.1 (OK)
parso >=0.7.0;<0.9.0                 :  0.8.1 (OK)
pexpect >=4.4.0                      :  4.8.0 (OK)
pickleshare >=0.4                    :  0.7.5 (OK)
psutil >=5.3                         :  5.9.0 (OK)
pygments >=2.0                       :  2.12.0 (OK)
pylint >=2.5.0;<3.0                  :  2.12.2 (OK)
pyls_spyder >=0.4.0                  :  0.4.0 (OK)
pylsp >=1.5.0;<1.6.0                 :  1.5.0 (OK)
pylsp_black >=1.2.0                  :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0            :  3.0.3 (OK)
qstylizer >=0.1.10                   :  0.2.1 (OK)
qtawesome >=1.0.2                    :  1.1.1 (OK)
qtconsole >=5.3.0;<5.4.0             :  5.3.0 (OK)
qtpy >=2.1.0                         :  2.1.0 (OK)
rtree >=0.9.7                        :  1.0.0 (OK)
setuptools >=49.6.0                  :  59.6.0 (OK)
sphinx >=0.6.6                       :  4.5.0 (OK)
spyder_kernels >=2.3.2;<2.4.0        :  2.3.2 (OK)
textdistance >=4.2.0                 :  4.2.2 (OK)
three_merge >=0.1.1                  :  0.1.1 (OK)
watchdog >=0.10.3                    :  2.1.9 (OK)
xdg >=0.26                           :  0.27 (OK)
zmq >=22.1.0                         :  22.3.0 (OK)

# Optional:
cython >=0.21                        :  0.29.30 (OK)
matplotlib >=3.0.0                   :  3.5.2 (OK)
numpy >=1.7                          :  1.21.5 (OK)
pandas >=1.1.1                       :  1.3.5 (OK)
scipy >=0.17.0                       :  1.7.3 (OK)
sympy >=0.7.3                        :  1.10.1 (OK)

# Spyder plugins:
spyder_unittest.unittestplugin 0.5.0 :  0.5.0 (OK)
dalthviz commented 2 years ago

Hi @juliangilbey thank you for the feedback! Then I guess this is related with the some change introduced in PyLSP 1.5.0 🤔

We will try to give it a check for the next release :+1:

juliangilbey commented 1 year ago

Hmm, I just tested 6.0.0a1, and the yapf tests are still failing, also with the new spyder/plugins/editor/widgets/codeeditor/tests/test_formatting.py::test_document_formatting. This is utterly bizarre, as your CI logs show a very similar environment to ours; we're also using PyLSP 1.7.4.

juliangilbey commented 1 year ago

Though actually it doesn't seem to matter for now, as the Spyder configuration doesn't currently offer yapf as a formatting option.

ccordoba12 commented 1 year ago

Though actually it doesn't seem to matter for now, as the Spyder configuration doesn't currently offer yapf as a formatting option.

Yep, we haven't had time to add support for Yapf because now it sends text diffs after formatting.