|
1 | 1 | # Copyright 2017 Palantir Technologies, Inc.
|
2 | 2 | import os
|
3 |
| -import os.path as osp |
4 | 3 | import sys
|
| 4 | + |
| 5 | +import pytest |
| 6 | + |
5 | 7 | from pyls import uris
|
6 | 8 |
|
7 | 9 | PY2 = sys.version_info.major == 2
|
|
16 | 18 |
|
17 | 19 |
|
18 | 20 | def path_as_uri(path):
|
19 |
| - return pathlib.Path(osp.abspath(path)).as_uri() |
| 21 | + return pathlib.Path(os.path.abspath(path)).as_uri() |
20 | 22 |
|
21 | 23 |
|
22 | 24 | def test_local(pyls):
|
@@ -49,21 +51,32 @@ def test_rm_document(pyls):
|
49 | 51 | assert pyls.workspace.get_document(DOC_URI)._source is None
|
50 | 52 |
|
51 | 53 |
|
52 |
| -def test_non_root_project(pyls): |
| 54 | +@pytest.mark.parametrize('metafiles', [('setup.py',), ('pyproject.toml',), ('setup.py', 'pyproject.toml')]) |
| 55 | +def test_non_root_project(pyls, metafiles): |
53 | 56 | repo_root = os.path.join(pyls.workspace.root_path, 'repo-root')
|
54 | 57 | os.mkdir(repo_root)
|
55 | 58 | project_root = os.path.join(repo_root, 'project-root')
|
56 | 59 | os.mkdir(project_root)
|
57 | 60 |
|
58 |
| - with open(os.path.join(project_root, 'setup.py'), 'w+') as f: |
59 |
| - f.write('# setup.py') |
| 61 | + for metafile in metafiles: |
| 62 | + with open(os.path.join(project_root, metafile), 'w+') as f: |
| 63 | + f.write('# ' + metafile) |
60 | 64 |
|
61 | 65 | test_uri = uris.from_fs_path(os.path.join(project_root, 'hello/test.py'))
|
62 | 66 | pyls.workspace.put_document(test_uri, 'assert True')
|
63 | 67 | test_doc = pyls.workspace.get_document(test_uri)
|
64 | 68 | assert project_root in test_doc.sys_path()
|
65 | 69 |
|
66 | 70 |
|
| 71 | +def test_root_project_with_no_setup_py(pyls): |
| 72 | + """Default to workspace root.""" |
| 73 | + workspace_root = pyls.workspace.root_path |
| 74 | + test_uri = uris.from_fs_path(os.path.join(workspace_root, 'hello/test.py')) |
| 75 | + pyls.workspace.put_document(test_uri, 'assert True') |
| 76 | + test_doc = pyls.workspace.get_document(test_uri) |
| 77 | + assert workspace_root in test_doc.sys_path() |
| 78 | + |
| 79 | + |
67 | 80 | def test_multiple_workspaces(tmpdir, pyls):
|
68 | 81 | workspace1_dir = tmpdir.mkdir('workspace1')
|
69 | 82 | workspace2_dir = tmpdir.mkdir('workspace2')
|
|
0 commit comments