Skip to content

Commit

Permalink
Uprev pydantic to v2.0a4
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed May 12, 2023
1 parent 3d5dbd8 commit 2ec8b42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ classifiers = [
]
requires-python = '>=3.7'
dependencies = [
'pydantic==v2.0a3',
'pydantic==v2.0a4',
'python-dotenv>=0.21.0',
]
dynamic = ['version']
Expand Down
28 changes: 18 additions & 10 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def test_sub_env_override(env):
def test_sub_env_missing():
with pytest.raises(ValidationError) as exc_info:
SimpleSettings()
assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('apple',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('apple',), 'msg': 'Field required', 'input': {}}
]


def test_other_setting():
Expand Down Expand Up @@ -227,7 +229,7 @@ class AnnotatedComplexSettings(BaseSettings):
env.set('apples', '["russet"]')
with pytest.raises(ValidationError) as exc_info:
AnnotatedComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'ctx': {'actual_length': 1, 'field_type': 'List', 'min_length': 2},
'input': ['russet'],
Expand Down Expand Up @@ -292,7 +294,7 @@ class ComplexSettings(BaseSettings):
env.set('field', '{"x": "a"}')
with pytest.raises(ValidationError) as exc_info:
ComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'input': 'a',
'loc': ('field', 'x'),
Expand All @@ -318,7 +320,7 @@ class ComplexSettings(BaseSettings):
env.set('field', '{"x": "a"}')
with pytest.raises(ValidationError) as exc_info:
ComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'input': 'a',
'loc': ('field', 'x'),
Expand All @@ -344,7 +346,7 @@ class ComplexSettings(BaseSettings):
env.set('field', '{"x": "a"}')
with pytest.raises(ValidationError) as exc_info:
ComplexSettings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'input': 'a',
'loc': ('field', 'x'),
Expand Down Expand Up @@ -507,7 +509,9 @@ class Settings(BaseSettings):
env.set('p_foo', 'bar')
with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}
]

env.set('foo', 'bar')
assert Settings().foobar == 'bar'
Expand All @@ -523,7 +527,9 @@ class Settings(BaseSettings):
monkeypatch.setattr(os, 'environ', value={'Foo': 'foo'})
with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}
]


def test_nested_dataclass(env):
Expand Down Expand Up @@ -684,7 +690,7 @@ class Settings(BaseSettings):

with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{
'type': 'missing',
'loc': ('a',),
Expand Down Expand Up @@ -1127,7 +1133,9 @@ class Settings(BaseSettings):
with pytest.raises(ValidationError) as exc_info:
Settings()

assert exc_info.value.errors() == [{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}]
assert exc_info.value.errors(include_url=False) == [
{'type': 'missing', 'loc': ('foo',), 'msg': 'Field required', 'input': {}}
]


def test_secrets_invalid_secrets_dir(tmp_path):
Expand Down Expand Up @@ -1546,7 +1554,7 @@ class Settings(BaseSettings):

with pytest.raises(ValidationError) as exc_info:
Settings()
assert exc_info.value.errors() == [
assert exc_info.value.errors(include_url=False) == [
{'type': 'extra_forbidden', 'loc': ('x',), 'msg': 'Extra inputs are not permitted', 'input': 'y'}
]

Expand Down

0 comments on commit 2ec8b42

Please sign in to comment.