コード例 #1
0
def test_attr_setnode4():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1"/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    doc2 = parse('<a xmlns:ns="urn:bogus:x"/>')
    attr_x = doc.xml_first_child.xml_attributes.getnode(BOGUS_X_NS, u'x')
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #2
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode4():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1"/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    doc2 = parse('<a xmlns:ns="urn:bogus:x"/>')
    attr_x = doc.xml_first_child.xml_attributes.getnode(BOGUS_X_NS, u'x')
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #3
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode3():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = copy.copy(doc.xml_first_child.xml_attributes.getnode(None, u'x'))
    del doc.xml_first_child.xml_attributes[None, u'x']
    doc.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #4
0
def test_attr_setnode2():
    EXPECTED = """<a x="1" y="1" z=""/>"""
    doc = parse('<a x="1"/>')
    attr_y = tree.attribute(None, u'y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(None, u'z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #5
0
def test_attr_setnode5():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1" ns:y="1" ns:z=""/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    attr_y = tree.attribute(BOGUS_X_NS, u'ns:y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(BOGUS_X_NS, u'ns:z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #6
0
def test_attr_setnode3():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = copy.copy(doc.xml_first_child.xml_attributes.getnode(None, u'x'))
    del doc.xml_first_child.xml_attributes[None, u'x']
    doc.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #7
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode2():
    EXPECTED = """<a x="1" y="1" z=""/>"""
    doc = parse('<a x="1"/>')
    attr_y = tree.attribute(None, u'y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(None, u'z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #8
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode5():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="1" ns:y="1" ns:z=""/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    attr_y = tree.attribute(BOGUS_X_NS, u'ns:y', u'1')
    doc.xml_first_child.xml_attributes.setnode(attr_y)
    attr_z = tree.attribute(BOGUS_X_NS, u'ns:z')
    doc.xml_first_child.xml_attributes.setnode(attr_z)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #9
0
def test_attr_setnode1():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    doc2 = parse('<a/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = doc.xml_first_child.xml_attributes.getnode(None, u'x')
    #doc.xml_first_child.xml_attributes[None, u'y'] = attr_x
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #10
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_attr_setnode1():
    EXPECTED = """<a x="1"/>"""
    doc = parse('<a x="1"/>')
    doc2 = parse('<a/>')
    #x = doc.xml_first_child.xml_attributes[None, u'x']
    attr_x = doc.xml_first_child.xml_attributes.getnode(None, u'x')
    #doc.xml_first_child.xml_attributes[None, u'y'] = attr_x
    doc2.xml_first_child.xml_attributes.setnode(attr_x)
    treecompare.check_xml(doc2.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #11
0
def test_coroutine_example2():
    EXPECTED = """<b attr1="val1"><c>1</c><c>2</c><c>3</c></b>"""
    output = structencoder()
    f = output.cofeed(ROOT(E_CURSOR(u'b', {u'attr1': u'val1'})))
    f.send(E(u'c', u'1'))
    f.send(E(u'c', u'2'))
    f.send(E(u'c', u'3'))
    f.close()
    result = output.read()
    treecompare.check_xml(result, XMLDECL + EXPECTED)
    return
コード例 #12
0
def test_simple_elem_and_attr_addition1():
    EXPECTED = """<spam><eggs eggs="1"/><eggs eggs="2"/></spam>"""
    doc = bindery.nodes.entity_base()
    doc.xml_append(doc.xml_element_factory(None, u'spam'))
    doc.spam.xml_append_fragment('<eggs eggs="1"/>')
    doc.spam.xml_append_fragment('<eggs eggs="2"/>')
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    result = [ k for k in doc.spam.eggs if 'eggs' in dir(k) ]
    assert len(result) == 2, result
    #unittest.TestCase.assertEquals([k for k in dir(doc.spam.eggs) if 'eggs' in k], [])
    return
コード例 #13
0
ファイル: test_html.py プロジェクト: abed-hawa/amara
def test_reserved_attributes_page_ns():
    EXPECTED = '<h1 xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml" id="akara:metadata">akara:metadata</h1>'
    f = filesource('tagsoup2.html')
    doc = html.parse(f.source, prefixes=XHTML_NSS, use_xhtml_ns=True)
    #import sys; print >> sys.stderr, doc.xml_select(u'*')[0].xml_name
    #import sys; print >> sys.stderr, doc.xml_select(u'//h:div[@id="content"]')[0].xml_first_child
    #content = doc.xml_select(u'//div[@id="content"]//h1')[0]
    #first_h1 = content.xml_select(u'.//h1')[0]
    first_h1 = doc.xml_select(u'//h:div[@id="content"]//h:h1')[0]
    treecompare.check_xml(first_h1.xml_encode(), EXPECTED)
    assert first_h1.id == u'akara:metadata', (first_h1.id, u'akara:metadata')
    return
コード例 #14
0
ファイル: test_pushtree.py プロジェクト: mredar/amara
def test_predicate2():
    EXPECTED = ['<one>repeat</one>']
    results = []

    def callback(node):
        results.append(node)

    pushtree(XML5, u"doc/one[2]", callback)

    for result, expected in zip(results, EXPECTED):
        treecompare.check_xml(result.xml_encode(), XMLDECL+expected)
    return
コード例 #15
0
ファイル: test_pushtree.py プロジェクト: mredar/amara
def test_1():
    EXPECTED = ['<a>0</a>', '<a>1</a>', '<a>10</a>', '<a>11</a>']
    results = []

    def callback(node):
        results.append(node)

    pushtree(XML1, u"a", callback)

    for result, expected in zip(results, EXPECTED):
        treecompare.check_xml(result.xml_encode(), XMLDECL+expected)
    return
コード例 #16
0
ファイル: test_html.py プロジェクト: mredar/amara
def test_reserved_attributes_page_ns():
    EXPECTED = '<h1 xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml" id="akara:metadata">akara:metadata</h1>'
    f = filesource('tagsoup2.html')
    doc = html.parse(f.source, prefixes=XHTML_NSS, use_xhtml_ns=True)
    #import sys; print >> sys.stderr, doc.xml_select(u'*')[0].xml_name
    #import sys; print >> sys.stderr, doc.xml_select(u'//h:div[@id="content"]')[0].xml_first_child
    #content = doc.xml_select(u'//div[@id="content"]//h1')[0]
    #first_h1 = content.xml_select(u'.//h1')[0]
    first_h1 = doc.xml_select(u'//h:div[@id="content"]//h:h1')[0]
    treecompare.check_xml(first_h1.xml_encode(), EXPECTED)
    assert first_h1.id == u'akara:metadata', (first_h1.id, u'akara:metadata')
    return
コード例 #17
0
def test_coroutine_two_ply1():
    from nose.plugins.skip import SkipTest
    raise SkipTest('Known failure.  Incompletely developed test')
    EXPECTED = """<a><b attr1="val1"><c>1<d><e>2</e><e>3</e></d></c></b></a>"""
    output = structencoder()
    f = output.cofeed(ROOT(E(u'a', E_CURSOR(u'b', {u'attr1': u'val1'}))))
    f.send(E(u'c', u'1', E_CURSOR(u'd')))
    f.send(E(u'e', u'2'))
    f.send(E(u'e', u'3'))
    f.close()
    result = output.read()
    treecompare.check_xml(result, XMLDECL + EXPECTED)
    return
コード例 #18
0
ファイル: test_pushtree.py プロジェクト: mredar/amara
def test_4():
    EXPECTED = ['<x:a xmlns:x="urn:bogus:x">0</x:a>', '<x:a xmlns:x="urn:bogus:x">1</x:a>']
    results = []

    def callback(node):
        results.append(node)

    pushtree(XML4, u"x:a", callback, namespaces = {"x": "urn:bogus:x"})

    for result, expected in zip(results, EXPECTED):
        treecompare.check_xml(result.xml_encode(), XMLDECL+expected)

    return
コード例 #19
0
ファイル: test_pushtree.py プロジェクト: mredar/amara
def test_2():
    EXPECTED = ['<a xmlns="urn:bogus:x">0</a>', '<a xmlns="urn:bogus:x">1</a>', '<a xmlns="urn:bogus:x">10</a>', '<a xmlns="urn:bogus:x">11</a>']
    results = []

    def callback(node):
        results.append(node)

    pushtree(XML2, u"a", callback, namespaces = {None: "urn:bogus:x"})

    for result, expected in zip(results, EXPECTED):
        treecompare.check_xml(result.xml_encode(), XMLDECL+expected)

    return
コード例 #20
0
def test_coroutine_with_nsdecls1():
    EXPECTED = """<a xmlns="urn:bogus:x"><b attr1="val1"><c>1</c><c>2</c><c>3</c></b></a>"""
    XNS = u'urn:bogus:x'
    output = structencoder()
    f = output.cofeed(
        ROOT(E(u'a', NS(None, XNS), E_CURSOR(u'b', {u'attr1': u'val1'}))))
    f.send(E(u'c', u'1'))
    f.send(E(u'c', u'2'))
    f.send(E(u'c', u'3'))
    f.close()
    result = output.read()
    treecompare.check_xml(result, XMLDECL + EXPECTED)
    return
コード例 #21
0
ファイル: test_html.py プロジェクト: abed-hawa/amara
def test_reserved_attributes_page():
    EXPECTED = '<h1 id="akara:metadata">akara:metadata</h1>'
    f = filesource('tagsoup2.html')
    doc = html.parse(f.source)
    #import sys; print >> sys.stderr, [ d.xml_name for d in doc.xml_select(u'//div') ]
    #import sys; print >> sys.stderr, dict(doc.xml_select(u'//div')[1].xml_attributes)
    #import sys; print >> sys.stderr, doc.xml_select(u'*')[0].xml_name
    #content = doc.xml_select(u'//div[@id="content"]//h1')[0]
    #first_h1 = content.xml_select(u'.//h1')[0]
    #import sys; print >> sys.stderr, doc.xml_select(u'//div[@id="content"]')[0].xml_first_child
    first_h1 = doc.xml_select(u'//div[@id="content"]//h1')[0]
    treecompare.check_xml(first_h1.xml_encode(), EXPECTED)
    assert first_h1.id == u'akara:metadata', (first_h1.id, u'akara:metadata')
    return
コード例 #22
0
ファイル: test_html.py プロジェクト: mredar/amara
def test_reserved_attributes_page():
    EXPECTED = '<h1 id="akara:metadata">akara:metadata</h1>'
    f = filesource('tagsoup2.html')
    doc = html.parse(f.source)
    #import sys; print >> sys.stderr, [ d.xml_name for d in doc.xml_select(u'//div') ]
    #import sys; print >> sys.stderr, dict(doc.xml_select(u'//div')[1].xml_attributes)
    #import sys; print >> sys.stderr, doc.xml_select(u'*')[0].xml_name
    #content = doc.xml_select(u'//div[@id="content"]//h1')[0]
    #first_h1 = content.xml_select(u'.//h1')[0]
    #import sys; print >> sys.stderr, doc.xml_select(u'//div[@id="content"]')[0].xml_first_child
    first_h1 = doc.xml_select(u'//div[@id="content"]//h1')[0]
    treecompare.check_xml(first_h1.xml_encode(), EXPECTED)
    assert first_h1.id == u'akara:metadata', (first_h1.id, u'akara:metadata')
    return
コード例 #23
0
def DISABLEDtest_coroutine_with_nsdecls2():
    #FIXME: Puts out redundant nsdecls for now.  Needs to be fixed in code
    #Trick for skipping tests:
    from nose.plugins.skip import SkipTest
    raise SkipTest('reason')
    EXPECTED = """<a><b attr1="val1"><c>1</c><c>2</c><c>3</c></b></a>"""
    XNS = u'urn:bogus:x'
    output = structencoder()
    f = output.cofeed(
        ROOT(E(u'a', NS(None, XNS), E_CURSOR((XNS, u'b'),
                                             {u'attr1': u'val1'}))))
    f.send(E((XNS, u'c'), u'1'))
    f.send(E((XNS, u'c'), u'2'))
    f.send(E((XNS, u'c'), u'3'))
    f.close()
    result = output.read()
    treecompare.check_xml(result, XMLDECL + EXPECTED)
    return
コード例 #24
0
ファイル: test_pushtree.py プロジェクト: mredar/amara
def test_predicate1():
    EXPECTED = ['''<b x='4'>
        <d x='5' />
        <e x='6' />
        <d x='7' />
        <b x='8' />
        <c x='9' />
      </b>''']
    results = []
    raise KnownFailure("No predicates support.  See: http://trac.xml3k.org/ticket/23")


    def callback(node):
        results.append(node)

    pushtree(TREE1, u"b[x='4']", callback)

    for result, expected in zip(results, EXPECTED):
        treecompare.check_xml(result.xml_encode(), XMLDECL+expected)
    return
コード例 #25
0
def test_delns1():
    EXPECTED = """<a/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x"/>')
    del doc.xml_first_child.xml_namespaces[u'ns']
    treecompare.check_xml(doc2.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #26
0
def test_simpe_attr_update3():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="2"/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    attr_x = doc.xml_first_child.xml_attributes[BOGUS_X_NS, u'x'] = u'2'
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #27
0
ファイル: test_html.py プロジェクト: abed-hawa/amara
def test_simple_attr_update3():
    EXPECTED = """<html xmlns="http://www.w3.org/1999/xhtml"><head><title>HELLO</title></head><body><p>WORLD</body></html>"""
    doc = html.parse('<n:a xmlns:n="urn:bogus:x" x="1"/>')
    doc.a.x = unicode(int(doc.a.x)+1)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #28
0
def test_simpe_attr_update2():
    EXPECTED = """<a x="2"/>"""
    doc = parse('<a x="1"/>')
    attr_x = doc.xml_first_child.xml_attributes[None, u'x'] = u'2'
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #29
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_simpe_attr_update2():
    EXPECTED = """<a x="2"/>"""
    doc = parse('<a x="1"/>')
    attr_x = doc.xml_first_child.xml_attributes[None, u'x'] = u'2'
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #30
0
def test_simple_attr_update3():
    EXPECTED = """<n:a xmlns:n="urn:bogus:x" x="2"/>"""
    doc = bindery.parse('<n:a xmlns:n="urn:bogus:x" x="1"/>')
    doc.a.x = unicode(int(doc.a.x)+1)
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #31
0
ファイル: test_html.py プロジェクト: mredar/amara
def test_simple_attr_update3():
    EXPECTED = """<html xmlns="http://www.w3.org/1999/xhtml"><head><title>HELLO</title></head><body><p>WORLD</body></html>"""
    doc = html.parse('<n:a xmlns:n="urn:bogus:x" x="1"/>')
    doc.a.x = unicode(int(doc.a.x) + 1)
    treecompare.check_xml(doc.xml_encode(), XMLDECL + EXPECTED)
    return
コード例 #32
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_delns1():
    EXPECTED = """<a/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x"/>')
    del doc.xml_first_child.xml_namespaces[u'ns']
    treecompare.check_xml(doc2.xml_encode(), XMLDECL+EXPECTED)
    return
コード例 #33
0
ファイル: test_mutation.py プロジェクト: abed-hawa/amara
def test_simpe_attr_update3():
    EXPECTED = """<a xmlns:ns="urn:bogus:x" ns:x="2"/>"""
    doc = parse('<a xmlns:ns="urn:bogus:x" ns:x="1"/>')
    attr_x = doc.xml_first_child.xml_attributes[BOGUS_X_NS, u'x'] = u'2'
    treecompare.check_xml(doc.xml_encode(), XMLDECL+EXPECTED)
    return