def test_python_pack_used_as_fallback(self, python_packer, mgr): # Don't let the manager report that it contains 'cpp' mgr.__contains__ = MagicMock(return_value=False) data = byte_arrays_of_floats() with test.util.force_python_ibm_float(False): ibm_float_packer.pack_ibm_floats(data) python_packer.return_value.pack.assert_called_with(data)
def test_python_pack_used_when_forced(self, python_packer, mgr): # Let the manager report that it contains 'cpp' mgr.__contains__ = MagicMock(return_value=True) data = byte_arrays_of_floats().example() with test.util.force_python_ibm_float(True): ibm_float_packer.pack_ibm_floats(data) mgr.__getitem__.assert_not_called() python_packer.return_value.pack.assert_called_with(data)
def test_roundtrip(self, data): packed = ibm_float_packer.pack_ibm_floats(data) unpacked = ibm_float_packer.unpack_ibm_floats(packed, len(data)) for f, u in zip(data, unpacked): assert almost_equal( f, float(u), epsilon=EPSILON_IBM_FLOAT)
def write_binary_values(fh, values, seg_y_type, endian='>'): """Write a series of values to a file. Args: fh: A file-like-object open for writing in binary mode. values: An iterable series of values. seg_y_type: The SEG Y data type. endian: '>' for big-endian data (the standard and default), '<' for little-endian (non-standard) """ ctype = SEG_Y_TYPE_TO_CTYPE[seg_y_type] buf = (pack_ibm_floats(values) if ctype == 'ibm' else pack_values(values, ctype, endian)) fh.write(buf)
def test_roundtrip(self, floats): byte_data, num_items = floats unpacked = ibm_float_packer.unpack_ibm_floats(byte_data, num_items) packed = ibm_float_packer.pack_ibm_floats(unpacked) assert bytes(byte_data) == bytes(packed)
def test_unpack_empty(self): dest = ibm_float_packer.pack_ibm_floats(b'') assert len(dest) == 0
def test_roundtrip(self, data): packed = ibm_float_packer.pack_ibm_floats(data) unpacked = ibm_float_packer.unpack_ibm_floats(packed, len(data)) for f, u in zip(data, unpacked): assert almost_equal(f, float(u), epsilon=EPSILON_IBM_FLOAT)
def test_packed_floats_are_four_bytes(self, floats): packed = ibm_float_packer.pack_ibm_floats(floats) assert len(packed) == len(floats) * 4