Testing framework for new entity replacement code

This commit is contained in:
Kovid Goyal 2024-09-12 21:53:40 +05:30
parent aa3b09e77c
commit a46e9ef881
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* ANSI-C code produced by gperf version 3.1 */
/* Command-line: gperf -t --readonly --includes */
/* Command-line: gperf --struct-type --readonly --includes */
/* Computed positions: -k'1-7,10,12,$' */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \

View File

@ -2135,13 +2135,26 @@ html5_entities = {
}
def find_tests():
import unittest
class TestHTMLEntityReplacement(unittest.TestCase):
def test_html_entity_replacement(self):
from calibre_extensions.fast_html_entities import replace_entities
def t(inp, exp):
self.assertEqual(exp, replace_entities(inp), f'Failed for input: {inp!r}')
t('', '')
t('a', 'a')
return unittest.defaultTestLoader.loadTestsFromTestCase(TestHTMLEntityReplacement)
def generate_entity_lists():
import re
from html import entities as e
entities = {k.rstrip(';'): e.name2codepoint[k] for k in e.name2codepoint}
entities.update({k.rstrip(';'): e.html5[k] for k in e.html5})
# common misspelled entity names
for k, v in {'apos': "'", 'squot': "'", 'hellips': entities['hellip']}.items():
for k, v in {'squot': "'", 'hellips': entities['hellip']}.items():
if k not in entities:
entities[k] = v
lines = []

View File

@ -269,6 +269,8 @@ def find_tests(which_tests=None, exclude_tests=None):
a(find_tests())
from calibre.gui2.viewer.annotations import find_tests
a(find_tests())
from calibre.ebooks.html_entities import find_tests
a(find_tests())
if ok('misc'):
from calibre.ebooks.html.input import find_tests
a(find_tests())