当前位置: 首页>>代码示例>>Python>>正文


Python utils.assert_nodes_equal函数代码示例

本文整理汇总了Python中tests.utils.assert_nodes_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_nodes_equal函数的具体用法?Python assert_nodes_equal怎么用?Python assert_nodes_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assert_nodes_equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_any_value_element_tree

def test_any_value_element_tree():
    schema = get_any_schema()

    item = etree.Element('{http://tests.python-zeep.org}lxml')
    etree.SubElement(item, 'node').text = 'foo'

    container_elm = schema.get_element('{http://tests.python-zeep.org/}container')

    # Create via arg
    obj = container_elm(item)
    node = etree.Element('document')
    container_elm.render(node, obj)
    expected = """
        <document>
            <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
                <ns0:lxml xmlns:ns0="http://tests.python-zeep.org">
                    <node>foo</node>
                </ns0:lxml>
            </ns0:container>
        </document>
    """
    assert_nodes_equal(expected, node)
    item = container_elm.parse(list(node)[0], schema)
    assert isinstance(item._value_1, etree._Element)
    assert item._value_1.tag == '{http://tests.python-zeep.org}lxml'
开发者ID:tobirl,项目名称:python-zeep,代码行数:25,代码来源:test_xsd_any.py

示例2: test_element_attribute_name_conflict

def test_element_attribute_name_conflict():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'container'),
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'item'),
                    xsd.String()),
            ]),
            [
                xsd.Attribute('foo', xsd.String()),
                xsd.Attribute('item', xsd.String()),
            ]
        ))

    # sequences
    expected = '{http://tests.python-zeep.org/}container(item: xsd:string, foo: xsd:string, attr__item: xsd:string)'
    assert custom_type.signature() == expected
    obj = custom_type(item='foo', foo='x', attr__item='bar')

    expected = """
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/" foo="x" item="bar">
          <ns0:item>foo</ns0:item>
        </ns0:container>
      </document>
    """
    node = render_node(custom_type, obj)
    assert_nodes_equal(expected, node)

    obj = custom_type.parse(list(node)[0], None)
    assert obj.item == 'foo'
    assert obj.foo == 'x'
    assert obj.attr__item == 'bar'
开发者ID:tobirl,项目名称:python-zeep,代码行数:34,代码来源:test_xsd.py

示例3: test_mime_content_serialize_xml

def test_mime_content_serialize_xml():
    wsdl = stub(schema=stub(_prefix_map={}))
    operation = stub(location='my-action', name='foo')

    element_1 = xsd.Element('arg1', xsd.ComplexType([
        xsd.Element('arg1_1', xsd.String())
    ]))
    element_2 = xsd.Element('arg2', xsd.String())
    abstract_message = definitions.AbstractMessage(
        etree.QName('{http://test.python-zeep.org/tests/msg}Method'))
    abstract_message.parts = OrderedDict([
        ('xarg1', definitions.MessagePart(element=element_1, type=None)),
        ('xarg2', definitions.MessagePart(element=element_2, type=None)),
    ])

    msg = messages.MimeContent(
        wsdl=wsdl, name=None, operation=operation, content_type='text/xml',
        part_name=None)

    msg._info = {
        'body': {'namespace': 'http://test.python-zeep.org/tests/rpc'},
        'header': None,
        'headerfault': None
    }
    msg.resolve(wsdl, abstract_message)

    serialized = msg.serialize(xarg1={'arg1_1': 'uh'}, xarg2='bla')
    assert serialized.headers == {
        'Content-Type': 'text/xml'
    }
    assert serialized.path == 'my-action'
    assert_nodes_equal(
        load_xml(serialized.content),
        load_xml(
            "<foo><xarg1><arg1_1>uh</arg1_1></xarg1><xarg2>bla</xarg2></foo>"))
开发者ID:elfixit,项目名称:python-zeep,代码行数:35,代码来源:test_wsdl_messages.py

示例4: test_any_in_nested_sequence

