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): 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 return True
hsh = P('hyphenation/sha1sum', data=True) hsh = P('hyphenation/sha1sum', data=True)
try: try:

View File

@ -10,7 +10,7 @@ import unittest
from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.hyphenation.dictionaries import ( 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 ( from calibre.utils.hyphenation.hyphenate import (
add_soft_hyphens, dictionary_for_locale, remove_punctuation add_soft_hyphens, dictionary_for_locale, remove_punctuation
@ -21,17 +21,19 @@ class TestHyphenation(unittest.TestCase):
ae = unittest.TestCase.assertEqual ae = unittest.TestCase.assertEqual
def setUp(cls): def setUp(self):
tdir = PersistentTemporaryDirectory() tdir = PersistentTemporaryDirectory()
path_to_dictionary.cache_dir = tdir path_to_dictionary.cache_dir = tdir
dictionary_name_for_locale.cache_clear() dictionary_name_for_locale.cache_clear()
dictionary_for_locale.cache_clear() dictionary_for_locale.cache_clear()
get_cache_path.cache_clear() get_cache_path.cache_clear()
is_cache_up_to_date.updated = False
def tearDown(self): def tearDown(self):
dictionary_name_for_locale.cache_clear() dictionary_name_for_locale.cache_clear()
dictionary_for_locale.cache_clear() dictionary_for_locale.cache_clear()
get_cache_path.cache_clear() get_cache_path.cache_clear()
is_cache_up_to_date.updated = False
try: try:
shutil.rmtree(path_to_dictionary.cache_dir) shutil.rmtree(path_to_dictionary.cache_dir)
except EnvironmentError: except EnvironmentError:
@ -59,8 +61,9 @@ class TestHyphenation(unittest.TestCase):
def cache_callback(): def cache_callback():
cache[0] = True cache[0] = True
dp = path_to_dictionary(dictionary_name_for_locale('en'), cache_callback)
self.assertTrue( 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]) self.assertTrue(cache[0])
cache[0] = False cache[0] = False