def test_references(tmp_workspace):  # pylint: disable=redefined-outer-name
    # Over 'Test1' in class Test1():
    position = {'line': 0, 'character': 8}
    DOC1_URI = uris.from_fs_path(
        os.path.join(tmp_workspace.root_path, DOC1_NAME))
    doc1 = Document(DOC1_URI)

    refs = pyls_references(doc1, position)

    # Definition, the import and the instantiation
    assert len(refs) == 3

    # Briefly check excluding the definitions (also excludes imports, only counts uses)
    no_def_refs = pyls_references(doc1, position, exclude_declaration=True)
    assert len(no_def_refs) == 1

    # Make sure our definition is correctly located
    doc1_ref = [u for u in refs if u['uri'] == DOC1_URI][0]
    assert doc1_ref['range']['start'] == {'line': 0, 'character': 6}
    assert doc1_ref['range']['end'] == {'line': 0, 'character': 11}

    # Make sure our import is correctly located
    doc2_import_ref = [u for u in refs if u['uri'] != DOC1_URI][0]
    assert doc2_import_ref['range']['start'] == {'line': 0, 'character': 18}
    assert doc2_import_ref['range']['end'] == {'line': 0, 'character': 23}

    doc2_usage_ref = [u for u in refs if u['uri'] != DOC1_URI][1]
    assert doc2_usage_ref['range']['start'] == {'line': 2, 'character': 0}
    assert doc2_usage_ref['range']['end'] == {'line': 2, 'character': 5}
def test_non_root_project(upyls):
    repo_root = os.path.join(upyls.workspace.root_path, 'repo-root')
    os.mkdir(repo_root)
    project_root = os.path.join(repo_root, 'project-root')
    os.mkdir(project_root)

    with open(os.path.join(project_root, 'setup.py'), 'w+') as f:
        f.write('# setup.py')

    test_uri = uris.from_fs_path(os.path.join(project_root, 'hello/test.py'))
    upyls.workspace.put_document(test_uri, 'assert True')
    test_doc = upyls.workspace.get_document(test_uri)
    assert project_root in test_doc.sys_path()
# Copyright 2017 Palantir Technologies, Inc.
import pytest
from upyls import uris
from upyls.plugins import signature
from upyls.workspace import Document

DOC_URI = uris.from_fs_path(__file__)
DOC = """import sys

def main(param1, param2):
    \"\"\" Main docstring

    Args:
        param1 (str): Docs for param1
    \"\"\"
    raise Exception()

main(
"""

MULTI_LINE_DOC = """import sys

def main(param1=None,
            param2=None,
            param3=None,
            param4=None,
            param5=None,
            param6=None,
            param7=None,
            param8=None):
    \"\"\" Main docstring
Ejemplo n.º 4
0
# Copyright 2017 Palantir Technologies, Inc.
import os
from upyls import lsp, uris
from upyls.workspace import Document
from upyls.plugins import pydocstyle_lint

DOC_URI = uris.from_fs_path(
    os.path.join(os.path.dirname(__file__), "pydocstyle.py"))
TEST_DOC_URI = uris.from_fs_path(__file__)

DOC = """import sys

def hello():
\tpass

import json
"""


def test_pydocstyle(config):
    doc = Document(DOC_URI, DOC)
    diags = pydocstyle_lint.pyls_lint(config, doc)

    assert all([d['source'] == 'pydocstyle' for d in diags])

    # One we're expecting is:
    assert diags[0] == {
        'code': 'D100',
        'message': 'D100: Missing docstring in public module',
        'severity': lsp.DiagnosticSeverity.Warning,
        'range': {
 def create_file(name, content):
     fn = os.path.join(workspace.root_path, name)
     with open(fn, 'w') as f:
         f.write(content)
     workspace.put_document(uris.from_fs_path(fn), content)
def test_win_from_fs_path(path, uri):
    assert uris.from_fs_path(path) == uri
def test_get_missing_document(tmpdir, upyls):
    source = 'TEXT'
    doc_path = tmpdir.join("test_document.py")
    doc_path.write(source)
    doc_uri = uris.from_fs_path(str(doc_path))
    assert upyls.workspace.get_document(doc_uri).source == 'TEXT'