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
|
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):
|
def find_tests(which_tests=None):
|
||||||
@ -69,6 +69,9 @@ def find_tests(which_tests=None):
|
|||||||
if ok('library'):
|
if ok('library'):
|
||||||
from calibre.library.test_cli import find_tests
|
from calibre.library.test_cli import find_tests
|
||||||
a(find_tests())
|
a(find_tests())
|
||||||
|
if ok('dictionaries'):
|
||||||
|
from calibre.spell.dictionary import find_tests
|
||||||
|
a(find_tests())
|
||||||
|
|
||||||
tests = unittest.TestSuite(ans)
|
tests = unittest.TestSuite(ans)
|
||||||
return tests
|
return tests
|
||||||
|
@ -415,27 +415,29 @@ class Dictionaries(object):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def test_dictionaries():
|
def find_tests():
|
||||||
dictionaries = Dictionaries()
|
import unittest
|
||||||
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'))
|
|
||||||
d = load_dictionary(get_dictionary(parse_lang_code('es'))).obj
|
|
||||||
assert d.recognized('Achí')
|
|
||||||
|
|
||||||
|
class TestDictionaries(unittest.TestCase):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def setUp(self):
|
||||||
test_dictionaries()
|
dictionaries = Dictionaries()
|
||||||
|
dictionaries.initialize()
|
||||||
|
eng = parse_lang_code('en')
|
||||||
|
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
|
||||||
|
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'))
|
||||||
|
|
||||||
|
return unittest.TestLoader().loadTestsFromTestCase(TestDictionaries)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user