Пример #1
0
def do_test_from_xml_file(version, xml_file, encoding):
    """Tests an xml representation aginst passed encoding.

    Keyword Arguments:
    version -- cim version that representation conforms to.
    xml_file - name of xml file to be opened.
    encoding -- type of representation to decode.

    """
    from pycim.cim_serializer import decode, encode

    # Decode from xml test file.
    xml = get_test_xml_file(version, xml_file)
    obj = decode(xml, version, 'xml')

    # Encode.
    encoded = encode(obj, version, encoding)
    assert encoded is not None

    # Decode.
    decoded = decode(encoded, version, encoding)
    assert decoded is not None

    # Compare decodings.
    assert obj.as_dict() == decoded.as_dict()
    
    
Пример #2
0
def decode_obj_from_xml(version, xml_file, expected_type):
    """Decodes a test xml file & performs basic assertions.

    Keyword Arguments:
    version -- cim version that representation conforms to.
    xml_file - name of xml file to be opened.
    expected_type -- type that the decoded instance should be.

    """
    from pycim.cim_serializer import decode

    # Open cim xml file.
    xml = get_test_xml_file(version, xml_file)

    # Decode.
    obj = decode(xml, version, 'xml')

    # Perform basic assertions.
    assert obj is not None
    assert isinstance(obj, expected_type)

    return obj