示例#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.")
示例#2
0
def create_message_string(msg):
    """
    Create an xml string to represent the given message.
    
    Parameters
    ----------
    msg : :class:`quartjes.connector.messages.Message`
        Message object to create XML for.
        
    Returns
    -------
    xml : string
        The XML for the input object.
        
    """
    root = serializer.serialize(msg, parent=None, tag_name="message")
    return et.tostring(root)
示例#3
0
def create_message_string(msg):
    """
    Create an xml string to represent the given message.
    
    Parameters
    ----------
    msg : :class:`quartjes.connector.messages.Message`
        Message object to create XML for.
        
    Returns
    -------
    xml : string
        The XML for the input object.
        
    """
    root = serializer.serialize(msg, parent=None, tag_name="message")
    return et.tostring(root)
示例#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.")