Ejemplo n.º 1
0
def test_file_render(tmpdir):
    p = tmpdir.join('tifa.yaml')
    file = File(name='tifa.yaml',
                origin='tifa.example.yaml',
                params=dict(name='tifa'))
    file.render(tmpdir.strpath)
    normalize_config(p.strpath)
Ejemplo n.º 2
0
def gen(config):
    config_path = config or './tifa.yaml'
    try:
        config = normalize_config(config_path)
    except ValidationError as e:
        Prompt.warn(str(e))
        return

    if os.path.isdir(config['name']):
        Prompt.warn('ops, folder {} has been used'.format(config['name']))
        return

    template = Template(config)
    template.render('./')

    os.remove(config_path)

    Prompt.success('🎉 {} created, enjoy coding!'.format(config['name']))
Ejemplo n.º 3
0
def test_bad_model_in_config(tmpdir):
    p = tmpdir.join('tifa.yaml')
    p.write(mock_bad_models_config())
    with pytest.raises(ValidationError, match=r'^invalid model: .*'):
        normalize_config(p.strpath)
Ejemplo n.º 4
0
def test_bad_name_in_config(tmpdir):
    p = tmpdir.join('tifa.yaml')
    p.write(mock_bad_name_config())
    with pytest.raises(ValidationError,
                       match=r'^space in project name is invalid$'):
        normalize_config(p.strpath)
Ejemplo n.º 5
0
def test_bad_yaml(tmpdir):
    # http://pyyaml.org/wiki/PyYAMLDocumentation#YAMLError
    p = tmpdir.join('tifa.yaml')
    p.write('unbalanced blackets: ][')
    with pytest.raises(ValidationError, match=r'^invalid yaml file$'):
        normalize_config(p.strpath)
Ejemplo n.º 6
0
def test_no_config():
    with pytest.raises(ValidationError,
                       match=r'^no configuration file found$'):
        normalize_config('./nowhere.yaml')
Ejemplo n.º 7
0
def test_valid_config(tmpdir):
    p = tmpdir.join('tifa.yaml')
    p.write(mock_valid_config())
    normalize_config(p.strpath)
    assert 1