Skip to content

Commit 156a36e

Browse files
committed
Add python fields tests
Fields of all currently existing types are verified, but not all fields as it would be somewhat repeating "application" tests and chance of error here is small.
1 parent dafc785 commit 156a36e

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

python/test/segy.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,108 @@ def test_write_header_update_atomic(small):
937937
assert header == f.header[10]
938938

939939

940+
def test_field_types_read():
941+
with segyio.open(testdata / 'decrement.sgy', "r", ignore_geometry=True) as f:
942+
bdec = f.bin
943+
tdec = f.header[3]
944+
945+
assert bdec[BinField.NrTracesInStream] == 18446744073709551572
946+
assert bdec[BinField.JobID] == 2147483647
947+
assert bdec[BinField.SamplesOriginal] == 65526
948+
assert bdec[BinField.VerticalSum] == 32755
949+
assert bdec[BinField.SEGYRevisionMinor] == 217
950+
assert bdec[BinField.ExtIntervalOriginal] == 1125899906842593.0
951+
952+
assert tdec[TraceField.INLINE_3D] == 2147483355
953+
assert tdec[TraceField.TRACE_SAMPLE_COUNT] == 65382
954+
assert tdec[TraceField.DelayRecordingTime] == 32627
955+
956+
with segyio.open(testdata / 'increment.sgy', "r", ignore_geometry=True) as f:
957+
binc = f.bin
958+
tinc = f.header[3]
959+
960+
assert binc[BinField.NrTracesInStream] == 43
961+
assert binc[BinField.JobID] == -2147483648
962+
assert binc[BinField.SamplesOriginal] == 8
963+
assert binc[BinField.VerticalSum] == -32756
964+
assert binc[BinField.SEGYRevisionMinor] == 37
965+
assert binc[BinField.ExtIntervalOriginal] == -1125899906842593.0
966+
967+
assert tinc[TraceField.INLINE_3D] == -2147483356
968+
assert tinc[TraceField.TRACE_SAMPLE_COUNT] == 152
969+
assert tinc[TraceField.DelayRecordingTime] == -32628
970+
971+
972+
@tmpfiles(testdata / 'small.sgy')
973+
def test_field_types_write(tmpdir):
974+
updpath = tmpdir / 'small.sgy'
975+
976+
with segyio.open(updpath, ignore_geometry=True) as f:
977+
orig_binh = f.bin
978+
orig_trh = f.header[0]
979+
980+
with segyio.open(updpath, mode='r+', ignore_geometry=True) as f:
981+
bupd = {
982+
BinField.NrTracesInStream: 18446744073709551615,
983+
BinField.JobID: 2147483647,
984+
BinField.SamplesOriginal: 65535,
985+
BinField.VerticalSum: -32768,
986+
BinField.SEGYRevisionMinor: 255,
987+
BinField.ExtIntervalOriginal: 10.125,
988+
}
989+
990+
tupd = {
991+
TraceField.INLINE_3D: -2147483648,
992+
TraceField.TRACE_SAMPLE_COUNT: 65535,
993+
TraceField.DelayRecordingTime: 32767,
994+
}
995+
996+
f.bin.update(bupd)
997+
f.header[0].update(tupd)
998+
f.flush()
999+
1000+
with segyio.open(updpath, ignore_geometry=True) as f:
1001+
binh = f.bin
1002+
trh = f.header[0]
1003+
1004+
assert orig_binh != binh
1005+
assert orig_trh != trh
1006+
1007+
for k, v in bupd.items():
1008+
assert binh[k] == v
1009+
1010+
for k, v in tupd.items():
1011+
assert trh[k] == v
1012+
1013+
1014+
@tmpfiles(testdata / 'small.sgy')
1015+
def test_field_types_bad_write(tmpdir):
1016+
updpath = tmpdir / 'small.sgy'
1017+
1018+
with segyio.open(updpath, ignore_geometry=True) as f:
1019+
binh = f.bin
1020+
1021+
with segyio.open(updpath, mode='r+', ignore_geometry=True) as f:
1022+
bad = {
1023+
BinField.NrTracesInStream: [18446744073709551616],
1024+
BinField.JobID: [18446744073709551616, 2147483648],
1025+
BinField.SamplesOriginal: [65536, -1],
1026+
BinField.VerticalSum: [-32769],
1027+
BinField.SEGYRevisionMinor: [256, -127],
1028+
BinField.ExtIntervalOriginal: ["wrong"],
1029+
}
1030+
1031+
for k, vlist in bad.items():
1032+
for v in vlist:
1033+
with pytest.raises(ValueError, match="out of range"):
1034+
f.bin[k] = v
1035+
1036+
f.flush()
1037+
1038+
with segyio.open(updpath, ignore_geometry=True) as f:
1039+
assert binh == f.bin
1040+
1041+
9401042
def test_fopen_error():
9411043
# non-existent file
9421044
with pytest.raises(IOError):

0 commit comments

Comments
 (0)