source: pyson/test/JsonToolsTest.py@ 163

Last change on this file since 163 was 158, checked in by wouter, 3 years ago

#70 modifications accepting primitives

File size: 992 bytes
Line 
1import unittest
2from pyson.JsonTools import getInitArgs, getListClass
3from abc import ABC
4from pyson.JsonSubTypes import JsonSubTypes
5
6class 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.