Ejemplo n.º 1
0
    def to_dict(self, encoding='base64'):
        '''
        Return a dictionary version of the report

        :param encoding: required encoding for the string values (default: 'base64')
        :rtype: dictionary
        :return: dictionary representation of the report
        '''
        res = {}
        for k, v in self._data_fields.items():
            if isinstance(v, (bytes, bytearray, six.string_types)):
                v = StrEncodeEncoder(encoding).encode(v).tobytes().decode()
            res[k] = v
        for k, v in self._sub_reports.items():
            res[k] = v.to_dict(encoding)
        return res
Ejemplo n.º 2
0
class StrEncoderWrapperTest(BitsEncoderTest):
    def setUp(self):
        super(StrEncoderWrapperTest, self).setUp(StrEncoderWrapper)
        self._str_encoder = StrEncodeEncoder('base64')

    def _encode_func(self, bits):
        return self._str_encoder.encode(bits.tobytes())

    def get_default_encoder(self):
        return self.cls(self._str_encoder)

    def testExceptionWhenBitsNotByteAligned(self):
        value = Bits(bin='1111111')
        uut = self.get_default_encoder()
        with self.assertRaises(KittyException):
            uut.encode(value)
class StrEncoderWrapperTest(BitsEncoderTest):

    def setUp(self):
        super(StrEncoderWrapperTest, self).setUp(StrEncoderWrapper)
        self._str_encoder = StrEncodeEncoder('base64')

    def _encode_func(self, bits):
        return self._str_encoder.encode(bits.tobytes())

    def get_default_encoder(self):
        return self.cls(self._str_encoder)

    def testExceptionWhenBitsNotByteAligned(self):
        value = Bits(bin='1111111')
        uut = self.get_default_encoder()
        with self.assertRaises(KittyException):
            uut.encode(value)
Ejemplo n.º 4
0
 def setUp(self):
     super(StrEncoderWrapperTest, self).setUp(StrEncoderWrapper)
     self._str_encoder = StrEncodeEncoder('base64')
 def setUp(self):
     super(StrEncoderWrapperTest, self).setUp(StrEncoderWrapper)
     self._str_encoder = StrEncodeEncoder('base64')