Rev | Line | |
---|
[160] | 1 | import unittest
|
---|
| 2 | from pyson.JsonValue import JsonValue, getJsonValue
|
---|
| 3 |
|
---|
| 4 | class 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.