Exemplo n.º 1
0
    def run_test(self):
        """
        Perform the test.
        
        Serializes the the object, checks whether the expected output matches.
        Then deserializes it again and checks it against the input object.
        """
        node = serialize(self.input, tag_name="test")
        self.assertIsNotNone(node, "Output should contain an object")

        string = serializer.et.tostring(node)
        self.assertRegexpMatches(string, self.output, "Incorrect output\nExpected:\n%s\nGot:\n%s\n" % (self.output, string))

        node = serializer.et.fromstring(string)
        val = deserialize(node)
        self.assertEquals(val, self.input, "Deserialized value should equal original object.")
Exemplo n.º 2
0
def parse_message_string(string):
    """
    Parse a string for an XML message an return an instance of the contained
    message type.
    
    Parameters
    ----------
    string : string
        A string containing an XML message to be parsed.
        
    Returns
    -------
    node
        An XML node containing the XML from the input string.
    """

    node = et.fromstring(string)
    return serializer.deserialize(node)
Exemplo n.º 3
0
def parse_message_string(string):
    """
    Parse a string for an XML message an return an instance of the contained
    message type.
    
    Parameters
    ----------
    string : string
        A string containing an XML message to be parsed.
        
    Returns
    -------
    node
        An XML node containing the XML from the input string.
    """

    node = et.fromstring(string)
    return serializer.deserialize(node)
Exemplo n.º 4
0
    def run_test(self):
        """
        Perform the test.
        
        Serializes the the object, checks whether the expected output matches.
        Then deserializes it again and checks it against the input object.
        """
        node = serialize(self.input, tag_name="test")
        self.assertIsNotNone(node, "Output should contain an object")

        string = serializer.et.tostring(node)
        self.assertRegexpMatches(
            string, self.output,
            "Incorrect output\nExpected:\n%s\nGot:\n%s\n" %
            (self.output, string))

        node = serializer.et.fromstring(string)
        val = deserialize(node)
        self.assertEquals(val, self.input,
                          "Deserialized value should equal original object.")