diff --git a/sentinelhub/config.py b/sentinelhub/config.py index 026af574..8b31f3ea 100644 --- a/sentinelhub/config.py +++ b/sentinelhub/config.py @@ -153,13 +153,13 @@ def load(cls, profile: str | None = None) -> SHConfig: profile = cls._get_profile(profile) filename = cls.get_config_location() if not os.path.exists(filename): - cls(use_defaults=True).save(profile) # store default configuration to standard location + cls(use_defaults=True).save() # store default configuration to standard location with open(filename, "rb") as cfg_file: configurations_dict = tomli.load(cfg_file) if profile not in configurations_dict: - raise KeyError(f"Profile {profile} not found in configuration file.") + raise KeyError(f"Profile `{profile}` not found in configuration file.") return cls(use_defaults=True, **configurations_dict[profile]) diff --git a/tests/test_config.py b/tests/test_config.py index 669f4d37..2318dea9 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -134,6 +134,20 @@ def test_profiles() -> None: assert SHConfig(profile="beep").sh_client_id == "bap" +@pytest.mark.dependency(depends=["test_user_config_is_masked"]) +@pytest.mark.usefixtures("_restore_config_file") +def test_initialize_nondefault_profile() -> None: + """Since there is no config, loading a non-default profile should fail.""" + config = SHConfig() + os.remove(config.get_config_location()) + + SHConfig() # works for default + + os.remove(config.get_config_location()) + with pytest.raises(KeyError): + SHConfig("mr_president") + + @pytest.mark.dependency(depends=["test_user_config_is_masked"]) @pytest.mark.usefixtures("_restore_config_file") def test_profiles_from_env(monkeypatch: pytest.MonkeyPatch) -> None: