Rev | Line | |
---|
[150] | 1 | from pyson.JsonGetter import JsonGetter, getGetter
|
---|
| 2 | import unittest
|
---|
| 3 |
|
---|
[160] | 4 | class JsonGetterTest(unittest.TestCase):
|
---|
[150] | 5 | def testGetter(self):
|
---|
| 6 |
|
---|
| 7 | class Simple:
|
---|
| 8 | @JsonGetter("One")
|
---|
| 9 | def getBla(self):
|
---|
| 10 | return 1
|
---|
| 11 |
|
---|
| 12 | simple=Simple()
|
---|
| 13 | self.assertTrue(hasattr(simple.getBla, '__jsongetter__'))
|
---|
| 14 | self.assertEquals('One', getattr(simple.getBla,'__jsongetter__'))
|
---|
| 15 |
|
---|
| 16 | def testGetGetterBasic(self):
|
---|
| 17 | class Simple:
|
---|
| 18 | def getBla(self):
|
---|
| 19 | return 1
|
---|
| 20 |
|
---|
| 21 | simple=Simple()
|
---|
| 22 | self.assertEquals(simple.getBla, getGetter(simple, 'Bla'))
|
---|
| 23 | self.assertRaises(ValueError, lambda:getGetter(simple, 'UnknownGetter'))
|
---|
| 24 |
|
---|
| 25 | def testGetGetterAnnotated(self):
|
---|
| 26 | class AnnotatedSimple:
|
---|
| 27 | @JsonGetter("Bla")
|
---|
| 28 | def getOne(self):
|
---|
| 29 | return 1
|
---|
| 30 | simple=AnnotatedSimple()
|
---|
| 31 | self.assertEquals(simple.getOne, getGetter(simple, 'Bla'))
|
---|
| 32 | self.assertRaises(ValueError, lambda:getGetter(simple, 'UnknownGetter'))
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | |
---|
Note:
See
TracBrowser
for help on using the repository browser.