def test_set_none(self): from cocktail.html.element import Element e = Element() e.set_style("font-weight", "bold") # Setting a meta attribute to None removes it from its element e.set_style("font-weight", None) self.assertFalse("font-weight" in e.style)
def test_attribute(self): from cocktail.html.element import Element e = Element() e.set_style("font-weight", "bold") self.assertEqual(e["style"], "font-weight: bold") e.set_style("font-style", "italic") self.assertEqual(set(e["style"].split("; ")), set(["font-weight: bold", "font-style: italic"]))
def test_dict(self): from cocktail.html.element import Element # An element starts with no style declarations e = Element() self.assertEqual(e.style, {}) # Style declarations set on the element show on its 'style' collection e.set_style("text-decoration", "underline") e.set_style("font-size", "2em") self.assertEqual(e.style, { "text-decoration": "underline", "font-size": "2em" })
def test_get_set(self): from cocktail.html.element import Element e = Element() # Style declarations can be set and read e.set_style("font-weight", "bold") e.set_style("margin", "1em") self.assertEqual(e.get_style("font-weight"), "bold") self.assertEqual(e.get_style("margin"), "1em") # Style declarations can be changed e.set_style("font-weight", "normal") self.assertEqual(e.get_style("font-weight"), "normal")
def create_tag_entry(self, tag, frequency): entry = Element("a") entry.label = self.create_tag_label(tag, frequency) entry.append(entry.label) entry.set_style("font-size", str(self._font_sizes[tag]) + "%") return entry