def test_any_in_nested_sequence():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
            xmlns:tns="http://tests.python-zeep.org/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            targetNamespace="http://tests.python-zeep.org/"
        >
          <xsd:element name="something" type="xsd:date"/>
          <xsd:element name="foobar" type="xsd:boolean"/>
          <xsd:element name="container">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="items" minOccurs="0">
                  <xsd:complexType>
                    <xsd:sequence>
                      <xsd:any namespace="##any" processContents="lax"/>
                    </xsd:sequence>
                  </xsd:complexType>
                </xsd:element>
                <xsd:element name="version" type="xsd:string"/>
                <xsd:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
    """))   # noqa

    container_elm = schema.get_element('{http://tests.python-zeep.org/}container')
    assert container_elm.signature() == (
        'items: {_value_1: ANY}, version: xsd:string, _value_1: ANY[]')

    something = schema.get_element('{http://tests.python-zeep.org/}something')
    foobar = schema.get_element('{http://tests.python-zeep.org/}foobar')

    any_1 = xsd.AnyObject(something, datetime.date(2016, 7, 4))
    any_2 = xsd.AnyObject(foobar, True)
    obj = container_elm(
        items={'_value_1': any_1}, version='str1234', _value_1=[any_1, any_2])

    node = etree.Element('document')
    container_elm.render(node, obj)
    expected = """
        <document>
          <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
            <ns0:items>
              <ns0:something>2016-07-04</ns0:something>
            </ns0:items>
            <ns0:version>str1234</ns0:version>
            <ns0:something>2016-07-04</ns0:something>
            <ns0:foobar>true</ns0:foobar>
          </ns0:container>
        </document>
    """
    assert_nodes_equal(expected, node)
    item = container_elm.parse(node.getchildren()[0], schema)
    assert item.items._value_1 == datetime.date(2016, 7, 4)
    assert item.version == 'str1234'
    assert item._value_1 == [datetime.date(2016, 7, 4), True]
开发者ID:mattpepin,项目名称:python-zeep,代码行数:60,代码来源:test_xsd_integration.py

示例5: test_create_node

def test_create_node():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'username'),
                    xsd.String()),
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'password'),
                    xsd.String()),
            ]),
            [
                xsd.Attribute('attr', xsd.String()),
            ]
        ))

    # sequences
    obj = custom_type(username='foo', password='bar', attr='x')

    expected = """
      <document>
        <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/" attr="x">
          <ns0:username>foo</ns0:username>
          <ns0:password>bar</ns0:password>
        </ns0:authentication>
      </document>
    """
    node = etree.Element('document')
    custom_type.render(node, obj)
    assert_nodes_equal(expected, node)
开发者ID:tobirl,项目名称:python-zeep,代码行数:31,代码来源:test_xsd.py

示例6: test_complex_type_with_attributes

def test_complex_type_with_attributes():
    node = etree.fromstring("""
        <?xml version="1.0"?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:complexType name="Address">
            <xs:sequence>
              <xs:element minOccurs="0" maxOccurs="1" name="NameFirst" type="xs:string"/>
              <xs:element minOccurs="0" maxOccurs="1" name="NameLast" type="xs:string"/>
              <xs:element minOccurs="0" maxOccurs="1" name="Email" type="xs:string"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required"/>
          </xs:complexType>
          <xs:element name="Address" type="Address"/>
        </xs:schema>
    """.strip())

    schema = xsd.Schema(node)

    address_type = schema.get_element('Address')
    obj = address_type(
        NameFirst='John', NameLast='Doe', Email='[email protected]', id='123')

    node = etree.Element('document')
    address_type.render(node, obj)

    expected = """
        <document>
            <Address id="123">
                <NameFirst>John</NameFirst>
                <NameLast>Doe</NameLast>
                <Email>[email protected]</Email>
            </Address>
        </document>
    """
    assert_nodes_equal(expected, node)
开发者ID:mattpepin,项目名称:python-zeep,代码行数:35,代码来源:test_xsd_integration.py

示例7: test_custom_simple_type

def test_custom_simple_type():
    node = etree.fromstring("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                elementFormDefault="qualified">
          <element name="something">
            <simpleType>
              <restriction base="integer">
                <minInclusive value="0"/>
                <maxInclusive value="100"/>
              </restriction>
            </simpleType>
          </element>
        </schema>
    """.strip())

    schema = xsd.Schema(node)

    custom_type = schema.get_element('{http://tests.python-zeep.org/}something')
    obj = custom_type(75)

    node = etree.Element('document')
    custom_type.render(node, obj)
    expected = """
        <document>
            <ns0:something xmlns:ns0="http://tests.python-zeep.org/">75</ns0:something>
        </document>
    """
    assert_nodes_equal(expected, node)
