Example #1
0
    def test__call__complex_fail(self):
        config = {
            'operator': 'and',
            'op1': {
                'op1': '.a',
                'transform1': 'len',
                'operator': 'ge',
                'op2': 4
            },
            'op2': {
                'op1': '.a',
                'transform1': 'len',
                'operator': 'le',
                'op2': {}
            }
        }
        d = {'a': 5}

        f = Filter.fromConfig(config)
        with raises(TypeError) as err:
            f(d)
Example #2
0
    def test__call__complex_ok(self):
        config = {
            'operator': 'and',
            'op1': {
                'op1': '.a',
                'transform1': 'len',
                'operator': 'ge',
                'op2': 4
            },
            'op2': {
                'op1': '.a',
                'transform1': 'len',
                'operator': 'le',
                'op2': 5
            }
        }

        records = [{'a': [1, 2, 3, 4, 5]}, {'a': [1, 2]}]
        expected_results = [True, False]

        f = Filter.fromConfig(config)
        for d, expected in zip(records, expected_results):
            assert f(d) == expected
Example #3
0
 def test_fromConfig(self):
     config = {'op1': '.a', 'transform1': 'len', 'operator': 'ge', 'op2': 4}
     f = Filter.fromConfig(config)
     assert isinstance(f, Filter)
     assert f.op1.transform is not identity
     assert str(f.op1.transform) == 'len'