def test_wrong_api(): ''' Check that we raise the correct errors when a user queries API-specific configuration options ''' _config = Config() _config.load(config_file=TEST_CONFIG) with pytest.raises(ConfigurationError) as err: _ = _config.api_conf("blah") assert "API 'blah' is not in the list" in str(err) with pytest.raises(ConfigurationError) as err: _ = _config.api_conf("dynamo0.1") assert ("Configuration file did not contain a section for the " "'dynamo0.1' API" in str(err)) with pytest.raises(ValueError) as err: _config.api = "invalid" assert "'invalid' is not a valid API" in str(err)
def test_default_access_mapping(tmpdir): '''Test that the default access mapping is correctly converted to AccessTypes.''' config_file = tmpdir.join("config") with config_file.open(mode="w") as new_cfg: new_cfg.write(_CONFIG_CONTENT) new_cfg.close() config = Config() config.load(str(config_file)) api_config = config.api_conf("dynamo0.3") for access_mode in api_config.get_access_mapping().values(): assert isinstance(access_mode, AccessType)
def test_debug_mode(tmpdir): '''Test creation of GOcean debug_mode congifuration. ''' _CONFIG_CONTENT = '''\ [DEFAULT] DEFAULTAPI = dynamo0.3 DEFAULTSTUBAPI = dynamo0.3 DISTRIBUTED_MEMORY = true REPRODUCIBLE_REDUCTIONS = false REPROD_PAD_SIZE = 8 [gocean1.0] ''' # Test with invalid debug mode content = _CONFIG_CONTENT + "DEBUG_MODE = 4" config_file = tmpdir.join("config1") with config_file.open(mode="w") as new_cfg: new_cfg.write(content) new_cfg.close() config = Config() with pytest.raises(ConfigurationError) as err: config.load(str(config_file)) assert ("error while parsing DEBUG_MODE in the [gocean1p0] section " "of the config file: Not a boolean") in str(err.value) # Test with debug mode True content = _CONFIG_CONTENT + "DEBUG_MODE = true" config_file = tmpdir.join("config2") with config_file.open(mode="w") as new_cfg: new_cfg.write(content) new_cfg.close() config = Config() config.load(str(config_file)) api_config = config.api_conf("gocean1.0") assert api_config.debug_mode is True # Test with debug mode False content = _CONFIG_CONTENT + "DEBUG_MODE = false" config_file = tmpdir.join("config3") with config_file.open(mode="w") as new_cfg: new_cfg.write(content) new_cfg.close() config = Config() config.load(str(config_file)) api_config = config.api_conf("gocean1.0") assert api_config.debug_mode is False # Test that if DEBUG_MODE key desn't exist it defaults to False content = _CONFIG_CONTENT config_file = tmpdir.join("config4") with config_file.open(mode="w") as new_cfg: new_cfg.write(content) new_cfg.close() config = Config() config.load(str(config_file)) api_config = config.api_conf("gocean1.0") assert api_config.debug_mode is False