def test_nested_2(dictionary=nested_dictionary):
    rule = df.Rule((('m', ), df.Not(('M', )), df.Not(('rr', )), df.All()))
    queries = set(df.expand_rule(rule, dictionary))
    queries0 = set([('m', 'MM', 'iii', 'kkkk'), ('m', 'MM', 'iii', 'uuuu'),
                    ('m', 'RR', 'iii', 'kkkk'), ('m', 'II', 'ooo', 'ssss'),
                    ('m', 'II', 'ooo', 'llll')])
    assert queries == queries0, queries
def test_include(data=data):
    fdata = df.nested_filter([df.Rule((df.All(), ('cumulative', )))], data)
    data0 = {
        '9b55b50c729411ea80ea42a51fad92d3': {
            'cumulative':
            data['9b55b50c729411ea80ea42a51fad92d3']['cumulative']
        }
    }
    assert compare(data0, fdata)
def test_nested_lambda2(dictionary=nested_dictionary):

    pattern = re.compile('^ssss$')
    want = lambda key, pattern=pattern: pattern.match(key) is not None
    rule = df.Rule(
        (df.All(), (lambda key: len(key) == 2, ), df.All(), (want, )))

    queries = set(df.expand_rule(rule, dictionary))
    queries0 = set([('m', 'II', 'ooo', 'ssss')])
    assert queries == queries0, (queries, queries0)
def test_not(data=data):
    rules = [df.Rule((df.All(), ('daily', ), df.All()))]
    fdata = df.nested_filter(rules, data)
    data0 = {
        '9b55b50c729411ea80ea42a51fad92d3': {
            'daily': {
                '2020-04-10':
                data['9b55b50c729411ea80ea42a51fad92d3']['daily']
                ['2020-04-10'],
                '2020-04-11':
                data['9b55b50c729411ea80ea42a51fad92d3']['daily']['2020-04-11']
            }
        }
    }
    assert compare(data0, fdata)
def test_nested_4(dictionary=nested_dictionary):
    rule = df.Rule((('m', ), ('MM', 'II'), df.All()))
    queries = set(df.expand_rule(rule, dictionary))
    queries0 = set([('m', 'MM', 'iii'), ('m', 'MM', 'rrr'), ('m', 'MM', 'ooo'),
                    ('m', 'II', 'rrr'), ('m', 'II', 'ooo')])
    assert queries == queries0, queries
def test_simple_single(dictionary=dictionary):
    rule = df.Rule((('m', ), ))
    queries = set(df.expand_rule(rule, dictionary))
    print(queries)
    queries0 = set([('m', )])
    assert queries == queries0, (queries, queries0)
def test_invalid_key(data=data):
    fdata = df.nested_filter([df.Rule((('1', )))], data)
    assert not len(fdata)
def test_copy(data=data):
    fdata = df.nested_filter([df.Rule((df.All(), ))], data)
    assert compare(data, fdata)
def test_simple_all(dictionary=dictionary):
    rule = df.Rule((df.All(), ))
    queries = set(df.expand_rule(rule, dictionary))
    print(queries)
    queries0 = set([('m', ), ('i', ), ('r', ), ('o', )])
    assert queries == queries0, queries
def test_nested_lambda(dictionary=nested_dictionary):
    rule = df.Rule((df.All(), (lambda key: len(key) == 2, )))

    queries = set(df.expand_rule(rule, dictionary))
    queries0 = set([('m', 'MM'), ('m', 'II'), ('m', 'RR')])
    assert queries == queries0, queries
def test_nested_9(dictionary=nested_dictionary):
    rules = [df.Rule((df.All(), df.All(), df.All(), ('ssss', )))]
    v = df.nested_filter(rules, dictionary)
    assert len(v) == 1
    key, = list(df.nested_keys(v))
    assert key == ('m', 'II', 'ooo', 'ssss')
def test_nested_8(dictionary=nested_dictionary):
    # Empty one
    rule = df.Rule(('aa', ))
    queries = set(df.expand_rule(rule, dictionary))
    assert not queries
def test_nested_7(dictionary=nested_dictionary):
    # Empty one
    rule = df.Rule((df.All(), df.All(), df.All(), df.All(), ('ssss', )))
    queries = set(df.expand_rule(rule, dictionary))
    assert not queries
def test_nested_6(dictionary=nested_dictionary):
    rule = df.Rule((df.All(), ('MM', 'RR'), df.All(), ('kkkk', 'uuuu')))
    queries = set(df.expand_rule(rule, dictionary))
    queries0 = set([('m', 'MM', 'iii', 'kkkk'), ('m', 'MM', 'iii', 'uuuu'),
                    ('m', 'RR', 'iii', 'kkkk')])
    assert queries == queries0, queries
def test_nested_5(dictionary=nested_dictionary):
    # Four level where last is 's'
    rule = df.Rule((df.All(), df.All(), df.All(), ('ssss', )))
    queries = set(df.expand_rule(rule, dictionary))
    queries0 = set([('m', 'II', 'ooo', 'ssss')])
    assert queries == queries0, queries