Last change
on this file since 187 was 175, checked in by wouter, 3 years ago |
Allow polymorphic list - type of list is the (possibly abstract) superclass type
|
File size:
989 bytes
|
Line | |
---|
1 | from abc import ABC
|
---|
2 | import unittest
|
---|
3 |
|
---|
4 | from pyson.JsonSubTypes import JsonSubTypes
|
---|
5 | from pyson.JsonTools import getInitArgs, getListClass
|
---|
6 |
|
---|
7 |
|
---|
8 | @JsonSubTypes(["test.JsonToolsTest.B"])
|
---|
9 | class A:
|
---|
10 | pass
|
---|
11 |
|
---|
12 | class B(A):
|
---|
13 | pass
|
---|
14 |
|
---|
15 |
|
---|
16 | class JsonToolsTest(unittest.TestCase):
|
---|
17 |
|
---|
18 |
|
---|
19 | def testGetInitArgs(self):
|
---|
20 | class ClassWithInitVars:
|
---|
21 | def __init__(self, x:int):
|
---|
22 | y=2
|
---|
23 |
|
---|
24 | self.assertEquals({"x":int}, getInitArgs(ClassWithInitVars))
|
---|
25 |
|
---|
26 | def testGetInitArgsAbc(self):
|
---|
27 | class BaseClass(ABC):
|
---|
28 | pass
|
---|
29 |
|
---|
30 | class ClassWithInitVars2(BaseClass):
|
---|
31 | def __init__(self, x:int):
|
---|
32 | y=2
|
---|
33 |
|
---|
34 | self.assertEquals({"x":int}, getInitArgs(ClassWithInitVars2))
|
---|
35 |
|
---|
36 | def testGetListTypePrimitiveMixed(self):
|
---|
37 | self.assertEqual(None, getListClass([3, True]))
|
---|
38 |
|
---|
39 | def testGetListTypePolymorphicNMixed(self):
|
---|
40 | self.assertEqual(A, getListClass([B(), A(),B()]))
|
---|
41 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.