Beispiel #1
0
class TwoToOne(Mapping):
    source_schema = Schema2
    target_schema = Schema1

    my_str = Get('peas')
    my_int = Get('carrots')
    another_str = Str(Get('beans'))
Beispiel #2
0
class SquarePegToRoundHole(Mapping):
    source_schema = SquarePeg
    target_schema = RoundHole

    id = Concat('from_square', ':', Str(Get('id')))
    name = Get('name')
    diameter = Do(largest_square, Get('width'))
Beispiel #3
0
    def test_can_mix_transformations(self):
        original = {"foo": 1, "bar": 2}
        concat_getter = Concat(Str(Get("foo")), ":", Str(Get("bar")))
        result = concat_getter(original)
        expected = u"1:2"
        self.assertEqual(expected, result)

        int_concatter = Int(Concat("1", Str(Get("bar")), "3"))
        result = int_concatter(original)
        self.assertEqual(123, result)
Beispiel #4
0
 class MyMap(Mapping):
     numbers = ManySubmap(Sub, Get('items'))
Beispiel #5
0
 class Simpler(Mapping):
     numbers = Many(Int, Get('wow'))
Beispiel #6
0
 class Hm(Mapping):
     wow = Int(Get('wow'), required=False)
Beispiel #7
0
 class InnerNoschema(Mapping):
     wow = Get('something')
Beispiel #8
0
        class Inner(Mapping):
            source_schema = SourceSub
            target_schema = TargetSub

            wow = Get('something')
Beispiel #9
0
        class Inner(Mapping):
            source_schema = InnerSource
            target_schema = InnerTarget

            goal = Get("okay")
Beispiel #10
0
 def test_can_get_from_dict(self):
     my_dict = {"path": "goal"}
     result = Get("path")(my_dict)
     self.assertEqual(result, "goal")
Beispiel #11
0
class ImpliesSchemas(Mapping):
    id = Concat('author', ':', Get('nom_de_plume'))
    name = Get('nom_de_plume')
    book = Get('best_known_for')
Beispiel #12
0
 class MappingB(MappingA):
     target_schema = SchemaB
     root_veg = Get('carrots')
Beispiel #13
0
 class MappingA(Mapping):
     source_schema = SchemaA
     legumes = Get('beans')
Beispiel #14
0
 class Mymap(Mapping):
     target_schema = MySchema
     content = Get('post', 'caption', 'text', default="")
Beispiel #15
0
        class Mymap(Mapping):
            source_schema = FirstSchema
            target_schema = OtherSchema

            cool = Get('wow')
            bad = Get('umm', default=3)
Beispiel #16
0
 class Inner(Mapping):
     goal = Get("okay")
Beispiel #17
0
 class Outer(Mapping):
     inner = Submapping(Inner, Get("nested"))
Beispiel #18
0
 def test_can_nest(self):
     my_dict = {"path": {"subpath": "goal"}}
     result = Get("path", "subpath")(my_dict)
     self.assertEqual(result, "goal")
Beispiel #19
0
        class Outer(Mapping):
            source_schema = OuterSource
            target_schema = OuterTarget

            inner = Submapping(Inner, Get("nested"))
Beispiel #20
0
 def test_can_nest_deeply(self):
     my_dict = {"path": {"deep": {"deeper": {"deepest": "goal"}}}}
     result = Get("path", "deep", "deeper", "deepest")(my_dict)
     self.assertEqual(result, "goal")
Beispiel #21
0
        class Outer(Mapping):
            source_schema = Source
            target_schema = Target

            inner = Submapping(Inner, Get("inner"))
Beispiel #22
0
    def test_can_get_from_obj(self):
        class MyObj(object):
            path = "goal"

        result = Get("path")(MyObj())
        self.assertEqual(result, "goal")
Beispiel #23
0
 class OuterNoschema(Mapping):
     inner = Submapping(InnerNoschema, Get("inner"))
Beispiel #24
0
 def test_default_is_not_required(self):
     my_dict = {"path": "goal"}
     result = Get("else")(my_dict)
     self.assertIsNone(result)
Beispiel #25
0
        class MyMap(Mapping):
            source_schema = Source

            numbers = Many(Int, Get('together'))
            more_numbers = Many(Int, Get('sep_1'), Get('sep_2'), Const(6))
Beispiel #26
0
 def test_mandatory_raises(self):
     my_dict = {"path": "goal"}
     with self.assertRaises(Missing):
         Get("other", required=True)(my_dict)
Beispiel #27
0
 class Sub(Mapping):
     inner = Get('wow')
Beispiel #28
0
 class Inner(Mapping):
     goal = Get("flat")
Beispiel #29
0
 class Deep(Mapping):
     nested = ManySubmap(Sub, Get("one", "two"))
Beispiel #30
0
class OneToTwoBase(Mapping):
    peas = Get('my_str')
    carrots = Get('my_int')
    beans = Int(Get('another_str'))