source: pyson/test/JsonValueTest.py@ 160

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

#58 added @JsonValue annotation but not yet working

File size: 806 bytes
Line 
1import unittest
2from pyson.JsonValue import JsonValue, getJsonValue
3
4class JsoValueTest(unittest.TestCase):
5 def testGetter(self):
6
7 class Simple:
8 @JsonValue()
9 def getBla(self):
10 return 1
11
12 simple=Simple()
13 self.assertTrue(hasattr(simple.getBla, '__jsonvalue__'))
14 self.assertTrue(getattr(simple.getBla, '__jsonvalue__'))
15
16 f=getJsonValue(Simple)
17 self.assertTrue(f)
18 self.assertEquals(1, f(simple))
19
20
21 def testGetterWrongArity(self):
22 self.assertRaises(ValueError, lambda: self.createClassWrongArity())
23
24 def createClassWrongArity(self):
25 class Simple:
26 @JsonValue()
27 def getBla(self, x):
28 return x
29
30
31
Note: See TracBrowser for help on using the repository browser.