<s> import decimal <EOL> from unittest import TestCase <EOL> from StringIO import StringIO <EOL> import simplejson as json <EOL> from simplejson import OrderedDict <EOL> class TestDecode ( TestCase ) : <EOL> def test_decimal ( self ) : <EOL> rval = json . loads ( '<STR_LIT>' , parse_float = decimal . Decimal ) <EOL> self . assert_ ( isinstance ( rval , decimal . Decimal ) ) <EOL> self . assertEquals ( rval , decimal . Decimal ( '<STR_LIT>' ) ) <EOL> def test_float ( self ) : <EOL> rval = json . loads ( '<STR_LIT:1>' , parse_int = float ) <EOL> self . assert_ ( isinstance ( rval , float ) ) <EOL> self . assertEquals ( rval , <NUM_LIT:1.0> ) <EOL> def test_decoder_optimizations ( self ) : <EOL> rval = json . loads ( '<STR_LIT>' ) <EOL> self . assertEquals ( rval , { "<STR_LIT:key>" : "<STR_LIT:value>" , "<STR_LIT:k>" : "<STR_LIT:v>" } ) <EOL> def test_object_pairs_hook ( self ) : <EOL> s = '<STR_LIT>' <EOL> p = [ ( "<STR_LIT>" , <NUM_LIT:1> ) , ( "<STR_LIT>" , <NUM_LIT:2> ) , ( "<STR_LIT>" , <NUM_LIT:3> ) , ( "<STR_LIT>" , <NUM_LIT:4> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:5> ) , ( "<STR_LIT>" , <NUM_LIT:6> ) , ( "<STR_LIT>" , <NUM_LIT:7> ) ] <EOL> self . assertEqual ( json . loads ( s ) , eval ( s ) ) <EOL> self . assertEqual ( json . loads ( s , object_pairs_hook = lambda x : x ) , p ) <EOL> self . assertEqual ( json . load ( StringIO ( s ) , <EOL> object_pairs_hook = lambda x : x ) , p ) <EOL> od = json . loads ( s , object_pairs_hook = OrderedDict ) <EOL> self . assertEqual ( od , OrderedDict ( p ) ) <EOL> self . assertEqual ( type ( od ) , OrderedDict ) <EOL> self . assertEqual ( json . loads ( s , <EOL> object_pairs_hook = OrderedDict , <EOL> object_hook = lambda x : None ) , <EOL> OrderedDict ( p ) ) </s>
