From 860cf7b9743744c9d21796b227cf21d684fb5519 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 14 Mar 2013 21:33:36 +0100 Subject: [PATCH] Add test_modulepickling_change_cache_dir --- test/test_cache.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/test_cache.py diff --git a/test/test_cache.py b/test/test_cache.py new file mode 100644 index 00000000..9f845fc2 --- /dev/null +++ b/test/test_cache.py @@ -0,0 +1,30 @@ +from jedi import settings +from jedi.cache import ParserCacheItem, _ModulePickling + + +ModulePickling = _ModulePickling() + + +def test_modulepickling_change_cache_dir(monkeypatch, tmpdir): + """ + ModulePickling should not save old cache when cache_directory is changed. + + See: `#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