from pyson.JsonGetter import JsonGetter, getGetter import unittest class JsonGetterTest(unittest.TestCase): def testGetter(self): class Simple: @JsonGetter("One") def getBla(self): return 1 simple=Simple() self.assertTrue(hasattr(simple.getBla, '__jsongetter__')) self.assertEquals('One', getattr(simple.getBla,'__jsongetter__')) def testGetGetterBasic(self): class Simple: def getBla(self): return 1 simple=Simple() self.assertEquals(simple.getBla, getGetter(simple, 'Bla')) self.assertRaises(ValueError, lambda:getGetter(simple, 'UnknownGetter')) def testGetGetterAnnotated(self): class AnnotatedSimple: @JsonGetter("Bla") def getOne(self): return 1 simple=AnnotatedSimple() self.assertEquals(simple.getOne, getGetter(simple, 'Bla')) self.assertRaises(ValueError, lambda:getGetter(simple, 'UnknownGetter'))