def test_line_endings(workspace, newline):
    doc = Document(DOC_URI, workspace,
                   f'import os;import sys{2 * newline}dict(a=1)')
    res = pylsp_format_document(doc)

    assert apply_text_edits(
        doc,
        res) == f'import os{newline}import sys{2 * newline}dict(a=1){newline}'
Esempio n. 2
0
def test_config_file(tmpdir, workspace):
    # a config file in the same directory as the source file will be used
    conf = tmpdir.join('.style.yapf')
    conf.write('[style]\ncolumn_limit = 14')
    src = tmpdir.join('test.py')
    doc = Document(uris.from_fs_path(src.strpath), workspace, DOC)

    # A was split on multiple lines because of column_limit from config file
    assert pylsp_format_document(doc)[0]['newText'] == "A = [\n    'h', 'w',\n    'a'\n]\n\nB = ['h', 'w']\n"
def test_format_returns_text_edit_per_line(workspace):
    single_space_indent = """def wow():
 log("x")
 log("hi")"""
    doc = Document(DOC_URI, workspace, single_space_indent)
    res = pylsp_format_document(doc)

    # two removes and two adds
    assert len(res) == 4
    assert res[0]['newText'] == ""
    assert res[1]['newText'] == ""
    assert res[2]['newText'] == "    log(\"x\")\n"
    assert res[3]['newText'] == "    log(\"hi\")\n"
Esempio n. 4
0
def test_line_endings(workspace, newline):
    doc = Document(DOC_URI, workspace, f'import os;import sys{2 * newline}dict(a=1)')
    res = pylsp_format_document(doc)

    assert res[0]['newText'] == f'import os{newline}import sys{2 * newline}dict(a=1){newline}'
Esempio n. 5
0
def test_no_change(workspace):
    doc = Document(DOC_URI, workspace, GOOD_DOC)
    assert not pylsp_format_document(doc)
Esempio n. 6
0
def test_format(workspace):
    doc = Document(DOC_URI, workspace, DOC)
    res = pylsp_format_document(doc)

    assert len(res) == 1
    assert res[0]['newText'] == "A = ['h', 'w', 'a']\n\nB = ['h', 'w']\n"
def test_format_with_insert_spaces_option(workspace):
    doc = Document(DOC_URI, workspace, FOUR_SPACE_DOC)
    res = pylsp_format_document(doc, {"insertSpaces": False})

    assert apply_text_edits(doc, res) == FOUR_SPACE_DOC.replace("    ", "\t")
def test_format_with_tab_size_option(workspace):
    doc = Document(DOC_URI, workspace, FOUR_SPACE_DOC)
    res = pylsp_format_document(doc, {"tabSize": "8"})

    assert apply_text_edits(doc,
                            res) == FOUR_SPACE_DOC.replace("    ", "        ")
def test_format(workspace):
    doc = Document(DOC_URI, workspace, DOC)
    res = pylsp_format_document(doc)

    assert apply_text_edits(doc,
                            res) == "A = ['h', 'w', 'a']\n\nB = ['h', 'w']\n"
def test_format_with_yapf_specific_option(workspace):
    doc = Document(DOC_URI, workspace, FOUR_SPACE_DOC)
    res = pylsp_format_document(doc, {"USE_TABS": True})

    assert apply_text_edits(doc, res) == FOUR_SPACE_DOC.replace("    ", "\t")