def test_read_numeric(): # make reader-like thing str_io = cStringIO.StringIO() r = _make_readerlike() r.mat_stream = str_io # check simplest of tags for base_dt, val, mdtype in (('u2', 30, mio5.miUINT16), ('i4', 1, mio5.miINT32), ('i2', -1, mio5.miINT16)): for byte_code in ('<', '>'): r.byte_order = byte_code r.dtypes = miob.convert_dtypes(mio5.mdtypes_template, byte_code) c_reader = m5u.VarReader5(r) yield assert_equal, c_reader.little_endian, byte_code == '<' yield assert_equal, c_reader.is_swapped, byte_code != boc.native_code for sde_f in (False, True): dt = np.dtype(base_dt).newbyteorder(byte_code) a = _make_tag(dt, val, mdtype, sde_f) a_str = a.tostring() _write_stream(str_io, a_str) el = c_reader.read_numeric() yield assert_equal, el, val # two sequential reads _write_stream(str_io, a_str, a_str) el = c_reader.read_numeric() yield assert_equal, el, val el = c_reader.read_numeric() yield assert_equal, el, val
def test_read_numeric(): # make reader-like thing str_io = cStringIO.StringIO() r = _make_readerlike() r.mat_stream = str_io # check simplest of tags for base_dt, val, mdtype in ( ('u2', 30, mio5.miUINT16), ('i4', 1, mio5.miINT32), ('i2', -1, mio5.miINT16)): for byte_code in ('<', '>'): r.byte_order = byte_code r.dtypes = miob.convert_dtypes(mio5.mdtypes_template, byte_code) c_reader = m5u.VarReader5(r) yield assert_equal, c_reader.little_endian, byte_code == '<' yield assert_equal, c_reader.is_swapped, byte_code != boc.native_code for sde_f in (False, True): dt = np.dtype(base_dt).newbyteorder(byte_code) a = _make_tag(dt, val, mdtype, sde_f) a_str = a.tostring() _write_stream(str_io, a_str) el = c_reader.read_numeric() yield assert_equal, el, val # two sequential reads _write_stream(str_io, a_str, a_str) el = c_reader.read_numeric() yield assert_equal, el, val el = c_reader.read_numeric() yield assert_equal, el, val
def test_read_numeric_writeable(): # make reader-like thing str_io = cStringIO.StringIO() r = _make_readerlike() r.mat_stream = str_io r.byte_order = '<' r.dtypes = miob.convert_dtypes(mio5.mdtypes_template, '<') c_reader = m5u.VarReader5(r) dt = np.dtype('<u2') a = _make_tag(dt, 30, mio5.miUINT16, 0) a_str = a.tostring() _write_stream(str_io, a_str) el = c_reader.read_numeric() yield assert_true, el.flags.writeable