From 9a7f06b18d903607513972d3bb2e7064edc0e0b0 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Tue, 18 Jun 2024 16:34:21 -0500 Subject: [PATCH] refactor: use cfg err --- src/ape/api/config.py | 6 +++++- tests/functional/test_config.py | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ape/api/config.py b/src/ape/api/config.py index 9cfa14aadc..f7e6f34008 100644 --- a/src/ape/api/config.py +++ b/src/ape/api/config.py @@ -74,7 +74,11 @@ def update(root: dict, value_map: dict): return root - return cls(**update(default_values, overrides)) + data = update(default_values, overrides) + try: + return cls.model_validate(data) + except ValidationError as err: + raise ConfigError(str(err)) from err @only_raise_attribute_error def __getattr__(self, attr_name: str) -> Any: diff --git a/tests/functional/test_config.py b/tests/functional/test_config.py index bac4306f90..d5e73cdbbe 100644 --- a/tests/functional/test_config.py +++ b/tests/functional/test_config.py @@ -3,7 +3,6 @@ from typing import Optional, Union import pytest -from pydantic import ValidationError from pydantic_settings import SettingsConfigDict from ape.api.config import ApeConfig, ConfigEnum, PluginConfig @@ -425,14 +424,14 @@ def test_get_config_unknown_plugin(config): def test_get_config_invalid_plugin_config(project): with project.temp_config(node={"ethereum": [1, 2]}): # Show project's ApeConfig model works. - with pytest.raises(ValidationError): + with pytest.raises(ConfigError): project.config.get_config("node") # Show the manager-wrapper also works # (simple wrapper for local project's config, # but at one time pointlessly overrode the `get_config()` # which caused issues). - with pytest.raises(ValidationError): + with pytest.raises(ConfigError): project.config_manager.get_config("node")