Skip to content

Commit 5b33c3b

Browse files
authored
Added test for union with generics (#261)
1 parent c9d407c commit 5b33c3b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/test_union.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import marshmallow
77

8-
from marshmallow_dataclass import dataclass
8+
from marshmallow_dataclass import dataclass, NewType
99

1010

1111
class TestClassSchema(unittest.TestCase):
@@ -196,3 +196,23 @@ class PEP604IntOrStr:
196196

197197
data_in = {"value": 42}
198198
self.assertEqual(schema.dump(schema.load(data_in)), data_in)
199+
200+
@unittest.skipIf(
201+
sys.version_info < (3, 7, 4),
202+
"Requires typeguard >=4.0.0 not available for py<3.7.4",
203+
)
204+
def test_union_with_generics(self):
205+
IntList = NewType("IntList", List[int])
206+
207+
@dataclass
208+
class Dclass:
209+
value: Union[IntList, List[str]]
210+
211+
schema = Dclass.Schema()
212+
213+
self.assertEqual(
214+
schema.load({"value": [1, 2, 3]}), Dclass(value=IntList([1, 2, 3]))
215+
)
216+
self.assertEqual(
217+
schema.dump(Dclass(value=IntList([1, 2, 3]))), {"value": [1, 2, 3]}
218+
)

0 commit comments

Comments
 (0)