示例#1
0
def test_element_to_lxml_element_with_children_must_use_original_order_to_add_it(
        string_type, lxml_root):
    children = [
        Element('Name', element_type=string_type),
        Element('Surname', element_type=string_type),
        Element('Owner', element_type=string_type),
        Element('Country', element_type=string_type),
    ]

    el_type = ElementType('EmployeeType', children=children)

    el = Element('Employee', element_type=el_type)

    el.to_lxml_element(lxml_root)

    result = et.tostring(lxml_root).decode()

    # Same order that was added to element type
    expected = (
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
        '<xsl:element name="Employee">'
        '<xsl:element name="Name">autogenerated</xsl:element>'
        '<xsl:element name="Surname">autogenerated</xsl:element>'
        '<xsl:element name="Owner">autogenerated</xsl:element>'
        '<xsl:element name="Country">autogenerated</xsl:element>'
        '</xsl:element>'
        '</xsl:stylesheet>')

    assert result == expected
示例#2
0
def test_element_to_lxml_element_must_return_expected_tag(
        string_type, lxml_root):
    el = Element('Surname', element_type=string_type)

    el.to_lxml_element(lxml_root)

    result = et.tostring(lxml_root).decode()

    expected = (
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
        '<xsl:element name="Surname">autogenerated</xsl:element>'
        '</xsl:stylesheet>')

    assert result == expected
示例#3
0
def test_element_to_lxml_element_with_restriction_enum_filled_in_type_must_return_expected_tag_with_value(
        string_type, lxml_root):
    string_type.restriction_enum = ('Perez', 'Silva')
    el = Element('Surname', element_type=string_type)
    el.to_lxml_element(lxml_root)

    result = et.tostring(lxml_root).decode()

    expected = (
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
        '<!--CHECK! Created with first element of restriction from type spec-->'
        '<xsl:element name="Surname">Perez</xsl:element>'
        '</xsl:stylesheet>')

    assert result == expected
示例#4
0
def test_element_to_lxml_element_with_default_attr_must_return_expected_tag_with_value(
        string_type, lxml_root):
    el = Element('Surname',
                 element_type=string_type,
                 attrs={'default': 'Silva'})
    el.to_lxml_element(lxml_root)

    result = et.tostring(lxml_root).decode()

    expected = (
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
        '<!--Created with default value--><xsl:element name="Surname">Silva</xsl:element>'
        '</xsl:stylesheet>')

    assert result == expected
示例#5
0
def test_element_to_lxml_element_with_children_must_return_expected_tags(
        complex_type, string_type, lxml_root):
    complex_type.add_child(Element('Surname', element_type=string_type))
    f = Element('Employee', element_type=complex_type)

    f.to_lxml_element(lxml_root)

    result = et.tostring(lxml_root).decode()

    expected = (
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
        '<xsl:element name="Employee">'
        '<xsl:element name="Name">autogenerated</xsl:element>'
        '<xsl:element name="Surname">autogenerated</xsl:element>'
        '</xsl:element>'
        '</xsl:stylesheet>')

    assert result == expected
示例#6
0
def test_element_to_lxml_element_with_copy_of_must_return_expected_tags(
        string_type, lxml_root):
    el = Element('Surname', element_type=string_type)
    el.copy_of = '/Foo/Surname'

    el.to_lxml_element(lxml_root)

    result = et.tostring(lxml_root).decode()

    expected = (
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'
        '<xsl:if test="/Foo/Surname">'
        '<xsl:copy-of select="/Foo/Surname"/>'
        '</xsl:if>'
        '<xsl:if test="not(/Foo/Surname)">'
        '<xsl:element name="Surname">autogenerated</xsl:element>'
        '</xsl:if>'
        '</xsl:stylesheet>')

    assert result == expected