示例#1
0
文件: test_bfh.py 项目: benauthor/bfh
class TwoToOne(Mapping):
    source_schema = Schema2
    target_schema = Schema1

    my_str = Get('peas')
    my_int = Get('carrots')
    another_str = Str(Get('beans'))
示例#2
0
文件: test_bfh.py 项目: benauthor/bfh
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'))
示例#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)
示例#4
0
 class MyMap(Mapping):
     numbers = ManySubmap(Sub, Get('items'))
示例#5
0
 class Simpler(Mapping):
     numbers = Many(Int, Get('wow'))
示例#6
0
 class Hm(Mapping):
     wow = Int(Get('wow'), required=False)
示例#7
0
 class InnerNoschema(Mapping):
     wow = Get('something')
示例#8
0
        class Inner(Mapping):
            source_schema = SourceSub
            target_schema = TargetSub

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

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

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

            inner = Submapping(Inner, Get("nested"))
示例#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")
示例#21
0
        class Outer(Mapping):
            source_schema = Source
            target_schema = Target

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

        result = Get("path")(MyObj())
        self.assertEqual(result, "goal")
示例#23
0
 class OuterNoschema(Mapping):
     inner = Submapping(InnerNoschema, Get("inner"))
示例#24
0
 def test_default_is_not_required(self):
     my_dict = {"path": "goal"}
     result = Get("else")(my_dict)
     self.assertIsNone(result)
示例#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))
示例#26
0
 def test_mandatory_raises(self):
     my_dict = {"path": "goal"}
     with self.assertRaises(Missing):
         Get("other", required=True)(my_dict)
示例#27
0
 class Sub(Mapping):
     inner = Get('wow')
示例#28
0
 class Inner(Mapping):
     goal = Get("flat")
示例#29
0
 class Deep(Mapping):
     nested = ManySubmap(Sub, Get("one", "two"))
示例#30
0
文件: test_bfh.py 项目: benauthor/bfh
class OneToTwoBase(Mapping):
    peas = Get('my_str')
    carrots = Get('my_int')
    beans = Int(Get('another_str'))