<s> """<STR_LIT>""" <EOL> import unittest <EOL> class JSONDeSerializableTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> from acme . jose . interfaces import JSONDeSerializable <EOL> class Basic ( JSONDeSerializable ) : <EOL> def __init__ ( self , v ) : <EOL> self . v = v <EOL> def to_partial_json ( self ) : <EOL> return self . v <EOL> @ classmethod <EOL> def from_json ( cls , jobj ) : <EOL> return cls ( jobj ) <EOL> class Sequence ( JSONDeSerializable ) : <EOL> def __init__ ( self , x , y ) : <EOL> self . x = x <EOL> self . y = y <EOL> def to_partial_json ( self ) : <EOL> return [ self . x , self . y ] <EOL> @ classmethod <EOL> def from_json ( cls , jobj ) : <EOL> return cls ( <EOL> Basic . from_json ( jobj [ <NUM_LIT:0> ] ) , Basic . from_json ( jobj [ <NUM_LIT:1> ] ) ) <EOL> class Mapping ( JSONDeSerializable ) : <EOL> def __init__ ( self , x , y ) : <EOL> self . x = x <EOL> self . y = y <EOL> def to_partial_json ( self ) : <EOL> return { self . x : self . y } <EOL> @ classmethod <EOL> def from_json ( cls , jobj ) : <EOL> pass <EOL> self . basic1 = Basic ( '<STR_LIT>' ) <EOL> self . basic2 = Basic ( '<STR_LIT>' ) <EOL> self . seq = Sequence ( self . basic1 , self . basic2 ) <EOL> self . mapping = Mapping ( self . basic1 , self . basic2 ) <EOL> self . nested = Basic ( [ [ self . basic1 ] ] ) <EOL> self . tuple = Basic ( ( '<STR_LIT:foo>' , ) ) <EOL> self . Basic = Basic <EOL> self . Sequence = Sequence <EOL> self . Mapping = Mapping <EOL> def test_to_json_sequence ( self ) : <EOL> self . assertEqual ( self . seq . to_json ( ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_to_json_mapping ( self ) : <EOL> self . assertEqual ( self . mapping . to_json ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_to_json_other ( self ) : <EOL> mock_value = object ( ) <EOL> self . assertTrue ( self . Basic ( mock_value ) . to_json ( ) is mock_value ) <EOL> def test_to_json_nested ( self ) : <EOL> self . assertEqual ( self . nested . to_json ( ) , [ [ '<STR_LIT>' ] ] ) <EOL> def test_to_json ( self ) : <EOL> self . assertEqual ( self . tuple . to_json ( ) , ( ( '<STR_LIT:foo>' , ) ) ) <EOL> def test_from_json_not_implemented ( self ) : <EOL> from acme . jose . interfaces import JSONDeSerializable <EOL> self . assertRaises ( TypeError , JSONDeSerializable . from_json , '<STR_LIT>' ) <EOL> def test_json_loads ( self ) : <EOL> seq = self . Sequence . json_loads ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( seq , self . Sequence ) ) <EOL> self . assertTrue ( isinstance ( seq . x , self . Basic ) ) <EOL> self . assertTrue ( isinstance ( seq . y , self . Basic ) ) <EOL> self . assertEqual ( seq . x . v , '<STR_LIT>' ) <EOL> self . assertEqual ( seq . y . v , '<STR_LIT>' ) <EOL> def test_json_dumps ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . seq . json_dumps ( ) ) <EOL> def test_json_dumps_pretty ( self ) : <EOL> self . assertEqual ( self . seq . json_dumps_pretty ( ) , <EOL> '<STR_LIT>' ) <EOL> def test_json_dump_default ( self ) : <EOL> from acme . jose . interfaces import JSONDeSerializable <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , JSONDeSerializable . json_dump_default ( self . basic1 ) ) <EOL> jobj = JSONDeSerializable . json_dump_default ( self . seq ) <EOL> self . assertEqual ( len ( jobj ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( jobj [ <NUM_LIT:0> ] is self . basic1 ) <EOL> self . assertTrue ( jobj [ <NUM_LIT:1> ] is self . basic2 ) <EOL> def test_json_dump_default_type_error ( self ) : <EOL> from acme . jose . interfaces import JSONDeSerializable <EOL> self . assertRaises ( <EOL> TypeError , JSONDeSerializable . json_dump_default , object ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
