Exemplo n.º 1
0
 def getter(self, name, getter=None):
     if not getter:
         method = 'field_{0}'.format(name)
         return (getattr(self, method) if hasattr(self, method) else
                 lambda o: recursive_get(o, name))
     return ((lambda o: recursive_get(o, getter)) if isinstance(
         getter, basestring) else getter)
Exemplo n.º 2
0
 def getter(self, name, getter=None):
     if not getter:
         method = 'field_{0}'.format(name)
         return (getattr(self, method)
                 if hasattr(self, method)
                 else lambda o: recursive_get(o, name))
     return ((lambda o: recursive_get(o, getter))
             if isinstance(getter, basestring) else getter)
Exemplo n.º 3
0
    def test_get_nested_attribute(self):
        class Nested(object):
            attr = 'value'

        class Tester(object):
            def __init__(self):
                self.nested = Nested()

        tester = Tester()
        assert recursive_get(tester, 'nested.attr') == 'value'
Exemplo n.º 4
0
    def test_nested_attribute_not_found(self):
        class Nested(object):
            attr = 'value'

        class Tester(object):
            def __init__(self):
                self.nested = Nested()

        tester = Tester()
        assert recursive_get(tester, 'nested.not_found') is None
Exemplo n.º 5
0
    def test_nested_attribute_not_found(self):
        class Nested(object):
            attr = 'value'

        class Tester(object):
            def __init__(self):
                self.nested = Nested()

        tester = Tester()
        assert recursive_get(tester, 'nested.not_found') is None
Exemplo n.º 6
0
    def test_get_nested_attribute(self):
        class Nested(object):
            attr = 'value'

        class Tester(object):
            def __init__(self):
                self.nested = Nested()

        tester = Tester()
        assert recursive_get(tester, 'nested.attr') == 'value'
Exemplo n.º 7
0
 def test_get_root_key(self):
     tester = {'key': 'value'}
     self.assertEqual(recursive_get(tester, 'key'), 'value')
Exemplo n.º 8
0
 def test_get_on_none(self):
     assert recursive_get(None, 'attr') is None
Exemplo n.º 9
0
 def test_nested_key_not_found(self):
     tester = {'nested': {'key': 'value'}}
     self.assertEqual(recursive_get(tester, 'nested.not_found'), None)
Exemplo n.º 10
0
 def test_get_key_none(self):
     tester = {'key': 'value'}
     self.assertEqual(recursive_get(tester, None), None)
     self.assertEqual(recursive_get(tester, ''), None)
Exemplo n.º 11
0
 def test_nested_key_not_found(self):
     tester = {'nested': {'key': 'value'}}
     self.assertEqual(recursive_get(tester, 'nested.not_found'), None)
Exemplo n.º 12
0
    def test_attr_not_found(self):
        class Tester(object):
            pass

        tester = Tester()
        self.assertEqual(recursive_get(tester, 'attr'), None)
Exemplo n.º 13
0
    def test_attr_not_found(self):
        class Tester(object):
            pass

        tester = Tester()
        assert recursive_get(tester, 'attr') is None
Exemplo n.º 14
0
 def test_get_nested_key(self):
     tester = {'nested': {'key': 'value'}}
     assert recursive_get(tester, 'nested.key') == 'value'
Exemplo n.º 15
0
 def test_get_root_key(self):
     tester = {'key': 'value'}
     assert recursive_get(tester, 'key') == 'value'
Exemplo n.º 16
0
    def test_get_root_attribute(self):
        class Tester(object):
            attr = 'value'

        tester = Tester()
        assert recursive_get(tester, 'attr') == 'value'
Exemplo n.º 17
0
 def test_get_key_none(self):
     tester = {'key': 'value'}
     self.assertEqual(recursive_get(tester, None), None)
     self.assertEqual(recursive_get(tester, ''), None)
Exemplo n.º 18
0
 def test_get_on_none(self):
     self.assertEqual(recursive_get(None, 'attr'), None)
Exemplo n.º 19
0
 def test_get_root_key(self):
     tester = {'key': 'value'}
     self.assertEqual(recursive_get(tester, 'key'), 'value')
Exemplo n.º 20
0
 def test_key_not_found(self):
     tester = {'key': 'value'}
     assert recursive_get(tester, 'not-found') is None
Exemplo n.º 21
0
 def test_get_nested_key(self):
     tester = {'nested': {'key': 'value'}}
     self.assertEqual(recursive_get(tester, 'nested.key'), 'value')
Exemplo n.º 22
0
    def test_get_root_attribute(self):
        class Tester(object):
            attr = 'value'

        tester = Tester()
        assert recursive_get(tester, 'attr') == 'value'
Exemplo n.º 23
0
 def test_key_not_found(self):
     tester = {'key': 'value'}
     self.assertEqual(recursive_get(tester, 'not-found'), None)
Exemplo n.º 24
0
    def test_attr_not_found(self):
        class Tester(object):
            pass

        tester = Tester()
        self.assertEqual(recursive_get(tester, 'attr'), None)
Exemplo n.º 25
0
 def test_get_on_none(self):
     self.assertEqual(recursive_get(None, 'attr'), None)
Exemplo n.º 26
0
    def test_attr_not_found(self):
        class Tester(object):
            pass

        tester = Tester()
        assert recursive_get(tester, 'attr') is None
Exemplo n.º 27
0
 def test_get_nested_key(self):
     tester = {'nested': {'key': 'value'}}
     self.assertEqual(recursive_get(tester, 'nested.key'), 'value')
Exemplo n.º 28
0
 def test_key_not_found(self):
     tester = {'key': 'value'}
     self.assertEqual(recursive_get(tester, 'not-found'), None)
Exemplo n.º 29
0
 def test_get_root_key(self):
     tester = {'key': 'value'}
     assert recursive_get(tester, 'key') == 'value'
Exemplo n.º 30
0
 def test_nested_key_not_found(self):
     tester = {'nested': {'key': 'value'}}
     assert recursive_get(tester, 'nested.not_found') is None
Exemplo n.º 31
0
 def test_get_nested_key(self):
     tester = {'nested': {'key': 'value'}}
     assert recursive_get(tester, 'nested.key') == 'value'
Exemplo n.º 32
0
 def test_get_on_none(self):
     assert recursive_get(None, 'attr') is None
Exemplo n.º 33
0
 def test_key_not_found(self):
     tester = {'key': 'value'}
     assert recursive_get(tester, 'not-found') is None
Exemplo n.º 34
0
 def test_get_key_none(self):
     tester = {'key': 'value'}
     assert recursive_get(tester, None) is None
     assert recursive_get(tester, '') is None
Exemplo n.º 35
0
 def test_nested_key_not_found(self):
     tester = {'nested': {'key': 'value'}}
     assert recursive_get(tester, 'nested.not_found') is None
Exemplo n.º 36
0
    def test_get_root_attribute(self):
        class Tester(object):
            attr = 'value'

        tester = Tester()
        self.assertEqual(recursive_get(tester, 'attr'), 'value')
Exemplo n.º 37
0
 def test_get_key_none(self):
     tester = {'key': 'value'}
     assert recursive_get(tester, None) is None
     assert recursive_get(tester, '') is None
Exemplo n.º 38
0
    def test_get_root_attribute(self):
        class Tester(object):
            attr = 'value'

        tester = Tester()
        self.assertEqual(recursive_get(tester, 'attr'), 'value')