<s> from unittest import TestCase <EOL> import simplejson as json <EOL> import textwrap <EOL> from StringIO import StringIO <EOL> class TestIndent ( TestCase ) : <EOL> def test_indent ( self ) : <EOL> h = [ [ '<STR_LIT>' ] , [ '<STR_LIT>' ] , [ ] , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT> } , { '<STR_LIT>' : '<STR_LIT:yes>' , '<STR_LIT>' : False } ] <EOL> expect = textwrap . dedent ( """<STR_LIT>""" ) <EOL> d1 = json . dumps ( h ) <EOL> d2 = json . dumps ( h , indent = '<STR_LIT:\t>' , sort_keys = True , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> d3 = json . dumps ( h , indent = '<STR_LIT:U+0020>' , sort_keys = True , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> d4 = json . dumps ( h , indent = <NUM_LIT:2> , sort_keys = True , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> h1 = json . loads ( d1 ) <EOL> h2 = json . loads ( d2 ) <EOL> h3 = json . loads ( d3 ) <EOL> h4 = json . loads ( d4 ) <EOL> self . assertEquals ( h1 , h ) <EOL> self . assertEquals ( h2 , h ) <EOL> self . assertEquals ( h3 , h ) <EOL> self . assertEquals ( h4 , h ) <EOL> self . assertEquals ( d3 , expect . replace ( '<STR_LIT:\t>' , '<STR_LIT:U+0020>' ) ) <EOL> self . assertEquals ( d4 , expect . replace ( '<STR_LIT:\t>' , '<STR_LIT:U+0020>' ) ) <EOL> self . assertEquals ( d2 , expect ) <EOL> def test_indent0 ( self ) : <EOL> h = { <NUM_LIT:3> : <NUM_LIT:1> } <EOL> def check ( indent , expected ) : <EOL> d1 = json . dumps ( h , indent = indent ) <EOL> self . assertEquals ( d1 , expected ) <EOL> sio = StringIO ( ) <EOL> json . dump ( h , sio , indent = indent ) <EOL> self . assertEquals ( sio . getvalue ( ) , expected ) <EOL> check ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> check ( None , '<STR_LIT>' ) </s>
