def test_trace_header_delegation(self, delegatee): delegatee.configure_mock(**{'trace_header.return_value': TraceHeaderRev1()}) trace_index = 42 dd = DelegatingDataset(delegatee) ts = dd.trace_header(trace_index) delegatee.trace_header.assert_called_once_with(trace_index) assert are_equal(ts, TraceHeaderRev1())
def test_binary_reel_header_delegation(self, delegatee): p = PropertyMock(return_value=BinaryReelHeader()) type(delegatee).binary_reel_header = p dd = DelegatingDataset(delegatee) brh = dd.binary_reel_header p.assert_called_once_with() assert are_equal(brh, BinaryReelHeader())
def test_trace_header_delegation(self, delegatee): delegatee.configure_mock( **{'trace_header.return_value': TraceHeaderRev1()}) trace_index = 42 dd = DelegatingDataset(delegatee) ts = dd.trace_header(trace_index) delegatee.trace_header.assert_called_once_with(trace_index) assert are_equal(ts, TraceHeaderRev1())
def test_read_header_successfully(self, trace_header_written, endian): trace_header_packer = make_header_packer(TraceHeaderRev1, endian) buffer = trace_header_packer.pack(trace_header_written) with BytesIO(buffer) as fh: trace_header = toolkit.read_trace_header(fh, trace_header_packer, pos=0) assert are_equal(trace_header_written, trace_header)
def test_roundtrip(self, write_header, endian): with BytesIO() as write_stream: write_binary_reel_header(write_stream, write_header, endian) written_stream = write_stream.getvalue() with BytesIO(written_stream) as read_stream: read_header = read_binary_reel_header(read_stream, endian) self.assertTrue(are_equal(write_header, read_header))
def test_roundtrip(self, write_header, endian): with BytesIO() as write_stream: write_binary_reel_header(write_stream, write_header, endian) written_stream = write_stream.getvalue() with BytesIO(written_stream) as read_stream: read_header = read_binary_reel_header(read_stream, endian) assert are_equal(write_header, read_header)
def _compare_datasets(ds1, ds2, compare_dimensionality=True): assert ds1.textual_reel_header == ds2.textual_reel_header assert are_equal(ds1.binary_reel_header, ds2.binary_reel_header) assert ds1.extended_textual_header == ds2.extended_textual_header assert ds1.data_sample_format == ds2.data_sample_format assert ds1.data_sample_format_description == ds2.data_sample_format_description assert sorted(ds1.trace_indexes()) == sorted(ds2.trace_indexes()) assert ds1.num_traces() == ds2.num_traces() assert len(list(ds1.trace_indexes())) == ds1.num_traces() assert len(list(ds2.trace_indexes())) == ds2.num_traces() assert sorted(ds1.trace_indexes()) == sorted(ds2.trace_indexes()) for trace_index in ds1.trace_indexes(): assert are_equal(ds1.trace_header(trace_index), ds2.trace_header(trace_index)) assert list(ds1.trace_samples(trace_index)) == list(ds2.trace_samples(trace_index)) if compare_dimensionality: assert ds1.dimensionality == ds2.dimensionality
def _compare_datasets(ds1, ds2, compare_dimensionality=True): assert ds1.textual_reel_header == ds2.textual_reel_header assert are_equal(ds1.binary_reel_header, ds2.binary_reel_header) assert ds1.extended_textual_header == ds2.extended_textual_header assert ds1.data_sample_format == ds2.data_sample_format assert ds1.data_sample_format_description == ds2.data_sample_format_description assert sorted(ds1.trace_indexes()) == sorted(ds2.trace_indexes()) assert ds1.num_traces() == ds2.num_traces() assert len(list(ds1.trace_indexes())) == ds1.num_traces() assert len(list(ds2.trace_indexes())) == ds2.num_traces() assert sorted(ds1.trace_indexes()) == sorted(ds2.trace_indexes()) for trace_index in ds1.trace_indexes(): assert are_equal(ds1.trace_header(trace_index), ds2.trace_header(trace_index)) assert list(ds1.trace_samples(trace_index)) == list( ds2.trace_samples(trace_index)) if compare_dimensionality: assert ds1.dimensionality == ds2.dimensionality
def test_unpack_bijective_header(self): class BijectiveHeader(Header): START_OFFSET_IN_BYTES = 1 field_a = field(Int32, 1, 0, "Field A.") field_b = field(NNInt32, 5, 0, "Field B.") packer = make_header_packer(BijectiveHeader, endian='>') buffer = bytes((0x12, 0x34, 0x56, 0x78, 0x01, 0x35, 0x79, 0x32)) header = packer.unpack(buffer) assert are_equal( header, BijectiveHeader(field_a=0x12345678, field_b=0x01357932))
def test_unpack_bijective_header(self): class BijectiveHeader(Header): START_OFFSET_IN_BYTES = 1 field_a = field(Int32, 1, 0, "Field A.") field_b = field(NNInt32, 5, 0, "Field B.") packer = make_header_packer(BijectiveHeader, endian='>') buffer = bytes((0x12, 0x34, 0x56, 0x78, 0x01, 0x35, 0x79, 0x32)) header = packer.unpack(buffer) assert are_equal(header, BijectiveHeader(field_a=0x12345678, field_b=0x01357932))
def test_round_trip(tmpdir, dataset): segy_file = str(tmpdir / 'test.segy') with open(segy_file, mode='bw') as fh: write_segy(fh, dataset) with open(segy_file, mode='br') as fh: reader = create_reader( fh, trace_header_format=dataset._trace_header_type, dimensionality=dataset.dimensionality) assert dataset.textual_reel_header == reader.textual_reel_header assert are_equal(dataset.binary_reel_header, reader.binary_reel_header) assert dataset.extended_textual_header == reader.extended_textual_header assert dataset.dimensionality == reader.dimensionality
def test_inequality(self, a, b, c): assume(a != 0) lhs = ExampleHeader(-a, b, c) rhs = ExampleHeader(a, b, c) assert not are_equal(lhs, rhs)
def test_inequality_different_type(self): h = ExampleHeader(1, 2, 3) assert not are_equal(h, 42)
def test_pickle_roundtrip(self, a, b, c): h1 = ExampleHeader(a, b, c) s = pickle.dumps(h1) h2 = pickle.loads(s) assert are_equal(h1, h2)
def test_equality(self, a, b, c): lhs = ExampleHeader(a, b, c) rhs = ExampleHeader(a, b, c) assert are_equal(lhs, rhs)
unassigned_4 = field(Int16, offset=239, default=0, documentation="Unassigned 4") in_filename = "data/rth.segy" out_filename = "data/rth_out2.segy" in_file = open(in_filename, 'rb') with open(out_filename, 'wb') as out_file: segy_reader_in = create_reader(in_file, trace_header_format=CustomTraceHeader) write_segy(out_file, segy_reader_in, trace_header_format=CustomTraceHeader) out_file = open(out_filename, 'rb') segy_reader_out = create_reader(in_file, trace_header_format=CustomTraceHeader) for trace_index in segy_reader_in.trace_indexes(): trace_offset = segy_reader_in._trace_offset_catalog[trace_index] print(trace_index, hex(trace_offset)) head0 = segy_reader_in.trace_header(trace_index) head1 = segy_reader_out.trace_header(trace_index) assert are_equal(head0, head1), "Error {}".format(trace_index) data0 = segy_reader_in.trace_samples(trace_index) data1 = segy_reader_out.trace_samples(trace_index) assert data0 == data1
unassigned_3 = field( Int16, offset=237, default=0, documentation="Unassigned 3") unassigned_4 = field( Int16, offset=239, default=0, documentation="Unassigned 4") in_filename = "data/rth.segy" out_filename = "data/rth_out2.segy" in_file = open(in_filename, 'rb') with open(out_filename, 'wb') as out_file: segy_reader_in = create_reader(in_file, trace_header_format=CustomTraceHeader) write_segy(out_file, segy_reader_in, trace_header_format=CustomTraceHeader) out_file = open(out_filename, 'rb') segy_reader_out = create_reader(out_file, trace_header_format=CustomTraceHeader) for trace_index in segy_reader_in.trace_indexes(): trace_offset = segy_reader_in._trace_offset_catalog[trace_index] print(trace_index, hex(trace_offset)) head0 = segy_reader_in.trace_header(trace_index) head1 = segy_reader_out.trace_header(trace_index) assert are_equal(head0, head1), "Error {}".format(trace_index) data0 = segy_reader_in.trace_samples(trace_index) data1 = segy_reader_out.trace_samples(trace_index) assert data0 == data1