Last change
on this file since 425 was 192, checked in by wouter, 3 years ago |
#82 fixed compatibility with python 3.9. pyson now works both with 3.8 and 3.9.
|
File size:
986 bytes
|
Rev | Line | |
---|
[175] | 1 | from abc import ABC
|
---|
| 2 | from pyson.JsonSubTypes import JsonSubTypes
|
---|
[158] | 3 | from pyson.JsonTools import getInitArgs, getListClass
|
---|
[192] | 4 | import unittest
|
---|
[134] | 5 |
|
---|
[175] | 6 |
|
---|
| 7 | @JsonSubTypes(["test.JsonToolsTest.B"])
|
---|
| 8 | class A:
|
---|
| 9 | pass
|
---|
| 10 |
|
---|
| 11 | class B(A):
|
---|
| 12 | pass
|
---|
| 13 |
|
---|
| 14 |
|
---|
[134] | 15 | class JsonToolsTest(unittest.TestCase):
|
---|
[158] | 16 |
|
---|
| 17 |
|
---|
[134] | 18 | def testGetInitArgs(self):
|
---|
| 19 | class ClassWithInitVars:
|
---|
| 20 | def __init__(self, x:int):
|
---|
| 21 | y=2
|
---|
| 22 |
|
---|
[192] | 23 | self.assertEqual({"x":int}, getInitArgs(ClassWithInitVars))
|
---|
[149] | 24 |
|
---|
| 25 | def testGetInitArgsAbc(self):
|
---|
| 26 | class BaseClass(ABC):
|
---|
| 27 | pass
|
---|
| 28 |
|
---|
| 29 | class ClassWithInitVars2(BaseClass):
|
---|
| 30 | def __init__(self, x:int):
|
---|
| 31 | y=2
|
---|
| 32 |
|
---|
[192] | 33 | self.assertEqual({"x":int}, getInitArgs(ClassWithInitVars2))
|
---|
[158] | 34 |
|
---|
| 35 | def testGetListTypePrimitiveMixed(self):
|
---|
| 36 | self.assertEqual(None, getListClass([3, True]))
|
---|
| 37 |
|
---|
| 38 | def testGetListTypePolymorphicNMixed(self):
|
---|
[175] | 39 | self.assertEqual(A, getListClass([B(), A(),B()]))
|
---|
[158] | 40 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.