Skip to content

Commit

Permalink
Add test for flatten literal
Browse files Browse the repository at this point in the history
  • Loading branch information
DBCerigo committed Apr 4, 2020
1 parent bb425d3 commit 85bf860
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_validators.py
Expand Up @@ -7,6 +7,7 @@
from pydantic import BaseModel, ConfigError, Extra, ValidationError, errors, validator
from pydantic.class_validators import make_generic_validator, root_validator
from pydantic.typing import Literal
from pydantic.validators import flatten_literal


def test_simple():
Expand Down Expand Up @@ -1078,3 +1079,15 @@ class Model(BaseModel):
'ctx': {'given': 'nope', 'permitted': ('foo', 'bar')},
}
]


def test_flatten_nested_literals():
L1 = Literal['1']
assert flatten_literal(L1) == ['1']

L2 = Literal['2']
L12 = Literal[L1, L2]
assert sorted(flatten_literal(L12)) == sorted(['1', '2'])

L312 = Literal['3', Literal[L1, L2]]
assert sorted(flatten_literal(L312)) == sorted(['1', '2', '3'])

0 comments on commit 85bf860

Please sign in to comment.