Back to index

python3.2  3.2.2
Public Member Functions
test.json_tests.test_indent.TestIndent Class Reference
Inheritance diagram for test.json_tests.test_indent.TestIndent:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def test_indent
def test_indent0

Detailed Description

Definition at line 6 of file test_indent.py.


Member Function Documentation

Definition at line 7 of file test_indent.py.

00007 
00008     def test_indent(self):
00009         h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
00010              {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
00011 
00012         expect = textwrap.dedent("""\
00013         [
00014         \t[
00015         \t\t"blorpie"
00016         \t],
00017         \t[
00018         \t\t"whoops"
00019         \t],
00020         \t[],
00021         \t"d-shtaeou",
00022         \t"d-nthiouh",
00023         \t"i-vhbjkhnth",
00024         \t{
00025         \t\t"nifty": 87
00026         \t},
00027         \t{
00028         \t\t"field": "yes",
00029         \t\t"morefield": false
00030         \t}
00031         ]""")
00032 
00033         d1 = self.dumps(h)
00034         d2 = self.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
00035         d3 = self.dumps(h, indent='\t', sort_keys=True, separators=(',', ': '))
00036 
00037         h1 = self.loads(d1)
00038         h2 = self.loads(d2)
00039         h3 = self.loads(d3)
00040 
00041         self.assertEqual(h1, h)
00042         self.assertEqual(h2, h)
00043         self.assertEqual(h3, h)
00044         self.assertEqual(d2, expect.expandtabs(2))
00045         self.assertEqual(d3, expect)

Here is the call graph for this function:

Definition at line 46 of file test_indent.py.

00046 
00047     def test_indent0(self):
00048         h = {3: 1}
00049         def check(indent, expected):
00050             d1 = self.dumps(h, indent=indent)
00051             self.assertEqual(d1, expected)
00052 
00053             sio = StringIO()
00054             self.json.dump(h, sio, indent=indent)
00055             self.assertEqual(sio.getvalue(), expected)
00056 
00057         # indent=0 should emit newlines
00058         check(0, '{\n"3": 1\n}')
00059         # indent=None is more compact
00060         check(None, '{"3": 1}')
00061 

Here is the call graph for this function:


The documentation for this class was generated from the following file: