Beispiel #1
0
def _generate_roundtrips(roundtrips):
    for is_binary in (True, False):
        for indent in ('not used', ) if is_binary else (None, '', ' ', '   ',
                                                        '\t', '\n\t\n  '):

            def _adjust_sids(annotations=()):
                if is_binary and isinstance(obj, SymbolToken):
                    return SymbolToken(obj.text, 10 + len(annotations))
                return obj

            def _to_obj(to_type=None, annotations=()):
                if to_type is None:
                    to_type = ion_type
                obj_out = _adjust_sids(annotations)
                return _FROM_ION_TYPE[ion_type].from_value(
                    to_type, obj_out,
                    annotations=annotations), is_binary, indent

            for obj in roundtrips:
                obj = _adjust_sids()
                yield obj, is_binary, indent
                if not isinstance(obj, _IonNature):
                    ion_type = _ion_type(obj)
                    yield _to_obj()
                else:
                    ion_type = obj.ion_type
                if isinstance(obj, IonPyNull):
                    obj = None
                yield _to_obj(annotations=(u'annot1', u'annot2'))
                if isinstance(obj, list):
                    yield _to_obj(IonType.SEXP)
                    yield _to_obj(IonType.SEXP,
                                  annotations=(u'annot1', u'annot2'))
Beispiel #2
0
def _generate_roundtrips(roundtrips):
    for is_binary in (True, False):

        def _adjust_sids(annotations=()):
            if is_binary and isinstance(obj, SymbolToken):
                return SymbolToken(obj.text, 10 + len(annotations))
            return obj

        def _to_obj(to_type=None, annotations=()):
            if to_type is None:
                to_type = ion_type
            obj_out = _adjust_sids(annotations)
            return _FROM_ION_TYPE[ion_type].from_value(to_type, obj_out, annotations=annotations), is_binary

        for obj in roundtrips:
            obj = _adjust_sids()
            yield obj, is_binary
            if not isinstance(obj, _IonNature):
                ion_type = _ion_type(obj)
                yield _to_obj()
            else:
                ion_type = obj.ion_type
            if isinstance(obj, IonPyNull):
                obj = None
            yield _to_obj(annotations=(u'annot1', u'annot2'))
            if isinstance(obj, list):
                yield _to_obj(IonType.SEXP)
                yield _to_obj(IonType.SEXP, annotations=(u'annot1', u'annot2'))
Beispiel #3
0
 def _to_ion_nature(obj):
     out = obj
     if not isinstance(out, _IonNature):
         ion_type = _ion_type(out)
         out = _FROM_ION_TYPE[ion_type].from_value(ion_type, out)
     if isinstance(out, dict):
         update = {}
         for field, value in six.iteritems(out):
             update[field] = _to_ion_nature(value)
         update = IonPyDict.from_value(out.ion_type, update, out.ion_annotations)
         out = update
     elif isinstance(out, list):
         update = []
         for value in out:
             update.append(_to_ion_nature(value))
         update = IonPyList.from_value(out.ion_type, update, out.ion_annotations)
         out = update
     return out
Beispiel #4
0
 def _to_ion_nature(obj):
     out = obj
     if not isinstance(out, _IonNature):
         ion_type = _ion_type(out)
         out = _FROM_ION_TYPE[ion_type].from_value(ion_type, out)
     if isinstance(out, dict):
         update = {}
         for field, value in six.iteritems(out):
             update[field] = _to_ion_nature(value)
         update = IonPyDict.from_value(out.ion_type, update,
                                       out.ion_annotations)
         out = update
     elif isinstance(out, list):
         update = []
         for value in out:
             update.append(_to_ion_nature(value))
         update = IonPyList.from_value(out.ion_type, update,
                                       out.ion_annotations)
         out = update
     return out
Beispiel #5
0
def test_subclass_types():
    class Foo(dict):
        pass

    assert _ion_type(Foo(), _FROM_TYPE) is IonType.STRUCT
Beispiel #6
0
def test_subclass_types():
    class Foo(dict):
        pass

    assert _ion_type(Foo()) is IonType.STRUCT