Exemplo n.º 1
0
 def test__get_value__set_in_grand_parent(self):
     prop = Operation(
         Operation(Property('x'), star_func=lambda x: x),
         star_func=lambda x: x,
         get_value=lambda *_: 'foo',
     )
     self.assertEqual('foo', prop.get(dict(x=5)))
Exemplo n.º 2
0
    def __init__(
        self,
        *props,
        skip_none: bool = False,
        props_it: Iterable = None,
        sources_it: Iterable = None,
        **kwargs,
    ):
        if sources_it:
            props = sources_it

        if props_it:
            props = props_it

        from data_mapper.properties import Value

        props = ((prop if isinstance(prop, AbstractProperty) else Property(
            *(sub_prop if isinstance(sub_prop, AbstractProperty
                                     ) else Value(sub_prop)
              for sub_prop in prop))
                  if hasattr(prop, '__iter__') else Value(prop))
                 for prop in props)
        super().__init__(*props, **kwargs)
        self.skip_none = skip_none
        self.values = None
Exemplo n.º 3
0
 def test__get_value__set_in_grand_parent(self):
     prop = Mapper(
         dict(get_value=lambda *_: 'foo'),
         y=Mapper(x=Property(), ),
     )
     self.assertEqual('foo', prop.get(dict(x=5))['y']['x'])
 def test__get_value__set_in_grand_parent(self):
     prop = L(
         L(Property('x')),
         get_value=lambda *_: 'foo',
     )
     self.prop_test(prop, [['foo']], dict(x=5))
Exemplo n.º 5
0
 class PersonMapper(Mapper):
     first_name = Property('first_name', 'name')
     last_name = Property('last_name', 'surname')
 def test__get_value__set_in_parent(self):
     prop = CompoundProperty(
         dict(get_value=lambda *_: 'foo'),
         x=Property(),
     )
     self.assertEqual('foo', prop.get(dict(x=5))['x'])