Skip to content

Commit

Permalink
Throw when curves can't id channel in the frame
Browse files Browse the repository at this point in the history
Related to issue equinor#241
When testing the same-signature channel in frame situation discovered
bad message in 'curves' call on missing channels in a frame.
  • Loading branch information
achaikou committed Jun 1, 2021
1 parent 0b556e8 commit 5c199d1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions python/data/chap4-7/eflr/frames-and-channels/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ Filename Description
================================= ==============================================
1-channel-2-frames.dlis Same channel belongs to two different frames

2-channels-same-content-diff-sign Two channels have same content, but different
copynumber. They belong to different frames.

2-channels-same-sign-diff-content Two channels have same signature, but
different content. Channel with that name
belongs to a frame.

2-channels-same-sign-same-content Two channels have same signature and same
content. Channel with that name belongs to a
frame.

channel-missing.dlis Frame refers to missing channel.

duplicated.dlis A frame containing two channels with the same
signatures (mnemonic, origin and copynumber)

Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions python/dlisio/dlis/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ def dtype(self, strict=True):

fmtlabel = self.dtype_fmt.format
for i, ch in enumerate(self.channels, start = 1):
if ch is None:
msg = "Channel {} not found"
raise ValueError(msg.format(self.attic['CHANNELS'].value[i-1]))
current = ((ch.fingerprint, ch.name), ch.dtype)

# first time for this label, register it as "seen before"
Expand Down
43 changes: 42 additions & 1 deletion python/tests/dlis/test_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ def test_channels_with_same_id(assert_info):
#
# T.FRAME-I.FRAME_SAME1-O.0-C.0' -> T.CHANNEL-I.SAME-O.0-C.1'
# T.FRAME-I.FRAME_SAME2-O.0-C.0' -> T.CHANNEL-I.SAME-O.0-C.2'
fpath = "data/chap4-7/eflr/frames-and-channels/2-channels-same-content-diff-copynr.dlis"
fname = "2-channels-same-content-diff-sign.dlis"
fpath = "data/chap4-7/eflr/frames-and-channels/"+fname
with dlis.load(fpath) as (f, *_):
ch1 = f.object('CHANNEL', 'SAME', 0, 1)
ch2 = f.object('CHANNEL', 'SAME', 0, 2)
Expand All @@ -365,6 +366,21 @@ def test_channel_in_multiple_frames(assert_info):
_ = ch.frame
assert_info("Channel(DUPL) belongs to multiple")

def test_channel_missing():
fpath = "data/chap4-7/eflr/frames-and-channels/channel-missing.dlis"
with dlis.load(fpath) as (f, *_):
fr = f.object("FRAME", "MAINFRAME")

with pytest.raises(ValueError) as exc:
_ = f.object("CHANNEL", "TDEP")
msg = "type=CHANNEL, name=TDEP, origin='any', copynumber='any'"
assert "Object not found: "+msg in str(exc.value)

with pytest.raises(ValueError) as exc:
_ = fr.curves()
msg = "Channel dlisio.core.obname(id='TDEP', origin=0, copynum=0) not found"
assert msg in str(exc.value)

def test_channel_duplicated_in_frame(assert_info):
fpath = "data/chap4-7/eflr/frames-and-channels/duplicated.dlis"
with dlis.load(fpath) as (f, *_):
Expand All @@ -373,6 +389,31 @@ def test_channel_duplicated_in_frame(assert_info):

assert ch.frame == fr

def test_channel_same_signature_same_content(assert_info):
fname = "2-channels-same-sign-same-content.dlis"
fpath = "data/chap4-7/eflr/frames-and-channels/"+fname
with dlis.load(fpath) as (f, *_):
fr = f.object("FRAME", "WHICH_CHANNEL")
ch = f.object("CHANNEL", "DUPL")

assert ch.frame == fr
fr.curves()

def test_channel_same_signature_diff_content(assert_info):
fname = "2-channels-same-sign-diff-content.dlis"
fpath = "data/chap4-7/eflr/frames-and-channels/"+fname
with dlis.load(fpath) as (f, *_):
fr = f.object("FRAME", "WHICH_CHANNEL")

with pytest.raises(ValueError) as exc:
_ = f.object("CHANNEL", "DUPL")
assert "Multiple CHANNEL objects with name DUPL" in str(exc.value)

with pytest.raises(ValueError) as exc:
_ = fr.curves()
msg = "Channel dlisio.core.obname(id='DUPL', origin=0, copynum=0) not found"
assert msg in str(exc.value)

def test_channel_fmt():
fpath = "data/chap4-7/eflr/frames-and-channels/various.dlis"
with dlis.load(fpath) as (f, *_):
Expand Down

0 comments on commit 5c199d1

Please sign in to comment.