def test_string_value(self): text = atom.Text(None) text.set_value("Some text") self.assertTrue(text.get_value() == "Some text", "String constructor data") self.assertTrue(text.type == atom.TextType.text, "Default text type not 'text' on construction") text = atom.Text(None) text.set_value("Some other text", atom.TextType.xhtml) self.assertTrue(text.get_value() == 'Some other text', "String constructor data: found %s" % text.get_value()) self.assertTrue(text.type == atom.TextType.xhtml, "Override text type on construction")
def test_constructor(self): text = atom.Text(None) self.assertTrue(text.xmlname is None, 'element name on construction') self.assertTrue(isinstance(text, atom.AtomElement), "Text not an AtomElement") self.assertTrue(text.get_base() is None, "xml:base present on construction") self.assertTrue(text.get_lang() is None, "xml:lang present on construction") attrs = text.get_attributes() self.assertTrue(sum(1 for k in dict_keys(attrs)) == 1, "Attributes present on construction") self.assertTrue(text.get_value() == '', "Content present on construction")
def test_types(self): """Text constructs MAY have a "type" attribute. When present, the value MUST be one of "text", "html", or "xhtml". If the "type" attribute is not provided, Atom Processors MUST behave as though it were present with a value of "text".""" text = atom.Text(None) attrs = text.get_attributes() self.assertTrue(text.type == atom.TextType.text and attrs[(xmlns.NO_NAMESPACE, 'type')] == "text", "Default text type not 'text' on construction") text.set_value('<p>Hello', atom.TextType.html) self.assertTrue(text.type == atom.TextType.html, "html text type failed") text.set_value('<p>Hello</p>', atom.TextType.xhtml) self.assertTrue(text.type == atom.TextType.xhtml, "xhtml text type failed") try: text.set_value('Hello\\par ', 'rtf') self.fail("rtf text type failed to raise error") except ValueError: pass