Skip to content

Commit

Permalink
add test for Literal
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Mar 2, 2021
1 parent 58d1911 commit f5c24cb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_generics.py
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Callable, ClassVar, Dict, Generic, List, Optional, Sequence, Tuple, Type, TypeVar, Union

import pytest
from typing_extensions import Literal

from pydantic import BaseModel, Field, ValidationError, root_validator, validator
from pydantic.generics import GenericModel, _generic_types_cache, iter_contained_typevars, replace_types
Expand Down Expand Up @@ -1057,3 +1058,16 @@ class MyModel(BaseModel):

m = MyModel.parse_obj({'my_gen': {'some_field': 'A'}})
assert m.my_gen.some_field is SomeStringEnum.A


@skip_36
def test_generic_literal():
FieldType = TypeVar('FieldType')
ValueType = TypeVar('ValueType')

class GModel(GenericModel, Generic[FieldType, ValueType]):
field: Dict[FieldType, ValueType]

Fields = Literal['foo', 'bar']
m = GModel[Fields, str](field={'foo': 'x'})
assert m.dict() == {'field': {'foo': 'x'}}

0 comments on commit f5c24cb

Please sign in to comment.