コード例 #1
0
    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)
コード例 #2
0
ファイル: test_ibm_float_packer.py プロジェクト: yzchs7/segpy
    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)
コード例 #3
0
ファイル: test_ibm_float_packer.py プロジェクト: yzchs7/segpy
    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)
コード例 #4
0
    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)
コード例 #5
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)
コード例 #6
0
ファイル: toolkit.py プロジェクト: abingham/segpy
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)
コード例 #7
0
ファイル: test_ibm_float_packer.py プロジェクト: yzchs7/segpy
 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)
コード例 #8
0
ファイル: test_ibm_float_packer.py プロジェクト: yzchs7/segpy
 def test_unpack_empty(self):
     dest = ibm_float_packer.pack_ibm_floats(b'')
     assert len(dest) == 0
コード例 #9
0
ファイル: test_ibm_float_packer.py プロジェクト: yzchs7/segpy
 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)
コード例 #10
0
ファイル: test_ibm_float_packer.py プロジェクト: yzchs7/segpy
 def test_packed_floats_are_four_bytes(self, floats):
     packed = ibm_float_packer.pack_ibm_floats(floats)
     assert len(packed) == len(floats) * 4
コード例 #11
0
 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)
コード例 #12
0
 def test_unpack_empty(self):
     dest = ibm_float_packer.pack_ibm_floats(b'')
     assert len(dest) == 0
コード例 #13
0
 def test_packed_floats_are_four_bytes(self, floats):
     packed = ibm_float_packer.pack_ibm_floats(floats)
     assert len(packed) == len(floats) * 4