from abc import ABC from pyson.JsonSubTypes import JsonSubTypes from pyson.JsonTools import getInitArgs, str_to_class, fullclasspath import unittest from pyson.ObjectMapper import ObjectMapper @JsonSubTypes(["test.JsonToolsTest.B"]) class A: pass class B(A): pass class JsonToolsTest(unittest.TestCase): def testGetInitArgs(self): class ClassWithInitVars: def __init__(self, x:int): y=2 self.assertEqual({"x":int}, getInitArgs(ClassWithInitVars)) def testGetInitArgsAbc(self): class BaseClass(ABC): pass class ClassWithInitVars2(BaseClass): def __init__(self, x:int): y=2 self.assertEqual({"x":int}, getInitArgs(ClassWithInitVars2)) # def testGetListTypePrimitiveMixed(self): # self.assertEqual(None, getListClass([3, True])) # def testGetListTypePolymorphicNMixed(self): # self.assertEqual(A, getListClass([B(), A(),B()])) def testStrToClassLocal(self): str_to_class("test.JsonToolsTest.A") def testStrToClassRemoteWrongName(self): # twrong name ValueDeserializer, see next test with correct name self.assertRaises(AttributeError, lambda:str_to_class("test.MyDeserializer.ValueDeserializer")) def testStrToClassRemote(self): str_to_class("test.MyDeserializer.ValueDeserializer2") def testFullClassPath(self): self.assertEquals("str", fullclasspath(str)) self.assertEquals('pyson.ObjectMapper$ObjectMapper', fullclasspath(ObjectMapper))