1
0
forked from VimPlug/jedi

Save a module instead of a parser when pickling.

This commit is contained in:
Dave Halter
2017-03-30 00:55:04 +02:00
parent 932703f04a
commit 8059c3c2c8
9 changed files with 103 additions and 103 deletions

View File

@@ -9,7 +9,7 @@ import pytest
import jedi
from jedi import settings, cache
from jedi.parser.utils import ParserCacheItem, ParserPickling
from jedi.parser.utils import NodeCacheItem, ParserPickling
from jedi.parser.python import load_grammar
@@ -26,39 +26,40 @@ def test_modulepickling_change_cache_dir(monkeypatch, tmpdir):
dir_1 = str(tmpdir.mkdir('first'))
dir_2 = str(tmpdir.mkdir('second'))
item_1 = ParserCacheItem('fake parser 1')
item_2 = ParserCacheItem('fake parser 2')
item_1 = NodeCacheItem('bla', [])
item_2 = NodeCacheItem('bla', [])
path_1 = 'fake path 1'
path_2 = 'fake path 2'
monkeypatch.setattr(settings, 'cache_directory', dir_1)
grammar = load_grammar()
ParserPickling.save_parser(grammar, path_1, item_1)
ParserPickling.save_item(grammar, path_1, item_1)
cached = load_stored_item(grammar, ParserPickling, path_1, item_1)
assert cached == item_1.parser
assert cached == item_1.node
monkeypatch.setattr(settings, 'cache_directory', dir_2)
ParserPickling.save_parser(grammar, path_2, item_2)
ParserPickling.save_item(grammar, path_2, item_2)
cached = load_stored_item(grammar, ParserPickling, path_1, item_1)
assert cached is None
def load_stored_item(grammar, cache, path, item):
"""Load `item` stored at `path` in `cache`."""
return cache.load_parser(grammar, path, item.change_time - 1)
item = cache.load_item(grammar, path, item.change_time - 1)
return item and item.node
@pytest.mark.usefixtures("isolated_jedi_cache")
def test_modulepickling_delete_incompatible_cache():
item = ParserCacheItem('fake parser')
item = NodeCacheItem('fake parser', [])
path = 'fake path'
cache1 = ParserPicklingCls()
cache1.version = 1
grammar = load_grammar()
cache1.save_parser(grammar, path, item)
cache1.save_item(grammar, path, item)
cached1 = load_stored_item(grammar, cache1, path, item)
assert cached1 == item.parser
assert cached1 == item.node
cache2 = ParserPicklingCls()
cache2.version = 2
@@ -81,15 +82,15 @@ def test_modulepickling_simulate_deleted_cache():
__ https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
"""
item = ParserCacheItem('fake parser')
item = NodeCacheItem('fake parser', [])
path = 'fake path'
cache = ParserPicklingCls()
cache.version = 1
grammar = load_grammar()
cache.save_parser(grammar, path, item)
cache.save_item(grammar, path, item)
cached1 = load_stored_item(grammar, cache, path, item)
assert cached1 == item.parser
assert cached1 == item.node
unlink(cache._get_hashed_path(grammar, path))