Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with self.assertRaises(TypeError):
_segyio.set_field(".", 0, 1)
with self.assertRaises(IndexError):
_segyio.get_field(hdr, 0)
with self.assertRaises(IndexError):
_segyio.set_field(hdr, 0, 1)
_segyio.set_field(hdr, 1, 127)
_segyio.set_field(hdr, 5, 67)
_segyio.set_field(hdr, 9, 19)
self.assertEqual(_segyio.get_field(hdr, 1), 127)
self.assertEqual(_segyio.get_field(hdr, 5), 67)
self.assertEqual(_segyio.get_field(hdr, 9), 19)
with self.assertRaises(TypeError):
trace_header = _segyio.read_traceheader("+", )
with self.assertRaises(TypeError):
trace_header = _segyio.read_traceheader(f, 0, None)
trace_header = _segyio.read_traceheader(f, 0, _segyio.empty_traceheader(), metrics['trace0'], metrics['trace_bsize'])
self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
self.assertEqual(_segyio.get_field(trace_header, xlb), 20)
trace_header = _segyio.read_traceheader(f, 1, _segyio.empty_traceheader(), metrics['trace0'], metrics['trace_bsize'])
self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
self.assertEqual(_segyio.get_field(trace_header, xlb), 21)
_segyio.set_field(trace_header, ilb, 99)
_segyio.set_field(trace_header, xlb, 42)
_segyio.write_traceheader(f, 0, trace_header, metrics['trace0'], metrics['trace_bsize'])
trace_header = _segyio.read_traceheader(f, 0, _segyio.empty_traceheader(), metrics['trace0'], metrics['trace_bsize'])
self.assertEqual(_segyio.get_field(trace_header, ilb), 99)
self.assertEqual(_segyio.get_field(trace_header, xlb), 42)
_segyio.close(f)
def test_get_and_set_field(self):
hdr = _segyio.empty_traceheader()
with self.assertRaises(TypeError):
_segyio.get_field(".", 0)
with self.assertRaises(TypeError):
_segyio.set_field(".", 0, 1)
with self.assertRaises(IndexError):
_segyio.get_field(hdr, 0)
with self.assertRaises(IndexError):
_segyio.set_field(hdr, 0, 1)
_segyio.set_field(hdr, 1, 127)
_segyio.set_field(hdr, 5, 67)
_segyio.set_field(hdr, 9, 19)
self.assertEqual(_segyio.get_field(hdr, 1), 127)
self.assertEqual(_segyio.get_field(hdr, 5), 67)
empty = _segyio.empty_traceheader()
with self.assertRaises(TypeError):
trace_header = _segyio.read_traceheader("+", )
with self.assertRaises(TypeError):
trace_header = _segyio.read_traceheader(f, 0, None)
trace_header = _segyio.read_traceheader(f, 0, _segyio.empty_traceheader(), metrics['trace0'], metrics['trace_bsize'])
self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
self.assertEqual(_segyio.get_field(trace_header, xlb), 20)
trace_header = _segyio.read_traceheader(f, 1, _segyio.empty_traceheader(), metrics['trace0'], metrics['trace_bsize'])
self.assertEqual(_segyio.get_field(trace_header, ilb), 1)
self.assertEqual(_segyio.get_field(trace_header, xlb), 21)
_segyio.set_field(trace_header, ilb, 99)
_segyio.set_field(trace_header, xlb, 42)
_segyio.write_traceheader(f, 0, trace_header, metrics['trace0'], metrics['trace_bsize'])
trace_header = _segyio.read_traceheader(f, 0, _segyio.empty_traceheader(), metrics['trace0'], metrics['trace_bsize'])
self.assertEqual(_segyio.get_field(trace_header, ilb), 99)
self.assertEqual(_segyio.get_field(trace_header, xlb), 42)
_segyio.close(f)
_segyio.get_field(".", 0)
with self.assertRaises(TypeError):
_segyio.set_field(".", 0, 1)
with self.assertRaises(IndexError):
_segyio.get_field(hdr, 0)
with self.assertRaises(IndexError):
_segyio.set_field(hdr, 0, 1)
_segyio.set_field(hdr, 1, 127)
_segyio.set_field(hdr, 5, 67)
_segyio.set_field(hdr, 9, 19)
self.assertEqual(_segyio.get_field(hdr, 1), 127)
self.assertEqual(_segyio.get_field(hdr, 5), 67)
self.assertEqual(_segyio.get_field(hdr, 9), 19)
def test_read_binary_header_fields(self):
f = _segyio.open(self.filename, "r")
binary_header = _segyio.read_binaryheader(f)
with self.assertRaises(TypeError):
value = _segyio.get_field("s", 0)
with self.assertRaises(IndexError):
value = _segyio.get_field(binary_header, -1)
self.assertEqual(_segyio.get_field(binary_header, 3225), 1)
self.assertEqual(_segyio.get_field(binary_header, 3221), 50)
_segyio.close(f)
def test_read_binary_header_fields(self):
f = _segyio.open(self.filename, "r")
binary_header = _segyio.read_binaryheader(f)
with self.assertRaises(TypeError):
value = _segyio.get_field("s", 0)
with self.assertRaises(IndexError):
value = _segyio.get_field(binary_header, -1)
self.assertEqual(_segyio.get_field(binary_header, 3225), 1)
self.assertEqual(_segyio.get_field(binary_header, 3221), 50)
_segyio.close(f)
def test_get_and_set_field(self):
hdr = _segyio.empty_traceheader()
with self.assertRaises(TypeError):
_segyio.get_field(".", 0)
with self.assertRaises(TypeError):
_segyio.set_field(".", 0, 1)
with self.assertRaises(IndexError):
_segyio.get_field(hdr, 0)
with self.assertRaises(IndexError):
_segyio.set_field(hdr, 0, 1)
_segyio.set_field(hdr, 1, 127)
_segyio.set_field(hdr, 5, 67)
_segyio.set_field(hdr, 9, 19)
self.assertEqual(_segyio.get_field(hdr, 1), 127)
self.assertEqual(_segyio.get_field(hdr, 5), 67)
self.assertEqual(_segyio.get_field(hdr, 9), 19)
def test_read_binary_header_fields(self):
f = _segyio.open(self.filename, "r")
binary_header = _segyio.read_binaryheader(f)
with self.assertRaises(TypeError):
value = _segyio.get_field("s", 0)
with self.assertRaises(IndexError):
value = _segyio.get_field(binary_header, -1)
self.assertEqual(_segyio.get_field(binary_header, 3225), 1)
self.assertEqual(_segyio.get_field(binary_header, 3221), 50)
_segyio.close(f)