Ejemplo n.º 1
0
def test_parse_format_output(tmpdir):
    args = [
        '-o',
        str(tmpdir), '--format', 'json', '--inline', '{"A": 1, "B":2, "C": 3}'
    ]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 2
0
def test_parse_inline_yaml(tmpdir):
    args = ['-o', str(tmpdir),
            '--format', 'json',
            '--inline', '{A: 1, B: [2, 4, 6], C: 3}',
            '-i', '5']
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 3
0
def test_parse_template_spec_with_vars(tmpdir):
    args = ['--spec', os.path.join(test_dir, 'templated_spec.json'),
            '--vars', 'pet_count=2',
            '-i', '5',
            '-o', str(tmpdir)]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 4
0
def test_parse_apply_raw(tmpdir):
    args = ['-o', str(tmpdir),
            '--apply-raw',
            '-t', os.path.join(test_dir, 'template.jinja'),
            '--inline', '{"A": 1, "B":2, "C": 3}']
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 5
0
def test_server(tmpdir, mocker):
    mocker.patch('datacraft.server.run', side_effect=ModuleNotFoundError())
    args = [
        '--format', 'json', '--inline', '{A: 1, B: [2, 4, 6], C: 3}', '-i',
        '5', '--server'
    ]
    dgmain.main(args)
Ejemplo n.º 6
0
def test_parse_debug_spec_yaml(tmpdir):
    args = [
        '--debug-spec-yaml', '-o',
        str(tmpdir), '--inline', '{foo: [1,2,3]}'
    ]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 7
0
def test_var_args_not_all_defined_no_assignment(tmpdir):
    args = ['--format', 'json',
            '--inline', '{ {{ first }}: 1, {{ second }}: [2, 4, 6], {{ third }}: 3}',
            '-i', '5',
            '-o', str(tmpdir),
            '--vars', 'first=a', 'second', 'third=c']  # missing second
    with pytest.raises(datacraft.SpecException):
        dgmain.main(args)
Ejemplo n.º 8
0
def test_parse_template_output_inline(tmpdir):
    args = [
        '-o',
        str(tmpdir), '-t', 'A:{{ A }}, B:{{ B }}, C:{{ C }}', '--inline',
        '{"A": 1, "B":2, "C": 3}'
    ]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 9
0
def test_parse_spec_and_inline_invalid():
    args = [
        '--spec',
        os.path.join(test_dir, 'spec.json'), '--inline',
        '{"A": 1, "B":2, "C": 3}'
    ]
    with pytest.raises(datacraft.SpecException):
        dgmain.main(args)
Ejemplo n.º 10
0
def test_var_args(tmpdir):
    args = ['--format', 'json',
            '--inline', '{ {{ first }}: 1, {{ second }}: [2, 4, 6], {{ third }}: 3}',
            '-i', '5',
            '-o', str(tmpdir),
            '--vars', 'first=a', 'second=b', 'third=c']
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 11
0
def test_parse_set_default_invalid_ignored():
    args = [
        '--set-defaults', 'incorrect_format', 'is_valid=should_exist',
        '--inline', '{}'
    ]
    dgmain.main(args)
    with pytest.raises(catalogue.RegistryError):
        datacraft.registries.get_default('incorrect_format')
Ejemplo n.º 12
0
def _test_default_is_changed(key, args, expected):
    orig_value = datacraft.registries.get_default(key)
    dgmain.main(args)
    new_value = datacraft.registries.get_default(key)
    # reset default in registry
    datacraft.registries.set_default(key, orig_value)
    assert orig_value != new_value
    assert new_value == expected, f'{key} changed with args {args}, expected {expected}, but got {new_value}'
Ejemplo n.º 13
0
def test_parse_spec_yaml_format(tmpdir):
    args = [
        '--spec',
        os.path.join(test_dir, 'spec.yaml'), '-o',
        str(tmpdir), '-i', '5'
    ]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 14
0
def test_var_file(tmpdir):
    args = ['--format', 'json',
            '--inline', '{ {{ first }}: 1, {{ second }}: [2, 4, 6], {{ third }}: 3}',
            '-i', '5',
            '-o', str(tmpdir),
            '--var-file', os.path.join(test_dir, 'vars.json')]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'generated-0'))
Ejemplo n.º 15
0
def test_parse_debug_defaults(tmpdir):
    args = ['--debug-defaults', '-o', str(tmpdir)]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'dataspec_defaults.json'))
Ejemplo n.º 16
0
def test_parse_not_json_or_yaml(tmpdir):
    args = ['--spec', os.path.join(test_dir, 'not_json_or_yaml.blah'),
            '-i', '5',
            '-o', str(tmpdir)]
    with pytest.raises(datacraft.SpecException):
        dgmain.main(args)
Ejemplo n.º 17
0
def test_write_info_file_created(info_flag, filename, tmpdir):
    args = [info_flag, '-o', str(tmpdir)]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, filename))
Ejemplo n.º 18
0
def test_parse_inline_yaml_blank_string():
    args = ['--format', 'json', '--inline', ' ']
    with pytest.raises(datacraft.SpecException):
        dgmain.main(args)
Ejemplo n.º 19
0
def test_parse_custom_code():
    dgmain.main(['-c', os.path.join(test_dir, 'custom.py'), '--inline', '{}'])

    # verify string_reverser is now in registry
    handler = datacraft.registries.lookup_type('string_reverser')
    assert handler is not None
Ejemplo n.º 20
0
def test_parse_spec_not_json_or_yaml():
    args = ['--spec', os.path.join(test_dir, 'blank_file')]
    with pytest.raises(datacraft.SpecException):
        dgmain.main(args)
Ejemplo n.º 21
0
def test_parse_spec_invalid_path():
    args = ['--spec', os.path.join(test_dir, 'spec_not_there.json')]
    # just for test coverage
    dgmain.main(args)
Ejemplo n.º 22
0
def test_type_help_with_filter(tmpdir):
    args = ['--type-help', 'calculate', 'sample', '-o', str(tmpdir)]
    dgmain.main(args)
    assert os.path.exists(os.path.join(tmpdir, 'type_help.txt'))
Ejemplo n.º 23
0
def test_parse_empty_args():
    with pytest.raises(datacraft.SpecException):
        dgmain.main([])