From 88f8e172d5db6dffca9dd648832e9cb4df2c1cfc Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 19 May 2017 16:28:07 -0400 Subject: [PATCH] Fixed a bug where providing a cache_path did not really affect anything. --- parso/cache.py | 3 ++- test/test_cache.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/parso/cache.py b/parso/cache.py index 4b4c884..bc9cef0 100644 --- a/parso/cache.py +++ b/parso/cache.py @@ -152,8 +152,9 @@ def clear_cache(cache_path=None): def _get_hashed_path(grammar, path, cache_path=None): + directory = _get_cache_directory_path(cache_path=cache_path) + file_hash = hashlib.sha256(path.encode("utf-8")).hexdigest() - directory = _get_cache_directory_path() return os.path.join(directory, '%s-%s.pkl' % (grammar.sha256, file_hash)) diff --git a/test/test_cache.py b/test/test_cache.py index d67f57d..99dfacc 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -23,7 +23,7 @@ def isolated_jedi_cache(monkeypatch, tmpdir): monkeypatch.setattr(cache, '_default_cache_path', str(tmpdir)) -def test_modulepickling_change_cache_dir(monkeypatch, tmpdir): +def test_modulepickling_change_cache_dir(tmpdir): """ ParserPickling should not save old cache when cache_directory is changed. @@ -37,22 +37,20 @@ def test_modulepickling_change_cache_dir(monkeypatch, tmpdir): path_1 = 'fake path 1' path_2 = 'fake path 2' - monkeypatch.setattr(cache, '_default_cache_path', dir_1) grammar = load_grammar() - _save_to_file_system(grammar, path_1, item_1) + _save_to_file_system(grammar, path_1, item_1, cache_path=dir_1) parser_cache.clear() - cached = load_stored_item(grammar, path_1, item_1) + cached = load_stored_item(grammar, path_1, item_1, cache_path=dir_1) assert cached == item_1.node - monkeypatch.setattr(cache, '_default_cache_path', dir_2) - _save_to_file_system(grammar, path_2, item_2) - cached = load_stored_item(grammar, path_1, item_1) + _save_to_file_system(grammar, path_2, item_2, cache_path=dir_2) + cached = load_stored_item(grammar, path_1, item_1, cache_path=dir_2) assert cached is None -def load_stored_item(grammar, path, item): +def load_stored_item(grammar, path, item, cache_path): """Load `item` stored at `path` in `cache`.""" - item = _load_from_file_system(grammar, path, item.change_time - 1) + item = _load_from_file_system(grammar, path, item.change_time - 1, cache_path) return item