source: pyson/test/JsonGetterTest.py@ 1292

Last change on this file since 1292 was 160, checked in by wouter, 4 years ago

#58 added @JsonValue annotation but not yet working

File size: 1.1 KB
RevLine 
[150]1from pyson.JsonGetter import JsonGetter, getGetter
2import unittest
3
[160]4class 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.