コード例 #1
0
def findmeld_test1():
    """ XML namespace unit test - find_meld - one element """
    x = xml.Renderer()
    node = x.parse_xmlstring(xml_test1_in)
    child = node.findmeld('child')

    assert child is not None
コード例 #2
0
def global_test7():
    """ XML namespace unit test - meld3 - test option write_xmlstring method with option pipeline=True """
    x = xml.Renderer()
    root = x.parse_xmlstring(xml_test2_in)

    root.findmeld('title').text = 'My document'
    root.findmeld('form1').set('action', './handler')

    data = (
        {'name': 'Girls',
         'description': 'Pretty'},
        {'name': 'Boys',
         'description': 'Ugly'},
        )

    children = []
    for elt in data:
        children.append(x.tr([x.td(elt['name']), x.td(elt['description'])], {'class': 'bar'}))

    root.findmeld('tr').replace(children)

    root.write_xmlstring(xml_declaration=True, pretty_print=True, pipeline=False).strip()

    assert root.findmeld('tr') is None
    assert root.findmeld('content_well') is None
コード例 #3
0
def parse_xmlstring_test4():
    """ XML namespace unit test - parse_xmlstring - parse xml tree with fragment flag """
    x = xml.Renderer()
    roots = x.parse_xmlstring(xml_fragments_1, fragment=True, no_leading_text=True)
    assert roots[0].write_xmlstring() == "<fragment1/>text"
    assert roots[0].tail == "text"
    assert roots[1].write_xmlstring() == "<fragment2/>"
コード例 #4
0
def root_test2():
    """ XML namespace unit test - root - two elements """
    x = xml.Renderer()
    x << x.node()
    x << x.node()

    assert isinstance(x.root, ListType)
コード例 #5
0
ファイル: test_xmlns.py プロジェクト: lorb888/core
def test_global8():
    """ XML namespace unit test - create xml """
    x = xml.Renderer()
    x.namespaces = {'meld': 'http://www.plope.com/software/meld3'}
    data = (
        {'name': 'Girls', 'description': 'Pretty'},
        {'name': 'Boys', 'description': 'Ugly'},
    )

    with x.html:
        with x.head:
            with x.meta:
                x << {'content': 'text/html; charset=ISO-8859-1', 'http-equiv': 'content-type'}
            with x.title.meld_id('title'):
                x << 'My document'
        with x.body:
            with x.div:
                pass
            x << x.comment(' empty tag ')
            with x.div:
                with x.form.meld_id('form1'):
                    x << {'action': './handler'}
                    with x.table:
                        with x.tbody:
                            with x.tr:
                                x << x.th('Name') << x.th('Description')
                            for elt in data:
                                with x.tr.meld_id('tr'):
                                    x << x.td(elt['name']).meld_id('td') << x.td(elt['description']).meld_id('td')
                    with x.input:
                        x << {'type': 'submit', 'name': 'next', 'value': ' Next '}

    assert [elt.text for elt in x.root.xpath('.//td')] == ['Girls', 'Pretty', 'Boys', 'Ugly']
    assert x.root[0][1].text == 'My document'
    assert x.root.xpath('.//form')[0].attrib['action'] == './handler'
