mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-28 07:52:18 +08:00
Merge pull request #172 from tkf/test_modulepickling_change_cache_dir
ModulePickling should not save old cache when cache_directory is changed
This commit is contained in:
@@ -238,6 +238,7 @@ class _ModulePickling(object):
|
|||||||
return parser_cache_item.parser
|
return parser_cache_item.parser
|
||||||
|
|
||||||
def save_module(self, path, parser_cache_item):
|
def save_module(self, path, parser_cache_item):
|
||||||
|
self.__index = None
|
||||||
try:
|
try:
|
||||||
files = self._index[self.py_version]
|
files = self._index[self.py_version]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
33
test/test_cache.py
Normal file
33
test/test_cache.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from jedi import settings
|
||||||
|
from jedi.cache import ParserCacheItem, _ModulePickling
|
||||||
|
|
||||||
|
|
||||||
|
ModulePickling = _ModulePickling()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif("sys.version_info >= (3,0)")
|
||||||
|
def test_modulepickling_change_cache_dir(monkeypatch, tmpdir):
|
||||||
|
"""
|
||||||
|
ModulePickling should not save old cache when cache_directory is changed.
|
||||||
|
|
||||||
|
See: `#168 <https://github.com/davidhalter/jedi/pull/168>`_
|
||||||
|
"""
|
||||||
|
dir_1 = str(tmpdir.mkdir('first'))
|
||||||
|
dir_2 = str(tmpdir.mkdir('second'))
|
||||||
|
|
||||||
|
item_1 = ParserCacheItem('fake parser 1')
|
||||||
|
item_2 = ParserCacheItem('fake parser 2')
|
||||||
|
path_1 = 'fake path 1'
|
||||||
|
path_2 = 'fake path 2'
|
||||||
|
|
||||||
|
monkeypatch.setattr(settings, 'cache_directory', dir_1)
|
||||||
|
ModulePickling.save_module(path_1, item_1)
|
||||||
|
cached = ModulePickling.load_module(path_1, item_1.change_time - 1)
|
||||||
|
assert cached == item_1.parser
|
||||||
|
|
||||||
|
monkeypatch.setattr(settings, 'cache_directory', dir_2)
|
||||||
|
ModulePickling.save_module(path_2, item_2)
|
||||||
|
cached = ModulePickling.load_module(path_1, item_1.change_time - 1)
|
||||||
|
assert cached is None
|
||||||
Reference in New Issue
Block a user