Last change
on this file since 62 was 59, checked in by Wouter Pasman, 3 years ago |
#44 manual commit of first public release, because this will cause the dist directory to move
|
File size:
1.1 KB
|
Line | |
---|
1 | from _decimal import Decimal
|
---|
2 | import unittest
|
---|
3 |
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 |
|
---|
6 | from geniusweb.issuevalue.NumberValue import NumberValue
|
---|
7 | from geniusweb.issuevalue.Value import Value
|
---|
8 |
|
---|
9 |
|
---|
10 | class NumberValueTest(unittest.TestCase):
|
---|
11 | pyson=ObjectMapper()
|
---|
12 | val = NumberValue(Decimal('0.1237'))
|
---|
13 | val2 = NumberValue(Decimal('2'))
|
---|
14 | valjson = 0.1237
|
---|
15 |
|
---|
16 | def testSerialize(self):
|
---|
17 | print(str(self.pyson.toJson(self.val)))
|
---|
18 | self.assertEqual(self.valjson, self.pyson.toJson(self.val))
|
---|
19 |
|
---|
20 | def testDeserialize(self):
|
---|
21 | self.assertEqual(self.val, self.pyson.parse(self.valjson, Value))
|
---|
22 |
|
---|
23 | def testSerialize2(self):
|
---|
24 | print(str(self.pyson.toJson(NumberValue(Decimal("900")))))
|
---|
25 |
|
---|
26 | def testNonDecimal(self):
|
---|
27 | self.assertRaises(ValueError, lambda:NumberValue(1200))
|
---|
28 |
|
---|
29 | def testHash(self):
|
---|
30 | self.assertEqual(self.val,self.val)
|
---|
31 | self.assertNotEqual(self.val,self.val2)
|
---|
32 | self.assertNotEqual(hash(self.val), hash(self.val2))
|
---|
33 |
|
---|
34 | def testRepr(self):
|
---|
35 | self.assertEqual('2', repr(self.val2)) |
---|
Note:
See
TracBrowser
for help on using the repository browser.