开发者ID:mattpepin,项目名称:python-zeep,代码行数:31,代码来源:test_xsd_integration.py

示例8: test_attribute_required

def test_attribute_required():
    node = load_xml("""
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                targetNamespace="http://tests.python-zeep.org/">
          <element name="foo">
            <complexType>
              <xsd:attribute name="base" use="required" type="xsd:string" />
            </complexType>
          </element>
        </schema>
    """)
    schema = parse_schema_node(node)
    xsd_element = schema.get_element('{http://tests.python-zeep.org/}foo')
    value = xsd_element()

    with pytest.raises(exceptions.ValidationError):
        node = render_node(xsd_element, value)

    value.base = 'foo'
    node = render_node(xsd_element, value)

    expected = """
      <document>
        <ns0:foo xmlns:ns0="http://tests.python-zeep.org/" base="foo"/>
      </document>
    """
    assert_nodes_equal(expected, node)
开发者ID:tobirl,项目名称:python-zeep,代码行数:28,代码来源:test_xsd_visitor.py

示例9: test_nill

def test_nill():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                elementFormDefault="qualified">
          <element name="container">
            <complexType>
              <sequence>
                <element name="foo" type="string" nillable="true"/>
              </sequence>
            </complexType>
          </element>
        </schema>
    """))

    address_type = schema.get_element('ns0:container')
    obj = address_type()
    expected = """
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        </ns0:container>
      </document>
    """
    node = etree.Element('document')
    address_type.render(node, obj)
    etree.cleanup_namespaces(node)

    assert_nodes_equal(expected, node)
开发者ID:pavelbrych,项目名称:python-zeep,代码行数:32,代码来源:test_xsd_integration.py

示例10: test_xml_complex_type_empty

def test_xml_complex_type_empty():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                elementFormDefault="qualified">
          <complexType name="empty"/>
          <element name="container">
            <complexType>
              <sequence>
                <element name="something" type="tns:empty"/>
              </sequence>
            </complexType>
          </element>
        </schema>
    """))

    container_elm = schema.get_element('{http://tests.python-zeep.org/}container')
    obj = container_elm(something={})

    node = etree.Element('document')
    container_elm.render(node, obj)
    expected = """
        <document>
            <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
                <ns0:something/>
            </ns0:container>
        </document>
    """
    assert_nodes_equal(expected, node)
    item = container_elm.parse(list(node)[0], schema)
    assert item.something is None
开发者ID:tobirl,项目名称:python-zeep,代码行数:33,代码来源:test_xsd_integration.py

示例11: test_union_same_types

