Fix failing test

This commit is contained in:
Kovid Goyal 2019-12-02 15:15:31 +05:30
parent a8cb5c96ba
commit 9d9cd957f2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 4 deletions

View File

@ -77,7 +77,7 @@ def extract_dicts(cache_path):
def is_cache_up_to_date(cache_path):
if hasattr(is_cache_up_to_date, 'updated'):
if getattr(is_cache_up_to_date, 'updated', False):
return True
hsh = P('hyphenation/sha1sum', data=True)
try:

View File

@ -10,7 +10,7 @@ import unittest
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.hyphenation.dictionaries import (
dictionary_name_for_locale, get_cache_path, path_to_dictionary
dictionary_name_for_locale, get_cache_path, path_to_dictionary, is_cache_up_to_date
)
from calibre.utils.hyphenation.hyphenate import (
add_soft_hyphens, dictionary_for_locale, remove_punctuation
@ -21,17 +21,19 @@ class TestHyphenation(unittest.TestCase):
ae = unittest.TestCase.assertEqual
def setUp(cls):
def setUp(self):
tdir = PersistentTemporaryDirectory()
path_to_dictionary.cache_dir = tdir
dictionary_name_for_locale.cache_clear()
dictionary_for_locale.cache_clear()
get_cache_path.cache_clear()
is_cache_up_to_date.updated = False
def tearDown(self):
dictionary_name_for_locale.cache_clear()
dictionary_for_locale.cache_clear()
get_cache_path.cache_clear()
is_cache_up_to_date.updated = False
try:
shutil.rmtree(path_to_dictionary.cache_dir)
except EnvironmentError:
@ -59,8 +61,9 @@ class TestHyphenation(unittest.TestCase):
def cache_callback():
cache[0] = True
dp = path_to_dictionary(dictionary_name_for_locale('en'), cache_callback)
self.assertTrue(
os.path.exists(path_to_dictionary(dictionary_name_for_locale('en'), cache_callback))
os.path.exists(dp), 'The dictionary {} does not exist'.format(dp)
)
self.assertTrue(cache[0])
cache[0] = False