forked from VimPlug/jedi
Add any .egg-link paths from VIRTUAL_ENV to sys.path
Adding test_get_sys_path required factoring out `_get_venv_sitepackages`, because `sys.version_info` cannot be mocked apparently.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -16,17 +17,26 @@ def get_sys_path():
|
||||
if not venv:
|
||||
return
|
||||
venv = os.path.abspath(venv)
|
||||
if os.name == 'nt':
|
||||
p = os.path.join(venv, 'lib', 'site-packages')
|
||||
else:
|
||||
p = os.path.join(venv, 'lib', 'python%d.%d' % sys.version_info[:2],
|
||||
'site-packages')
|
||||
p = _get_venv_sitepackages(venv)
|
||||
if p not in sys_path:
|
||||
sys_path.insert(0, p)
|
||||
|
||||
# Add all egg-links from the virtualenv.
|
||||
for egg_link in glob.glob(os.path.join(p, '*.egg-link')):
|
||||
with open(egg_link) as fd:
|
||||
sys_path.insert(0, fd.readline().rstrip())
|
||||
|
||||
check_virtual_env(sys.path)
|
||||
return [p for p in sys.path if p != ""]
|
||||
|
||||
def _get_venv_sitepackages(venv):
|
||||
if os.name == 'nt':
|
||||
p = os.path.join(venv, 'lib', 'site-packages')
|
||||
else:
|
||||
p = os.path.join(venv, 'lib', 'python%d.%d' % sys.version_info[:2],
|
||||
'site-packages')
|
||||
return p
|
||||
|
||||
|
||||
def _execute_code(module_path, code):
|
||||
c = "import os; from os.path import *; result=%s"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
addopts = --doctest-modules
|
||||
|
||||
# Ignore broken files in blackbox test directories
|
||||
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed static_analysis not_in_sys_path buildout_project
|
||||
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed static_analysis not_in_sys_path buildout_project egg-link
|
||||
|
||||
# Activate `clean_jedi_cache` fixture for all tests. This should be
|
||||
# fine as long as we are using `clean_jedi_cache` as a session scoped
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/path/from/egg-link
|
||||
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from jedi._compatibility import unicode
|
||||
from jedi.parser import Parser, load_grammar
|
||||
from jedi.evaluate import sys_path, Evaluator
|
||||
@@ -15,3 +17,15 @@ def test_paths_from_assignment():
|
||||
|
||||
# Fail for complicated examples.
|
||||
assert paths('sys.path, other = ["a"], 2') == []
|
||||
|
||||
|
||||
def test_get_sys_path(monkeypatch):
|
||||
monkeypatch.setenv('VIRTUAL_ENV', os.path.join(os.path.dirname(__file__),
|
||||
'egg-link', 'venv'))
|
||||
def sitepackages_dir(venv):
|
||||
return os.path.join(venv, 'lib', 'python3.4', 'site-packages')
|
||||
|
||||
monkeypatch.setattr('jedi.evaluate.sys_path._get_venv_sitepackages',
|
||||
sitepackages_dir)
|
||||
|
||||
assert '/path/from/egg-link' in sys_path.get_sys_path()
|
||||
|
||||
Reference in New Issue
Block a user