Exemplo n.º 1
0
 def test_loads(self):
     for expected, value in self.get_loads_test_values():
         result = hipack.loads(six.b(dedent(value)))
         self.assertTrue(isinstance(result, dict))
         self.assertDictEqual(expected, result)
         # Passing Unicode text should work as well.
         result = hipack.loads(dedent(value))
         self.assertTrue(isinstance(result, dict))
         self.assertDictEqual(expected, result)
Exemplo n.º 2
0
    def from_hipack(cls, data, encoding=None):
        """
        Deserializes an object from HiPack and validates it.

        Loads data from a HiPack string, decoding it with `hipack.loads()`,
        and the resulting value is passed to a `.validate()` class method.
        That method is responsible of validating the input date, and
        optionally returning an object which represents the deserialized
        data.
        """
        from hipack import loads
        return cls.validate(loads(data))
Exemplo n.º 3
0
 def test_parse_valid_message_with_annots(self, text):
     def check_annot(annotations, text, value):
         self.assertIn(u"annot", annotations)
         return value
     value = hipack.loads(six.b(text), check_annot)
     self.assertIsInstance(value, dict)