From 0abd0d88eedba1e5f3abd03eba9faf4a9aecd25c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Dec 2019 13:40:29 +0530 Subject: [PATCH] Test cache usage --- src/calibre/utils/hyphenation/dictionaries.py | 4 +++- src/calibre/utils/hyphenation/test_hyphenation.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/calibre/utils/hyphenation/dictionaries.py b/src/calibre/utils/hyphenation/dictionaries.py index 8622cbda46..aa1df4d551 100644 --- a/src/calibre/utils/hyphenation/dictionaries.py +++ b/src/calibre/utils/hyphenation/dictionaries.py @@ -88,7 +88,7 @@ def is_cache_up_to_date(cache_path): return False -def path_to_dictionary(dictionary_name): +def path_to_dictionary(dictionary_name, cache_callback=None): cd = getattr(path_to_dictionary, 'cache_dir', None) or cache_dir() cache_path = os.path.join(cd, 'hyphenation') try: @@ -98,4 +98,6 @@ def path_to_dictionary(dictionary_name): raise if not is_cache_up_to_date(cache_path): extract_dicts(cache_path) + if cache_callback is not None: + cache_callback() return os.path.join(cache_path, 'f', dictionary_name) diff --git a/src/calibre/utils/hyphenation/test_hyphenation.py b/src/calibre/utils/hyphenation/test_hyphenation.py index 502250994c..1476083739 100644 --- a/src/calibre/utils/hyphenation/test_hyphenation.py +++ b/src/calibre/utils/hyphenation/test_hyphenation.py @@ -45,9 +45,21 @@ class TestHyphenation(unittest.TestCase): t('nl', 'nl_NL') t('fr', 'fr') t('XXX') + + cache = [False] + + def cache_callback(): + cache[0] = True + self.assertTrue( - os.path.exists(path_to_dictionary(dictionary_name_for_locale('en'))) + os.path.exists(path_to_dictionary(dictionary_name_for_locale('en'), cache_callback)) ) + self.assertTrue(cache[0]) + cache[0] = False + self.assertTrue( + os.path.exists(path_to_dictionary(dictionary_name_for_locale('es'), cache_callback)) + ) + self.assertFalse(cache[0]) def find_tests():