def test_union_same_types():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/"
            targetNamespace="http://tests.python-zeep.org/"
            elementFormDefault="qualified">


          <xsd:simpleType name="MMYY">
            <xsd:restriction base="xsd:int"/>
          </xsd:simpleType>

          <xsd:simpleType name="MMYYYY">
            <xsd:restriction base="xsd:int"/>
          </xsd:simpleType>

          <xsd:simpleType name="Date">
            <xsd:union memberTypes="MMYY MMYYYY"/>
          </xsd:simpleType>
          <xsd:element name="item" type="tns:Date"/>
        </xsd:schema>
    """))

    elm = schema.get_element('ns0:item')
    node = render_node(elm, '102018')
    expected = """
        <document>
          <ns0:item xmlns:ns0="http://tests.python-zeep.org/">102018</ns0:item>
        </document>
    """
    assert_nodes_equal(expected, node)
    value = elm.parse(node.getchildren()[0], schema)
    assert value == 102018
开发者ID:mvantellingen,项目名称:python-zeep,代码行数:35,代码来源:test_xsd_union.py

示例12: test_xml_defaults_parse_boolean

def test_xml_defaults_parse_boolean():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                elementFormDefault="qualified"
                targetNamespace="http://tests.python-zeep.org/">
          <xsd:element name="container">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="foo" type="xsd:boolean" default="false"/>
              </xsd:sequence>
              <xsd:attribute name="bar" type="xsd:boolean" default="0"/>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
    """))

    container_type = schema.get_element(
        '{http://tests.python-zeep.org/}container')
    obj = container_type()
    assert obj.foo == "false"
    assert obj.bar == "0"

    expected = """
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/" bar="false">
          <ns0:foo>false</ns0:foo>
        </ns0:container>
      </document>
    """
    node = etree.Element('document')
    container_type.render(node, obj)
    assert_nodes_equal(expected, node)
开发者ID:tobirl,项目名称:python-zeep,代码行数:35,代码来源:test_xsd_integration.py

示例13: test_xml_element_ref

def test_xml_element_ref():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                   elementFormDefault="qualified">
          <element name="foo" type="string"/>
          <element name="bar">
            <complexType>
              <sequence>
                <element ref="tns:foo"/>
              </sequence>
            </complexType>
          </element>
        </schema>
    """))

    foo_type = schema.get_element('{http://tests.python-zeep.org/}foo')
    assert isinstance(foo_type.type, xsd.String)

    custom_type = schema.get_element('{http://tests.python-zeep.org/}bar')
    custom_type.signature()
    obj = custom_type(foo='bar')

    node = etree.Element('document')
    custom_type.render(node, obj)
    expected = """
        <document>
            <ns0:bar xmlns:ns0="http://tests.python-zeep.org/">
                <ns0:foo>bar</ns0:foo>
            </ns0:bar>
        </document>
    """
    assert_nodes_equal(expected, node)
开发者ID:tobirl,项目名称:python-zeep,代码行数:35,代码来源:test_xsd_integration.py

示例14: test_xml_complex_type_unbounded_one

def test_xml_complex_type_unbounded_one():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                elementFormDefault="qualified">
          <element name="Address">
            <complexType>
              <sequence>
                <element minOccurs="0" maxOccurs="unbounded" name="foo" type="string" />
              </sequence>
            </complexType>
          </element>
        </schema>
    """))
    address_type = schema.get_element('{http://tests.python-zeep.org/}Address')
    obj = address_type(foo=['foo'])

    expected = """
        <document>
          <ns0:Address xmlns:ns0="http://tests.python-zeep.org/">
            <ns0:foo>foo</ns0:foo>
          </ns0:Address>
        </document>
    """

    node = etree.Element('document')
    address_type.render(node, obj)
    assert_nodes_equal(expected, node)
开发者ID:tobirl,项目名称:python-zeep,代码行数:30,代码来源:test_xsd_integration.py

示例15: test_ref_attribute_qualified

def test_ref_attribute_qualified():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                attributeFormDefault="qualified"
                targetNamespace="http://tests.python-zeep.org/">
          <xsd:element name="container">
            <xsd:complexType>
              <xsd:attribute ref="tns:attr" use="required" />
            </xsd:complexType>
          </xsd:element>
          <xsd:attribute name="attr" type="xsd:string" />
        </xsd:schema>
    """))

    elm_cls = schema.get_element('{http://tests.python-zeep.org/}container')
    instance = elm_cls(attr="hoi")

    expected = """
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/" ns0:attr="hoi"/>
      </document>
    """

    node = etree.Element('document')
    elm_cls.render(node, instance)
    assert_nodes_equal(expected, node)
开发者ID:nicoe,项目名称:python-zeep,代码行数:29,代码来源:test_xsd_attributes.py


注:本文中的tests.utils.assert_nodes_equal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。