john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

xml domish pytest

import pytest
from twisted.words.xish import domish


@pytest.mark.usefixtures()
class TestDomish( object ):

    def test_element( self ):
        root = domish.Element( ( 'myxmlnamespace', 'root' ) )    # tuple parameter is the xmlns type and structure of the xml
        assert "<root xmlns='myxmlnamespace'/>" == root.toXml()

    def test_element_attribute( self ):
        root = domish.Element( ( 'myxmlnamespace', 'root' ) )
        root['myattribute'] = 'green'
        assert "<root xmlns='myxmlnamespace' myattribute='green'/>" == root.toXml()

    def test_element_add_empty_element( self ):
        root = domish.Element( ( 'myxmlnamespace', 'root' ) )
        root.addElement( 'child' )
        assert "<root xmlns='myxmlnamespace'><child/></root>" == root.toXml()


    def test_element_add_element_value( self ):
        root = domish.Element( ( 'myxmlnamespace', 'root' ) )
        root.addElement( 'child', content='value' )
        assert "<root xmlns='myxmlnamespace'><child>value</child></root>" == root.toXml()



    def test_html_example( self ):
        html = domish.Element( ( "http://www.w3.org/1999/xhtml", 'html' ) )
        head = domish.Element( ( None, 'head' ) )
        head.addElement( 'title', content='my page' )
        html.addChild( head )
        html.addElement( 'body', content=' ' )
        print html.toXml()
        assert "<html xmlns='http://www.w3.org/1999/xhtml'><head><title>my page</title></head><body> </body></html>" == html.toXml()

  • « input reader stdio commands get url
  • deferToThread blocking call LoopingCall »

Published

Jul 19, 2013

Category

python-twisted

~101 words

Tags

  • domish 1
  • pytest 6
  • python 180
  • twisted 20
  • xml 22