コード例 #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'))