Пример #1
0
def test_register():
    with pytest.raises(TypeError):
        unmarshal.unmarshal("Foobar", "bar")

    unmarshal.register("Foobar", lambda x: "foo: {}".format(x))
    assert unmarshal.unmarshal("Foobar", "bar") == "foo: bar"

    with pytest.raises(NameError):
        unmarshal.register("Foobar", lambda x: x)
Пример #2
0
def test_unpack():
    class Unpacker(object):
        def __init__(self, x, y):
            self.x = x
            self.y = y

    unmarshal.register("unpack", unmarshal.unpack_into(Unpacker))
    unmarshalled = unmarshal.unmarshal("unpack", dict(x=1, y=True))
    assert isinstance(unmarshalled, Unpacker)
    assert unmarshalled.x == 1
    assert unmarshalled.y is True
Пример #3
0
import datetime
import collections
import itertools
import warnings
import sys
import functools

import six
import numpy as np

from descarteslabs.common.workflows import unmarshal


unmarshal.register("Number", unmarshal.identity)
unmarshal.register("Int", unmarshal.identity)
unmarshal.register("Float", unmarshal.identity)
unmarshal.register("NoneType", unmarshal.identity)
unmarshal.register("Bool", unmarshal.astype(bool))
unmarshal.register("Str", unmarshal.astype(str))
unmarshal.register("List", unmarshal.astype(list))
unmarshal.register("Tuple", unmarshal.astype(tuple))
unmarshal.register("Dict", unmarshal.astype(dict))
unmarshal.register("KnownDict", unmarshal.astype(dict))
unmarshal.register("Slice", unmarshal.astype(slice))
unmarshal.register("AOI", unmarshal.astype(dict))
unmarshal.register("DLTile", unmarshal.astype(dict))
unmarshal.register("XYZTile", unmarshal.astype(dict))
unmarshal.register("GeoContext", unmarshal.astype(dict))
unmarshal.register("Array", unmarshal.identity)
unmarshal.register("MaskedArray", unmarshal.identity)
Пример #4
0
def test_identity():
    unmarshal.register("self", unmarshal.identity)
    x = object()
    assert unmarshal.unmarshal("self", x) is x