コード例 #6
0
ファイル: test_database.py プロジェクト: rezaghanimi/core
def test_3():
    """ database - test with elixir & framework render method """
    app = App1()

    filePath = os.path.join(os.path.dirname(__file__), 'helloworld.csv')
    reader = csv.reader(open(filePath, 'r'))

    res = {}
    for row in reader:
        res[row[0].decode('utf-8')] = row[1].decode('utf-8')
        Language(id=row[0].decode('utf-8'), label=row[1].decode('utf-8'))
    session.flush()

    for language in Language.query.all():
        app.add_language(language)

    h = xml.Renderer()
    xmlToTest = component.Component(app).render(h).write_xmlstring(
        xml_declaration=True, pretty_print=True).strip()

    f = open(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
    xmlToCompare = f.read()
    f.close()

    assert xmlToTest == xmlToCompare
コード例 #7
0
ファイル: test_xslns.py プロジェクト: bcroq/nagare-namespaces
def test1():
    """ XSL namespace unit test - simple xsl transformation 1 """
    x = xsl.Renderer()
    x.namespaces = {'xsl': 'http://www.w3.org/1999/XSL/Transform'}
    x.default_namespace = 'xsl'

    styleSheet = x.stylesheet(
        x.output(encoding="utf-8", method="html"),
        x.template(x.copy(x.apply_templates(select="@*|node()")), match="@*|node()"),
        x.template(x.element(name="head"),
                   x.element(x.element(x.apply_templates(select="@*|node()"), name="body"), name="html"),
                   match="helloWorlds"),
        x.template(x.element(x.value_of(select="@language"), ' : ', x.value_of(select="."), name="h1"), match="helloWorld")
    )

    x = xml.Renderer()

    f = open(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
    root = x.parse_xmlstring(f.read())
    f.close()

    r = root.getroottree().xslt(styleSheet)

    f = open(os.path.join(os.path.dirname(__file__), 'helloworld.html'))
    xmlToCompare = f.read()
    f.close()

    assert r.__str__().strip() == xmlToCompare
コード例 #8
0
def init_portal_xml_published_ideas(self, url, comp, http_method, request):
    root = comp.render(xml.Renderer(), model='xml_published_ideas')
    # Now we need to fix the avatar urls because we can't pass the request object to the component
    # render function (or did I missed something ?)
    for node in root.xpath('//avatar'):
        node.text = request.application_url + node.text
    raise HTTPOk(content_type='application/xml', body=root.write_xmlstring(
        xml_declaration=True, encoding='UTF-8'))
コード例 #9
0
ファイル: test_xmlns.py プロジェクト: lorb888/core
def test_parse_xmlstring3():
    """ XML namespace unit test - parse_xmlstring - parse fragment xml with fragment flag """
    x = xml.Renderer()
    roots = x.parse_xmlstring(xml_fragments_1, fragment=True)
    assert roots[0] == 'leading_text'
    assert roots[1].write_xmlstring() == "<fragment1/>text"
    assert roots[1].tail == "text"
    assert roots[2].write_xmlstring() == "<fragment2/>"
コード例 #10
0
def repeat_test1():
    """ XML namespace unit test - repeat - Repeat with 2 simple text, use childname argument"""
    x = xml.Renderer()
    node = x.parse_xmlstring(xml_test1_in)
    iterator = node.repeat(['test1', 'test2'], childname='child')

    for child, value in iterator:
        child.append_text(value)
    assert [child.text for child in node.getchildren()] == ['test1', 'test2']
コード例 #11
0
def parse_xml_test1():
    """ XML namespace unit test - parse_xmlstring - good encoding """
    try:
        x = xml.Renderer()
        x.parse_xml(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
    except UnicodeDecodeError:
        assert False
    else:
        assert True
コード例 #12
0
ファイル: test_xmlns.py プロジェクト: lorb888/core
def test_repeat2():
    """ XML namespace unit test - repeat - Repeat with 2 simple text, don't use childname argument"""
    x = xml.Renderer()
    node = x.parse_xmlstring(xml_test1_in)
    child = node.findmeld('child')
    iterator = child.repeat(['test1', 'test2'])

    for child, value in iterator:
        child.append_text(value)
    assert [child.text for child in node.getchildren()] == ['test1', 'test2']
コード例 #13
0
ファイル: test_xmlns.py プロジェクト: lorb888/core
def test_parse_xmlstring1():
    """ XML namespace unit test - parse_xmlstring - good encoding """
    try:
        x = xml.Renderer()
        f = open(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
        x.parse_xmlstring(f.read())
        f.close()
    except UnicodeDecodeError:
        assert False
    else:
        assert True
コード例 #14
0
def parse_xmlstring_test2():
    """ XML namespace unit test - parse_xmlstring - bad encoding """
    try:
        x = xml.Renderer()
        f = open(os.path.join(os.path.dirname(__file__), 'iso-8859.xml'))
        x.parse_xml(f, encoding='utf-8')
        f.close()
    except ET.XMLSyntaxError:
        assert True
    else:
        assert False
コード例 #15
0
def add_child_test7():
    """ XML namespace unit test - add_child - add int

    In:
      - <node/>

    Out:
      - <node>42</node>
    """
    x = xml.Renderer()

    node = x.node(42)
    assert node.text == '42'
    assert node.write_xmlstring() == '<node>42</node>'
コード例 #16
0
def add_child_test3():
    """ XML namespace unit test - add_child - add dictionnary

    In:
      - <node/>

    Out:
      - <node test="test"/>
    """
    x = xml.Renderer()

    node = x.node({'test': 'test'})
    assert node.attrib == {'test': 'test'}
    assert node.write_xmlstring() == '<node test="test"/>'
コード例 #17
0
def repeat_test3():
    """ XML namespace unit test - repeat - findmeld in repeat loop """
    h = xml.Renderer()

    xhtml_tree_2 = '<div xmlns:meld="http://www.plope.com/software/meld3"><ul><li meld:id="entry"><span meld:id="count">count</span></li></ul></div>'

    root = h.parse_xmlstring(xhtml_tree_2, fragment=True)[0]

    for (elem, count) in root.repeat(range(2), 'entry'):
        elem.findmeld('count').fill(count)

    h << root

    assert h.root.write_xmlstring() == '<div xmlns:meld="http://www.plope.com/software/meld3"><ul><li meld:id="entry"><span meld:id="count">0</span></li><li meld:id="entry"><span meld:id="count">1</span></li></ul></div>'
コード例 #18
0
def add_child_test4():
    """ XML namespace unit test - add_child - add attribute with keyword

    In:
      - <node/>

    Out:
      - <node test="test"/>
    """
    x = xml.Renderer()

    node = x.node(test='test')
    assert node.attrib == {'test': 'test'}
    assert node.write_xmlstring() == '<node test="test"/>'
コード例 #19
0
def add_child_test8():
    """ XML namespace unit test - add_child - add float

    In:
      - <node/>

    Out:
      - <node>0.1</node>
    """
    x = xml.Renderer()

    node = x.node(0.1)
    assert node.text == '0.1'
    assert node.write_xmlstring() == '<node>0.1</node>'
コード例 #20
0
def add_child_test10():
    """ XML namespace unit test - add_child - add attribute with python keyword

    In:
      - <node/>

    Out:
      - <node class="test"/>
    """
    x = xml.Renderer()

    node = x.node(class_='test')
    assert node.attrib == {'class': 'test'}
    assert node.write_xmlstring() == '<node class="test"/>'
コード例 #21
0
def replace_test6():
    """ XML namespace unit test - replace - replace root node

    In:
      - <node/>

    Out:
      - <node/>
    """
    x = xml.Renderer()

    node = x.node()
    node.replace('test')
    assert node.write_xmlstring() == '<node/>'
コード例 #22
0
def add_child_test1():
    """ XML namespace unit test - add_child - add text

    In:
      - <node/>

    Out:
      - <node>test</node>
    """
    x = xml.Renderer()

    node = x.node('test')
    assert node.text == 'test'
    assert node.write_xmlstring() == '<node>test</node>'
コード例 #23
0
ファイル: test_xmlns.py プロジェクト: lorb888/core
def test_add_child9():
    """ XML namespace unit test - add_child - add dictionnary with python keyword

    In:
      - <node/>

    Out:
      - <node class="test"/>
    """
    x = xml.Renderer()

    node = x.node({'class_': 'test'})
    assert node.attrib == {'class': 'test'}
    assert node.write_xmlstring() == '<node class="test"/>'
コード例 #24
0
def global_test3():
    """ XML namespace unit test - test parse_xmlstring method """
    x = xml.Renderer()

    f = open(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
    root = x.parse_xmlstring(f.read())
    f.close()

    xmlToTest = root.write_xmlstring(xml_declaration=True, pretty_print=True).strip()

    f = open(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
    xmlToCompare = f.read()
    f.close()
    assert xmlToTest == xmlToCompare
コード例 #25
0
def add_child_test2():
    """ XML namespace unit test - add_child - add node

    In:
      - <node/>

    Out:
      - <node><child/></node>
    """
    x = xml.Renderer()

    child = x.child()
    node = x.node(child)
    assert node.getchildren()[0] == child
    assert node.write_xmlstring() == '<node><child/></node>'
コード例 #26
0
def append_text_test3():
    """ XML namespace unit test - append_text - Append text to node with node child

    In:
      - <node><child/></node>

    Out:
      - <node><child/>test</node>
    """
    x = xml.Renderer()

    node = x.node(x.child())
    node.append_text('test')
    assert node.getchildren()[0].tail == 'test'
    assert node.write_xmlstring() == '<node><child/>test</node>'
コード例 #27
0
def append_text_test1():
    """ XML namespace unit test - append_text Append text to an empty node

    In:
      - <node/>

    Out:
      - <node>test</node>
    """
    x = xml.Renderer()

    node = x.node()
    node.append_text('test')
    assert node.text == 'test'
    assert node.write_xmlstring() == '<node>test</node>'
コード例 #28
0
def append_text_test2():
    """ XML namespace unit test - append_text - Append text to node with text child

    In:
      - <node>test1</node>

    Out:
      - <node>test1test2</node>
    """
    x = xml.Renderer()

    node = x.node('test1')
    node.append_text('test2')
    assert node.text == 'test1test2'
    assert node.write_xmlstring() == '<node>test1test2</node>'
コード例 #29
0
def append_text_test4():
    """ XML namespace unit test - append_text - Append text to node with text & node children

    In:
      - <node>test1<child/></node>

    Out:
      - <node>test1<child/>test2</node>
    """
    x = xml.Renderer()

    node = x.node(['test1', x.child()])
    node.append_text('test2')
    assert node.text == 'test1'
    assert node.getchildren()[0].tail == 'test2'
    assert node.write_xmlstring() == '<node>test1<child/>test2</node>'
コード例 #30
0
def global_test2():
    """ XML namespace unit test - create xml by functionnal way """
    x = xml.Renderer()

    filePath = os.path.join(os.path.dirname(__file__), 'helloworld.csv')

    reader = csv.reader(open(filePath, 'r'))

    root = x.helloWorlds([x.helloWorld(row[1].decode('utf-8'),
                            {'language':row[0].decode('utf-8')}) for row in reader])

    xmlToTest = root.write_xmlstring(xml_declaration=True, pretty_print=True).strip()

    f = open(os.path.join(os.path.dirname(__file__), 'test_xmlns_1.xml'))
    xmlToCompare = f.read()
    f.close()
    assert xmlToTest == xmlToCompare