Exemple #1
0
def test(session):

    '''
    test load data precedence is env, file, args;
    '''

    data_file = join(get_input_dir(test_name), 'a.json')
    tmpl_file = join(get_input_dir(test_name), 'a.j2')

    import os
    os.environ['FOOD'] = 'env'

    text_file = join(get_input_dir(test_name), 'env.txt')
    text_data = read_bytes(text_file)
    args = [
        'jinja', '-E', 'FOOD', tmpl_file,
    ]
    cp = run_proc(args)
    assert cp.stdout == text_data

    text_file = join(get_input_dir(test_name), 'file.txt')
    text_data = read_bytes(text_file)
    args = [
        'jinja', '-E', 'FOOD', '-d', data_file, tmpl_file,
    ]
    cp = run_proc(args)
    assert cp.stdout == text_data

    text_file = join(get_input_dir(test_name), 'args.txt')
    text_data = read_bytes(text_file)
    args = [
        'jinja', '-E', 'FOOD', '-d', data_file, '-D', 'FOOD', 'args', tmpl_file,
    ]
    cp = run_proc(args)
    assert cp.stdout == text_data
Exemple #2
0
def test(session):
    '''
    test load data in various formats;
    '''

    tmpl_file = join(get_input_dir(test_name), 'a.j2')
    text_file = join(get_input_dir(test_name), 'a.txt')
    text_data = read_bytes(text_file)

    data_file = join(get_input_dir(test_name), 'a.json')
    args = ['jinja', '-d', data_file, tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data

    data_file = join(get_input_dir(test_name), 'a.json')
    args = ['jinja', '-d', data_file, '-f', 'json', tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data

    data_file = join(get_input_dir(test_name), 'a.ini')
    args = ['jinja', '-d', data_file, '-f', 'ini', tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data

    data_file = join(get_input_dir(test_name), 'a.xml')
    args = ['jinja', '-d', data_file, '-f', 'xml', tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data

    data_file = join(get_input_dir(test_name), 'a.yaml')
    args = ['jinja', '-d', data_file, '-f', 'yaml', tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data
Exemple #3
0
def test(session):
    '''
    test load template from stdin;
    '''

    data_file = join(get_input_dir(test_name), 'a.json')
    text_file = join(get_input_dir(test_name), 'a.txt')
    text_data = read_bytes(text_file)

    tmpl = b'sheep eat {{ sheep.eat }};\n'
    args = ['jinja', '-d', data_file]
    cp = run_proc(args, input=tmpl)
    assert cp.stdout == text_data
Exemple #4
0
def test(session):
    '''
    test load data from stdin;
    '''

    tmpl_file = join(get_input_dir(test_name), 'a.j2')
    text_file = join(get_input_dir(test_name), 'a.txt')
    text_data = read_bytes(text_file)

    data = b'{ "sheep": { "eat": "grass" } }'
    args = ['jinja', '-d', '-', '-f', 'json', tmpl_file]
    cp = run_proc(args, input=data)
    assert cp.stdout == text_data
Exemple #5
0
def test(session):
    '''
    test load data from cmd args;
    '''

    data_file = join(get_input_dir(test_name), 'a.json')
    tmpl_file = join(get_input_dir(test_name), 'a.j2')

    text_file = join(get_input_dir(test_name), 'a.txt')
    text_data = read_bytes(text_file)

    args = ['jinja', '-D', 'FOOD', 'grass', tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data
Exemple #6
0
def test(session):
    '''
    test strict undefined;
    '''

    data_file = join(get_input_dir(test_name), 'a.json')
    tmpl_file = join(get_input_dir(test_name), 'a.j2')

    text_file = join(get_input_dir(test_name), 'a.txt')
    text_data = read_bytes(text_file)

    args = ['jinja', '-d', data_file, tmpl_file]
    cp = run_proc(args)
    assert cp.stdout == text_data

    args = ['jinja', '-d', data_file, '-u', 'strict', tmpl_file]
    with raises(Exception):
        cp = run_proc(args)
Exemple #7
0
def test(session):
    '''
    test load data from env;
    '''

    data_file = join(get_input_dir(test_name), 'a.json')
    tmpl_file = join(get_input_dir(test_name), 'a.j2')

    import os
    os.environ['FOOD'] = 'grass'

    text_file = join(get_input_dir(test_name), 'a.txt')
    text_data = read_bytes(text_file)

    args = ['jinja', '-E', 'FOOD', tmpl_file]
    cp = run_proc(args, env=os.environ)
    assert cp.stdout == text_data

    args = ['jinja', '-X', '.*', tmpl_file]
    cp = run_proc(args, env=os.environ)
    assert cp.stdout == text_data