Test cache usage

This commit is contained in:
Kovid Goyal 2019-12-01 13:40:29 +05:30
parent cd4f231d74
commit 0abd0d88ee
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 2 deletions

View File

@ -88,7 +88,7 @@ def is_cache_up_to_date(cache_path):
return False 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() cd = getattr(path_to_dictionary, 'cache_dir', None) or cache_dir()
cache_path = os.path.join(cd, 'hyphenation') cache_path = os.path.join(cd, 'hyphenation')
try: try:
@ -98,4 +98,6 @@ def path_to_dictionary(dictionary_name):
raise raise
if not is_cache_up_to_date(cache_path): if not is_cache_up_to_date(cache_path):
extract_dicts(cache_path) extract_dicts(cache_path)
if cache_callback is not None:
cache_callback()
return os.path.join(cache_path, 'f', dictionary_name) return os.path.join(cache_path, 'f', dictionary_name)

View File

@ -45,9 +45,21 @@ class TestHyphenation(unittest.TestCase):
t('nl', 'nl_NL') t('nl', 'nl_NL')
t('fr', 'fr') t('fr', 'fr')
t('XXX') t('XXX')
cache = [False]
def cache_callback():
cache[0] = True
self.assertTrue( 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(): def find_tests():