mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Add a way to cwd into a tmpdir.
This commit is contained in:
@@ -131,3 +131,9 @@ def isolated_jedi_cache(monkeypatch, tmpdir):
|
|||||||
each test case (scope='function').
|
each test case (scope='function').
|
||||||
"""
|
"""
|
||||||
monkeypatch.setattr(settings, 'cache_directory', str(tmpdir))
|
monkeypatch.setattr(settings, 'cache_directory', str(tmpdir))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def cwd_tmpdir(monkeypatch, tmpdir):
|
||||||
|
with helpers.set_cwd(tmpdir.dirpath):
|
||||||
|
yield tmpdir
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ A helper module for testing, improves compatibility for testing (as
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
if sys.hexversion < 0x02070000:
|
if sys.hexversion < 0x02070000:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
else:
|
else:
|
||||||
@@ -29,12 +31,19 @@ def cwd_at(path):
|
|||||||
def decorator(func):
|
def decorator(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwds):
|
def wrapper(*args, **kwds):
|
||||||
try:
|
with set_cwd(path):
|
||||||
oldcwd = os.getcwd()
|
|
||||||
repo_root = os.path.dirname(test_dir)
|
|
||||||
os.chdir(os.path.join(repo_root, path))
|
|
||||||
return func(*args, **kwds)
|
return func(*args, **kwds)
|
||||||
finally:
|
|
||||||
os.chdir(oldcwd)
|
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def set_cwd(path, absolute_path=False):
|
||||||
|
repo_root = os.path.dirname(test_dir)
|
||||||
|
|
||||||
|
oldcwd = os.getcwd()
|
||||||
|
os.chdir(os.path.join(repo_root, path))
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
os.chdir(oldcwd)
|
||||||
|
|||||||
Reference in New Issue
Block a user