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)
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']))
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)
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)
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)
def test_no_config(): with pytest.raises(ValidationError, match=r'^no configuration file found$'): normalize_config('./nowhere.yaml')
def test_valid_config(tmpdir): p = tmpdir.join('tifa.yaml') p.write(mock_valid_config()) normalize_config(p.strpath) assert 1