Line | |
---|
1 | import unittest
|
---|
2 | from pyson.JsonTools import getInitArgs, getListClass
|
---|
3 | from abc import ABC
|
---|
4 | from pyson.JsonSubTypes import JsonSubTypes
|
---|
5 |
|
---|
6 | class JsonToolsTest(unittest.TestCase):
|
---|
7 |
|
---|
8 |
|
---|
9 | def testGetInitArgs(self):
|
---|
10 | class ClassWithInitVars:
|
---|
11 | def __init__(self, x:int):
|
---|
12 | y=2
|
---|
13 |
|
---|
14 | self.assertEquals({"x":int}, getInitArgs(ClassWithInitVars))
|
---|
15 |
|
---|
16 | def testGetInitArgsAbc(self):
|
---|
17 | class BaseClass(ABC):
|
---|
18 | pass
|
---|
19 |
|
---|
20 | class ClassWithInitVars2(BaseClass):
|
---|
21 | def __init__(self, x:int):
|
---|
22 | y=2
|
---|
23 |
|
---|
24 | self.assertEquals({"x":int}, getInitArgs(ClassWithInitVars2))
|
---|
25 |
|
---|
26 | def testGetListTypePrimitiveMixed(self):
|
---|
27 | self.assertEqual(None, getListClass([3, True]))
|
---|
28 |
|
---|
29 | def testGetListTypePolymorphicNMixed(self):
|
---|
30 | class A:
|
---|
31 | pass
|
---|
32 | class B(A):
|
---|
33 | pass
|
---|
34 | self.assertRaises(ValueError, lambda:getListClass([A(),B()]))
|
---|
35 |
|
---|
36 | |
---|
Note:
See
TracBrowser
for help on using the repository browser.