forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workspace.py
More file actions
50 lines (35 loc) · 1.52 KB
/
Copy pathtest_workspace.py
File metadata and controls
50 lines (35 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2017 Palantir Technologies, Inc.
import os
from pyls import uris
DOC_URI = uris.from_fs_path(__file__)
def test_local(pyls):
""" Since the workspace points to the test directory """
assert pyls.workspace.is_local()
def test_put_document(pyls):
pyls.workspace.put_document(DOC_URI, 'content')
assert DOC_URI in pyls.workspace._docs
def test_get_document(pyls):
pyls.workspace.put_document(DOC_URI, 'TEXT')
assert pyls.workspace.get_document(DOC_URI).source == 'TEXT'
def test_get_missing_document(tmpdir, pyls):
source = 'TEXT'
doc_path = tmpdir.join("test_document.py")
doc_path.write(source)
doc_uri = uris.from_fs_path(str(doc_path))
assert pyls.workspace.get_document(doc_uri).source == 'TEXT'
def test_rm_document(pyls):
pyls.workspace.put_document(DOC_URI, 'TEXT')
assert pyls.workspace.get_document(DOC_URI).source == 'TEXT'
pyls.workspace.rm_document(DOC_URI)
assert pyls.workspace.get_document(DOC_URI)._source is None
def test_non_root_project(pyls):
repo_root = os.path.join(pyls.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'))
pyls.workspace.put_document(test_uri, 'assert True')
test_doc = pyls.workspace.get_document(test_uri)
assert project_root in test_doc.sys_path()