def build_codec(self):
        (enc, dec) = build_codec('RemoteExec', *tuple(self.codec_handlers))

        def encoder(obj):
            return json.dumps(obj, cls=enc)

        self._encoder = encoder

        def decoder(obj):
            return json.loads(obj, cls=dec, key_typecasts=self.key_typecasts)

        self._decoder = decoder
Пример #2
0
        return True
    return obj == _obj

for handlers in combinations(HANDLERS):
    if len(failures) > 5:
        break
    _d = copy(d)
    unused_handlers = list()

    for key in list(d['handler_tests'].keys()):
        if key not in handlers:
            unused_handlers.append((key, _d['handler_tests'].pop(key)))

    typecast2key = dict((val, key) for key, val in _d['typecast_tests'].items())
    for typecasts in combinations(KEYTYPECASTS):
        en, de = build_codec('Test', *handlers)
        _dump = None
        loaded = None
        try:
            _dump = json.dumps(_d, cls=en)
            loaded = json.loads(_dump, cls=de, key_typecasts=typecasts)
            dump = json.loads(_dump)
        except Exception as e:
            failures.append(failures.append({'Exception': {' typecasts': typecasts,
                                                                    ' handlers': handlers,
                                                                    'orig': _d, 'dump': trunc(_dump), 'load': trunc(loaded),
                                                                    '  error': trunc(str(e))}}))
            continue
        #print("Handlers: {0}\nKey typecasts: {2}\n\torig dict: {4}\n\tjson dump: {1}\n\tload dict: {3}\n------".format(handlers,
        #                                                                                     dump,
        #                                                                                     typecasts, loaded, _d))