-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
from dataclass_settings.base import load_settings | ||
from dataclass_settings.context import Context | ||
from dataclass_settings.loaders import Env, Loader, Secret | ||
from dataclass_settings.loaders import Env, Loader, Secret, Toml | ||
|
||
__all__ = [ | ||
"Env", | ||
"load_settings", | ||
"Loader", | ||
"Secret", | ||
"Context", | ||
"Toml", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
from dataclass_settings import Toml, load_settings | ||
from pydantic import BaseModel, ValidationError | ||
from typing_extensions import Annotated | ||
|
||
from tests.utils import env_setup, skip_under | ||
|
||
|
||
@skip_under(3, 11, reason="Requires tomllib") | ||
def test_missing_required(): | ||
class Config(BaseModel): | ||
foo: Annotated[int, Toml("pyproject.toml", "tool.poetry.asdf")] | ||
|
||
with env_setup({}), pytest.raises(ValidationError): | ||
load_settings(Config) | ||
|
||
|
||
@skip_under(3, 11, reason="Requires tomllib") | ||
def test_has_required_required(): | ||
class Config(BaseModel): | ||
foo: Annotated[str, Toml("pyproject.toml", "tool.poetry.name")] | ||
license: Annotated[str, Toml("pyproject.toml", "tool.poetry.license")] | ||
ignoreme: str = "asdf" | ||
|
||
config = load_settings(Config) | ||
assert config == Config( | ||
foo="dataclass-settings", ignoreme="asdf", license="Apache-2.0" | ||
) | ||
|
||
|
||
@skip_under(3, 11, reason="Requires tomllib") | ||
def test_missing_optional_inferred_name(): | ||
class Config(BaseModel): | ||
tool: Annotated[int, Toml("pyproject.toml")] | ||
ignoreme: str = "asdf" | ||
|
||
with pytest.raises(ValueError) as e: | ||
load_settings(Config) | ||
assert ( | ||
str(e.value) | ||
== "Toml instance for `tool` supplies no `key` and `infer_names` is enabled" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters