Last change
on this file since 837 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:
806 bytes
|
Rev | Line | |
---|
[192] | 1 | from pyson.JsonValue import JsonValue, getJsonValue
|
---|
[160] | 2 | import unittest
|
---|
| 3 |
|
---|
[192] | 4 |
|
---|
[160] | 5 | class JsoValueTest(unittest.TestCase):
|
---|
| 6 | def testGetter(self):
|
---|
| 7 |
|
---|
| 8 | class Simple:
|
---|
| 9 | @JsonValue()
|
---|
| 10 | def getBla(self):
|
---|
| 11 | return 1
|
---|
| 12 |
|
---|
| 13 | simple=Simple()
|
---|
| 14 | self.assertTrue(hasattr(simple.getBla, '__jsonvalue__'))
|
---|
| 15 | self.assertTrue(getattr(simple.getBla, '__jsonvalue__'))
|
---|
| 16 |
|
---|
| 17 | f=getJsonValue(Simple)
|
---|
| 18 | self.assertTrue(f)
|
---|
[192] | 19 | self.assertEqual(1, f(simple))
|
---|
[160] | 20 |
|
---|
| 21 |
|
---|
| 22 | def testGetterWrongArity(self):
|
---|
| 23 | self.assertRaises(ValueError, lambda: self.createClassWrongArity())
|
---|
| 24 |
|
---|
| 25 | def createClassWrongArity(self):
|
---|
| 26 | class Simple:
|
---|
| 27 | @JsonValue()
|
---|
| 28 | def getBla(self, x):
|
---|
| 29 | return x
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | |
---|
Note:
See
TracBrowser
for help on using the repository browser.