<s> """<STR_LIT>""" <EOL> import sys <EOL> import struct <EOL> from . . structreader import Unpacker <EOL> from nose . tools import ( assert_true , assert_false , assert_equal , assert_raises ) <EOL> def test_unpacker ( ) : <EOL> s = b'<STR_LIT>' <EOL> le_int , = struct . unpack ( '<STR_LIT>' , b'<STR_LIT>' ) <EOL> be_int , = struct . unpack ( '<STR_LIT>' , b'<STR_LIT>' ) <EOL> if sys . byteorder == '<STR_LIT>' : <EOL> native_int = le_int <EOL> swapped_int = be_int <EOL> swapped_code = '<STR_LIT:>>' <EOL> else : <EOL> native_int = be_int <EOL> swapped_int = le_int <EOL> swapped_code = '<STR_LIT:<>' <EOL> up_str = Unpacker ( s , endian = '<STR_LIT:<>' ) <EOL> assert_equal ( up_str . read ( <NUM_LIT:4> ) , b'<STR_LIT>' ) <EOL> up_str . ptr = <NUM_LIT:0> <EOL> assert_equal ( up_str . unpack ( '<STR_LIT>' ) , ( b'<STR_LIT>' , ) ) <EOL> assert_equal ( up_str . unpack ( '<STR_LIT:h>' ) , ( le_int , ) ) <EOL> up_str = Unpacker ( s , endian = '<STR_LIT:>>' ) <EOL> assert_equal ( up_str . unpack ( '<STR_LIT>' ) , ( b'<STR_LIT>' , ) ) <EOL> assert_equal ( up_str . unpack ( '<STR_LIT:h>' ) , ( be_int , ) ) <EOL> up_str = Unpacker ( s , ptr = <NUM_LIT:4> , endian = '<STR_LIT:>>' ) <EOL> assert_equal ( up_str . unpack ( '<STR_LIT>' ) , ( le_int , ) ) <EOL> up_str = Unpacker ( s , ptr = <NUM_LIT:4> , endian = swapped_code ) <EOL> assert_equal ( up_str . unpack ( '<STR_LIT:h>' ) , ( swapped_int , ) ) <EOL> up_str . ptr = <NUM_LIT:4> <EOL> assert_equal ( up_str . unpack ( '<STR_LIT>' ) , ( le_int , ) ) <EOL> up_str . ptr = <NUM_LIT:4> <EOL> assert_equal ( up_str . unpack ( '<STR_LIT>' ) , ( be_int , ) ) <EOL> up_str . ptr = <NUM_LIT:4> <EOL> assert_equal ( up_str . unpack ( '<STR_LIT>' ) , ( native_int , ) ) <EOL> up_str . ptr = <NUM_LIT:2> <EOL> assert_equal ( up_str . read ( ) , b'<STR_LIT>' ) <EOL> assert_equal ( up_str . read ( ) , b'<STR_LIT>' ) <EOL> up_str . ptr = <NUM_LIT:2> <EOL> assert_equal ( up_str . read ( <NUM_LIT:2> ) , b'<STR_LIT>' ) <EOL> assert_equal ( up_str . read ( <NUM_LIT:2> ) , b'<STR_LIT>' ) </s>
