~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/python/simplejson-2.1.1/simplejson/tests/test_decimal.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from decimal import Decimal
 
2
from unittest import TestCase
 
3
 
 
4
import simplejson as json
 
5
 
 
6
class TestDecimal(TestCase):
 
7
    NUMS = "1.0", "10.00", "1.1", "1234567890.1234567890", "500"
 
8
    def test_decimal_encode(self):
 
9
        for d in map(Decimal, self.NUMS):
 
10
            self.assertEquals(json.dumps(d, use_decimal=True), str(d))
 
11
    
 
12
    def test_decimal_decode(self):
 
13
        for s in self.NUMS:
 
14
            self.assertEquals(json.loads(s, parse_float=Decimal), Decimal(s))
 
15
    
 
16
    def test_decimal_roundtrip(self):
 
17
        for d in map(Decimal, self.NUMS):
 
18
            # The type might not be the same (int and Decimal) but they
 
19
            # should still compare equal.
 
20
            self.assertEquals(
 
21
                json.loads(
 
22
                    json.dumps(d, use_decimal=True), parse_float=Decimal),
 
23
                d)
 
24
            self.assertEquals(
 
25
                json.loads(
 
26
                    json.dumps([d], use_decimal=True), parse_float=Decimal),
 
27
                [d])
 
28
 
 
29
    def test_decimal_defaults(self):
 
30
        d = Decimal(1)
 
31
        # use_decimal=False is the default
 
32
        self.assertRaises(TypeError, json.dumps, d, use_decimal=False)
 
33
        self.assertRaises(TypeError, json.dumps, d)
 
 
b'\\ No newline at end of file'