#NEWLINE# def test_simple_struct( ) : #NEWLINE# #INDENT# data = struct . pack ( '>IqQb' , 2947603933 , ( - 57 ) , 90 , 0 ) #NEWLINE# test = b . parse ( data , spec = test_struct ) #NEWLINE# assert_equal ( test . __offsets__ . flag_one , 0 ) #NEWLINE# assert_equal ( test . __offsets__ . flag_two , 1 ) #NEWLINE# assert_equal ( test . __offsets__ . flag_three , 2 ) #NEWLINE# assert_equal ( test . __offsets__ . flag_four , 3 ) #NEWLINE# assert_equal ( test . __offsets__ . first , 4 ) #NEWLINE# assert_equal ( test . __offsets__ . blah , 16 ) #NEWLINE# assert_equal ( test . __offsets__ . second , 32 ) #NEWLINE# assert_equal ( test . __offsets__ . third , 96 ) #NEWLINE# assert_equal ( test . __offsets__ . fourth , 160 ) #NEWLINE# assert_equal ( len ( test ) , 168 ) #NEWLINE# assert_equal ( test . flag_one , True ) #NEWLINE# assert_equal ( test . flag_two , False ) #NEWLINE# assert_equal ( test . flag_three , True ) #NEWLINE# assert_equal ( test . flag_four , False ) #NEWLINE# assert_equal ( test . first , 251 ) #NEWLINE# assert_equal ( test . blah , 56797 ) #NEWLINE# assert_equal ( test . second , ( - 57 ) ) #NEWLINE# assert_equal ( test . third , 90 ) #NEWLINE# assert_equal ( test . fourth , 0 ) #NEWLINE# output_data = b . write ( test , test_struct ) #NEWLINE# assert_equal ( output_data , data ) #NEWLINE# expected_json_struct = { #NEWLINE# #INDENT# 'flag_one' : True , #NEWLINE# 'flag_two' : False , #NEWLINE# 'flag_three' : True , #NEWLINE# 'flag_four' : False , #NEWLINE# 'first' : 251 , #NEWLINE# 'blah' : 56797 , #NEWLINE# 'second' : ( - 57 ) , #NEWLINE# 'third' : 90 , #NEWLINE# 'fourth' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# assert_equal ( json . loads ( test . as_json ( ) ) , expected_json_struct )