mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add a flag to abort when a psedo element is missing
This commit is contained in:
parent
0f1fbf0a8c
commit
825905a092
@ -237,10 +237,14 @@ def resolve_property(style_map, elem, name):
|
||||
q = q.getparent() if inheritable else None
|
||||
return defvals().get(name)
|
||||
|
||||
def resolve_pseudo_property(style_map, pseudo_style_map, elem, prop, name):
|
||||
def resolve_pseudo_property(style_map, pseudo_style_map, elem, prop, name, abort_on_missing=False):
|
||||
sub_map = pseudo_style_map.get(elem)
|
||||
if abort_on_missing and sub_map is None:
|
||||
return None
|
||||
if sub_map is not None:
|
||||
prop_map = sub_map.get(prop)
|
||||
if abort_on_missing and prop_map is None:
|
||||
return None
|
||||
if prop_map is not None:
|
||||
val = prop_map.get(name)
|
||||
if val is not None:
|
||||
|
@ -72,9 +72,13 @@ class CascadeTest(BaseTest):
|
||||
val = type('')(DEFAULTS[name])
|
||||
self.assertEqual(val, ans.cssText)
|
||||
|
||||
def test_pseudo_property(select, resolve_pseudo_property, selector, prop, name, val=None):
|
||||
def test_pseudo_property(select, resolve_pseudo_property, selector, prop, name, val=None, abort_on_missing=False):
|
||||
elem = next(select(selector))
|
||||
ans = resolve_pseudo_property(elem, prop, name)
|
||||
ans = resolve_pseudo_property(elem, prop, name, abort_on_missing=abort_on_missing)
|
||||
if abort_on_missing:
|
||||
if val is None:
|
||||
self.assertTrue(ans is None)
|
||||
return
|
||||
if val is None:
|
||||
val = type('')(DEFAULTS[name])
|
||||
self.assertEqual(val, ans.cssText)
|
||||
@ -125,4 +129,5 @@ class CascadeTest(BaseTest):
|
||||
t('p', 'before', 'content', 'xxx')
|
||||
t('p', 'before', 'margin-top', '0')
|
||||
t('p', 'before', 'font-weight', 'bold')
|
||||
t('p', 'first-letter', 'content', 'normal')
|
||||
t('p', 'first-letter', 'content')
|
||||
t('p', 'first-letter', 'content', abort_on_missing=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user