mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add the dictionary tests to the global test suite
This commit is contained in:
parent
97a1a92e1b
commit
2d185e8f9f
@ -8,7 +8,7 @@ import unittest
|
||||
|
||||
from setup import Command
|
||||
|
||||
TEST_MODULES = frozenset('srv db polish opf css docx cfi matcher icu smartypants build misc library'.split())
|
||||
TEST_MODULES = frozenset('srv db polish opf css docx cfi matcher icu smartypants build misc library dictionaries'.split())
|
||||
|
||||
|
||||
def find_tests(which_tests=None):
|
||||
@ -69,6 +69,9 @@ def find_tests(which_tests=None):
|
||||
if ok('library'):
|
||||
from calibre.library.test_cli import find_tests
|
||||
a(find_tests())
|
||||
if ok('dictionaries'):
|
||||
from calibre.spell.dictionary import find_tests
|
||||
a(find_tests())
|
||||
|
||||
tests = unittest.TestSuite(ans)
|
||||
return tests
|
||||
|
@ -415,27 +415,29 @@ class Dictionaries(object):
|
||||
return ans
|
||||
|
||||
|
||||
def test_dictionaries():
|
||||
def find_tests():
|
||||
import unittest
|
||||
|
||||
class TestDictionaries(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
dictionaries = Dictionaries()
|
||||
dictionaries.initialize()
|
||||
eng = parse_lang_code('en')
|
||||
rec = partial(dictionaries.recognized, locale=eng)
|
||||
sg = partial(dictionaries.suggestions, locale=eng)
|
||||
if not rec('recognized'):
|
||||
raise ValueError('recognized not recognized')
|
||||
if not rec('one-half'):
|
||||
raise ValueError('one-half not recognized')
|
||||
if not rec('one\u2010half'):
|
||||
raise ValueError('one\u2010half not recognized with unicode hyphen (U+2010)')
|
||||
if 'one\u2010half' not in sg('oone\u2010half'):
|
||||
raise ValueError('Unicode hyphen not preserved in suggestions')
|
||||
if 'adequately' not in sg('ade-quately'):
|
||||
raise ValueError('adequately not in %s' % sg('ade-quately'))
|
||||
if 'magic. Wand' not in sg('magic.wand'):
|
||||
raise ValueError('magic. Wand not in: %s' % sg('magic.wand'))
|
||||
self.recognized = partial(dictionaries.recognized, locale=eng)
|
||||
self.suggestions = partial(dictionaries.suggestions, locale=eng)
|
||||
|
||||
def ar(self, w):
|
||||
if not self.recognized(w):
|
||||
raise AssertionError('The word %r was not recognized' % w)
|
||||
|
||||
def test_dictionaries(self):
|
||||
for w in 'recognized one-half one\u2010half'.split():
|
||||
self.ar(w)
|
||||
d = load_dictionary(get_dictionary(parse_lang_code('es'))).obj
|
||||
assert d.recognized('Achí')
|
||||
self.assertTrue(d.recognized('Achí'))
|
||||
self.assertIn('one\u2010half', self.suggestions('oone\u2010half'))
|
||||
self.assertIn('adequately', self.suggestions('ade-quately'))
|
||||
self.assertIn('magic. Wand', self.suggestions('magic.wand'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_dictionaries()
|
||||
return unittest.TestLoader().loadTestsFromTestCase(TestDictionaries)
|
||||
|
Loading…
x
Reference in New Issue
Block a user