def test_user_missing(configure_with, base_config): del base_config['user'] config_file = configure_with(base_config) with pytest.raises(ValueError) as ei: load(config_file) assert str(ei.value) == "No user found in the configuration."
def test_token_wrong_token_type(configure_with, base_config): base_config['token'] = 'xoxo' config_file = configure_with(base_config) with pytest.raises(ValueError) as ei: load(config_file) assert str(ei.value) == "The token does not appear to be a bot token."
def test_token(configure_with, base_config): config_file = configure_with(base_config) config = load(config_file) assert config.token == base_config['token']
def test_token_wrong_data_type(configure_with, base_config): base_config['token'] = 2 config_file = configure_with(base_config) with pytest.raises(ValueError) as ei: load(config_file) assert str(ei.value) == "The token must be a string, found a int."
def test_missing_file(): with pytest.raises(FileNotFoundError): load('foo.bar')
def test_list_configuration(configure_with): config_file = configure_with([]) with pytest.raises(ValueError) as ei: load(config_file) assert str(ei.value) == "Configuration must be a dictionary, found a list."
def test_empty_configuration(configure_with): config_file = configure_with(None) with pytest.raises(ValueError) as ei: load(config_file) assert str( ei.value) == "Configuration must be a dictionary, found a NoneType."
def test_malformed_config(config_file): config_file.write_text(':') with pytest.raises(yaml.YAMLError): load(config_file)
def test_unreadable_config(config_file): config_file.touch(0o0200) with pytest.raises(PermissionError): load(config_file)
def test_user(configure_with, base_config): config_file = configure_with(base_config) config = load(config_file) assert config.user == base_config['user']