~ubuntu-branches/ubuntu/precise/enigmail/precise-security

« back to all changes in this revision

Viewing changes to python/simplejson-2.1.1/simplejson/tests/test_indent.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-12 16:36:01 UTC
  • mfrom: (0.12.15)
  • Revision ID: package-import@ubuntu.com-20121112163601-t8e8skdfi3ni9iqp
Tags: 2:1.4.6-0ubuntu0.12.04.1
* New upstream release v1.4.6
  - see LP: #1080212 for USN information
* Drop unneeded patches
  - remove debian/patches/correct-version-number.diff
  - remove debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Support building in an objdir
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from unittest import TestCase
 
2
 
 
3
import simplejson as json
 
4
import textwrap
 
5
 
 
6
class TestIndent(TestCase):
 
7
    def test_indent(self):
 
8
        h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh',
 
9
             'i-vhbjkhnth',
 
10
             {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
 
11
 
 
12
        expect = textwrap.dedent("""\
 
13
        [
 
14
        \t[
 
15
        \t\t"blorpie"
 
16
        \t],
 
17
        \t[
 
18
        \t\t"whoops"
 
19
        \t],
 
20
        \t[],
 
21
        \t"d-shtaeou",
 
22
        \t"d-nthiouh",
 
23
        \t"i-vhbjkhnth",
 
24
        \t{
 
25
        \t\t"nifty": 87
 
26
        \t},
 
27
        \t{
 
28
        \t\t"field": "yes",
 
29
        \t\t"morefield": false
 
30
        \t}
 
31
        ]""")
 
32
 
 
33
 
 
34
        d1 = json.dumps(h)
 
35
        d2 = json.dumps(h, indent='\t', sort_keys=True, separators=(',', ': '))
 
36
        d3 = json.dumps(h, indent='  ', sort_keys=True, separators=(',', ': '))
 
37
        d4 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
 
38
 
 
39
        h1 = json.loads(d1)
 
40
        h2 = json.loads(d2)
 
41
        h3 = json.loads(d3)
 
42
        h4 = json.loads(d4)
 
43
 
 
44
        self.assertEquals(h1, h)
 
45
        self.assertEquals(h2, h)
 
46
        self.assertEquals(h3, h)
 
47
        self.assertEquals(h4, h)
 
48
        self.assertEquals(d3, expect.replace('\t', '  '))
 
49
        self.assertEquals(d4, expect.replace('\t', '  '))
 
50
        # NOTE: Python 2.4 textwrap.dedent converts tabs to spaces,
 
51
        #       so the following is expected to fail. Python 2.4 is not a
 
52
        #       supported platform in simplejson 2.1.0+.
 
53
        self.assertEquals(d2, expect)