Rewrote sys_path._paths_from_assignment.

This commit is contained in:
Dave Halter
2014-09-04 14:12:10 +02:00
parent 4180005893
commit 7b2e11d71b
4 changed files with 53 additions and 48 deletions

View File

@@ -1,9 +1,11 @@
import os
from textwrap import dedent
from jedi._compatibility import u
from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
_get_buildout_scripts,
_check_module)
from jedi.evaluate import Evaluator
from jedi.parser import Parser
from ..helpers import cwd_at
@@ -27,45 +29,45 @@ def test_buildout_detection():
def test_append_on_non_sys_path():
SRC = u("""
class Dummy(object):
path = []
SRC = dedent(u("""
class Dummy(object):
path = []
d = Dummy()
d.path.append('foo')""")
d = Dummy()
d.path.append('foo')"""))
p = Parser(SRC)
paths = _check_module(p.module)
paths = _check_module(Evaluator(), p.module)
assert len(paths) > 0
assert 'foo' not in paths
def test_path_from_invalid_sys_path_assignment():
SRC = u("""
import sys
sys.path = 'invalid'""")
SRC = dedent(u("""
import sys
sys.path = 'invalid'"""))
p = Parser(SRC)
paths = _check_module(p.module)
paths = _check_module(Evaluator(), p.module)
assert len(paths) > 0
assert 'invalid' not in paths
def test_path_from_sys_path_assignment():
SRC = u("""
#!/usr/bin/python
SRC = dedent(u("""
#!/usr/bin/python
import sys
sys.path[0:0] = [
'/usr/lib/python3.4/site-packages',
'/home/test/.buildout/eggs/important_package.egg'
]
import sys
sys.path[0:0] = [
'/usr/lib/python3.4/site-packages',
'/home/test/.buildout/eggs/important_package.egg'
]
path[0:0] = [1]
path[0:0] = [1]
import important_package
import important_package
if __name__ == '__main__':
sys.exit(important_package.main())""")
if __name__ == '__main__':
sys.exit(important_package.main())"""))
p = Parser(SRC)
paths = _check_module(p.module)
paths = _check_module(Evaluator(), p.module)
assert 1 not in paths
assert '/home/test/.buildout/eggs/important_package.egg' in paths