Example #1
0
File: tests.py Project: flintc/lenz
    def testF():
        def add10(x):
            return x + 10

        data = {'a': 1, 'b': [1, 2, 3]}
        optic = ['b', L.elems, L.modify_op(add10)]
        result = L.transform(optic, data)
        assert (result == {'a': 1, 'b': [11, 12, 13]})
        return result
Example #2
0
File: tests.py Project: flintc/lenz
    def testC():
        def add10(x):
            return x + 10

        expected = {'a': 1, 'b': [11, 2, 3]}
        data = {'a': 1, 'b': [1, 2, 3]}
        optic = [L.subseq_u(0, 1, ['b', L.elems]), L.modify_op(add10)]
        result = L.transform(optic, data)
        assert (result == expected)
        return result
Example #3
0
File: tests.py Project: flintc/lenz
    def testL():
        # shouldn't do anything, but should fail silently?
        def add10(x):
            return x + 10

        data = {'a': 1, 'b': [1, 2, 3]}
        expected = {'a': 1, 'b': [1, 2, 3]}
        optic = L.pick({'z': ['b', 1, L.modify_op(add10)], 'q': 'a'})
        result = L.modify(optic, add10, data)
        assert (result == expected)
        return result
Example #4
0
File: tests.py Project: flintc/lenz
    def testJ():
        # should work b/c transform instead of modify
        def add10(x):
            return x + 10

        data = {'a': 1, 'b': [1, 2, 3]}
        expected = {'a': 1, 'b': [1, 12, 3]}
        optic = L.pick({'z': ['b', 1, L.modify_op(add10)], 'q': 'a'})
        result = L.transform(optic, data)
        assert (result == expected)
        return result
Example #5
0
File: tests.py Project: flintc/lenz
    def testD():
        def add10(x):
            return x + 10

        expected = {
            'a': 1,
            'b': {
                'b': {
                    'b': {
                        'b': {
                            'b': {
                                'b': [11, 12, 13]
                            }
                        }
                    }
                }
            }
        }
        data = dict(a=1, b=dict(b=dict(b=dict(b=dict(b=dict(b=[1, 2, 3]))))))
        optic = ['b', 'b', 'b', 'b', 'b', 'b', L.elems, L.modify_op(add10)]
        result = L.transform(optic, data)
        logger.debug(result)
        assert (result == expected)
        return result