source: pyson/test/JsonToolsTest.py@ 158

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

#70 modifications accepting primitives

File size: 992 bytes
RevLine 
[134]1import unittest
[158]2from pyson.JsonTools import getInitArgs, getListClass
[149]3from abc import ABC
[158]4from pyson.JsonSubTypes import JsonSubTypes
[134]5
6class JsonToolsTest(unittest.TestCase):
[158]7
8
[134]9 def testGetInitArgs(self):
10 class ClassWithInitVars:
11 def __init__(self, x:int):
12 y=2
13
14 self.assertEquals({"x":int}, getInitArgs(ClassWithInitVars))
[149]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))
[158]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.