def test_config_set_from_env(tmp_config, config_values): os.environ['BMU_GITHUB_USER'] = '******' with open(tmp_config, 'w') as fh: fh.write(yaml.dump(config_values)) fh.flush() bmu_config.populate() assert bmu_config.github_user == 'x'
def test_config_set_from_yaml(tmp_config, config_values): with open(tmp_config, 'w') as fh: fh.write(yaml.dump(config_values)) fh.flush() bmu_config.populate() for name, expected_value in config_values.items(): assert getattr(bmu_config, name) == expected_value
def test_raises_on_bad_yaml(tmp_config): with open(tmp_config, 'w') as fh: fh.write('bah\n new: \n{:-\n\n$!') fh.flush() with pytest.raises(ConfigError) as excinfo: bmu_config.populate() assert 'parse' in excinfo.value.message
def bmu_conf(github_repo): conf_yaml = tempfile.NamedTemporaryFile(delete=False) user, _, repo = github_repo['full_name'].partition('/') conf_yaml.write('''\ repos: {0}: {1}: - a: - b - c - d: - e: - f - g - h mergers: - {0} developers: - {0} buildbot_auth: - bmu - bmu '''.format(user, repo)) conf_yaml.file.flush() conf_yaml.close() config.populate(conf_yaml.name) yield conf_yaml.name os.remove(conf_yaml.name)
def test_config_env_overrides_yaml(tmp_config, config_values): os.environ['BMU_GITHUB_USER'] = '******' with open(tmp_config, 'w') as fh: fh.write(yaml.dump(config_values)) fh.flush() bmu_config.populate() for name, expected_value in config_values.items(): if name != 'github_user': assert getattr(bmu_config, name) == expected_value assert bmu_config.github_user == 'y'
def test_raises_on_missing_config(): with pytest.raises(ConfigError) as excinfo: bmu_config.populate() assert 'is required' in excinfo.value.message
def test_raises_on_empty_yaml(tmp_config): with pytest.raises(ConfigError) as excinfo: bmu_config.populate() assert 'YAML was empty' in excinfo.value.message