def test_overwrite_style(self): self.rule.style = CSSStyleDeclaration() self.rule.style.color = 'red' self.assertEqual(self.rule.cssText, ' {color: red;}') self.rule.selectorText = 'h1' self.assertEqual(self.rule.cssText, 'h1 {color: red;}') self.rule.selectorText = 'h1,h2' self.assertEqual(self.rule.cssText, 'h1,h2 {color: red;}') self.rule.style.removeProperty('color') self.assertEqual(self.rule.cssText, '')
def test_style_new(self): st = CSSStyleDeclaration() self.assertEqual(self.elm.style.cssText, '') self.assertEqual(st.cssText, '') st.setProperty('color', 'red') self.assertEqual(st.cssText, 'color: red;') self.assertEqual(self.elm.style.cssText, '') self.elm.style = st self.assertEqual(self.elm.style.cssText, 'color: red;') st.setProperty('color', 'blue') self.assertEqual(st.cssText, 'color: blue;') # shouldn't do this??? self.assertEqual(self.elm.style.cssText, 'color: blue;')
def style(self, style: _AttrValueType) -> None: """Set style attribute of this node. If argument ``style`` is string, it will be parsed to ``CSSStyleDeclaration``. """ if isinstance(style, str): self.__style._parse_str(style) elif style is None: self.__style._parse_str('') elif isinstance(style, CSSStyleDeclaration): self.__style._owner = None if style._owner is not None: new_style = CSSStyleDeclaration(owner=self) new_style.update(style) self.__style = new_style else: # always making new decl may be better style._owner = self self.__style = style else: raise TypeError('Invalid type for style: {}'.format(type(style)))
def setUp(self): self.css = CSSStyleDeclaration()
def test_append2(self): self.list.append(self.rule) rule2 = CSSStyleRule('h2', CSSStyleDeclaration('background: black;')) self.list.append(rule2) css = self.list.cssText self.assertIn('h1 {color: red;}\nh2 {background: black;}', css)
def setUp(self): self.list = CSSRuleList() self.style = CSSStyleDeclaration() self.style.color = 'red' self.rule = CSSStyleRule('h1', self.style)
def test_init(self): style = CSSStyleDeclaration() style.color = 'red' rule = CSSStyleRule('h1', style) self.assertEqual(rule.cssText, 'h1 {color: red;}')
def __init__(self, *args: Any, style: str = None, **kwargs: Any) -> None: # noqa: D102 super().__init__(*args, **kwargs) self.__style = CSSStyleDeclaration(style, owner=self)