def test_parse_critical_escaped(tmpdir, merge_files_oneLR, assert_error): path = os.path.join(str(tmpdir), 'error-on-attribute-access.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/invalid-repcode-no-value.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/empty.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path, error_handler=errorhandler) as (f, *_): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) # value is unclear and shouldn't be trusted _ = obj['INVALID'] assert_error("invalid representation code")
def test_values_infer_dimensions_from_zones(tmpdir, merge_files_oneLR, settype): path = os.path.join(str(tmpdir), 'values-infer-dimensions-from-zones.dlis') content = [ *assemble_set(settype), 'data/chap4-7/eflr/ndattrs/objattr/1-2-3-4-5.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/empty-INT.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/zones-5.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): obj = f.object(settype, 'OBJECT', 10, 0) # Should be able to infer correct dimension from zones assert np.array_equal(obj.values, np.array([1, 2, 3, 4, 5]))
def test_unexpected_set_in_template(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'unexpected-set-in-template.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/set/second-set.dlis.part', 'data/chap3/template/invariant.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): with pytest.raises(RuntimeError) as excinfo: f.load() assert "expected ATTRIB" in str(excinfo.value)
def test_repcode_invalid_datetime(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'invalid_dtime.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/repcode/invalid-dtime.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) with pytest.raises(ValueError) as excinfo: _ = obj.attic['DTIME'].value assert "month must be in 1..12" in str(excinfo.value)
def test_label_bit_not_set_in_template(tmpdir, merge_files_oneLR, assert_log): path = os.path.join(str(tmpdir), 'label-bit-not-set-in-template.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/label-bit-not-set.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic['NEW_ATTRIBUTE'] dt = datetime(2033, 4, 19, 20, 39, 58, 103000) assert attr.value == [dt] assert_log("Label not set in template")
def test_count0_different_repcode(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'count0-different-repcode.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/count0-different-repcode.dlis.part' ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic['DEFAULT_ATTRIBUTE'] #assert attr.count == 0 #assert attr.reprc == dlisio.core.reprc.units assert attr.value == None
def test_object_many_objects_nameonly(tmpdir_factory, merge_files_manyLR): fpath = str(tmpdir_factory.mktemp('lf').join('same-id.dlis')) content = [ 'data/chap4-7/eflr/envelope.dlis.part', 'data/chap4-7/eflr/file-header.dlis.part', 'data/chap4-7/eflr/match/T.CHANNEL-I.MATCH1-O.16-C.0.dlis.part', 'data/chap4-7/eflr/match/T.CHANNEL-I.MATCH1-O.127-C.0.dlis.part', ] merge_files_manyLR(fpath, content) with dlis.load(fpath) as (f, *_): with pytest.raises(ValueError) as exc: _ = f.object("CHANNEL", "MATCH1") assert "Candidates are" in str(exc.value) assert "origin=16, copy=0" in str(exc.value) assert "origin=127, copy=0" in str(exc.value)
def test_repcode(tmpdir, merge_files_oneLR, filename_p, attr_n, attr_reprc, attr_v): path = os.path.join(str(tmpdir), filename_p + '.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/repcode/' + filename_p + '.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic[attr_n] #assert attr.reprc == attr_reprc assert attr.value == [attr_v]
def test_values_multidim_values(tmpdir, merge_files_oneLR, settype): path = os.path.join(str(tmpdir), 'values-multidim-values.dlis') content = [ *assemble_set(settype), 'data/chap4-7/eflr/ndattrs/objattr/1-2-3-4-5-6-7-8-9-10-11-12.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/2-3.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/empty-OBNAME.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): obj = f.object(settype, 'OBJECT', 10, 0) assert list(obj.values[0][1]) == [3, 4] assert list(obj.values[1][2]) == [11, 12] assert obj.dimension == [3, 2]
def test_values_right_dimensions_right_zones(tmpdir, merge_files_oneLR, settype): path = os.path.join(str(tmpdir), 'values-right-dimensions-right-zones.dlis') content = [ *assemble_set(settype), 'data/chap4-7/eflr/ndattrs/objattr/1-2-3-4.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/2.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/zones-2.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): obj = f.object(settype, 'OBJECT', 10, 0) assert np.array_equal(obj.values, np.array([[1, 2], [3, 4]]))
def test_values_empty_dimension_provided(tmpdir, merge_files_oneLR, settype): path = os.path.join(str(tmpdir), 'values-empty-dimension-provided.dlis') content = [ *assemble_set(settype), 'data/chap4-7/eflr/ndattrs/objattr/empty-INT.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/1.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/empty-OBNAME.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): obj = f.object(settype, 'OBJECT', 10, 0) assert np.array_equal(obj.values, np.empty(0)) assert obj.dimension == [1] assert obj.axis == [] assert obj.zones == []
def test_channel_without_frame(assert_info, tmpdir_factory, merge_files_manyLR): fpath = str(tmpdir_factory.mktemp('curves').join('no-frame.dlis')) content = [ 'data/chap4-7/eflr/envelope.dlis.part', 'data/chap4-7/eflr/file-header.dlis.part', 'data/chap4-7/eflr/channel.dlis.part', ] merge_files_manyLR(fpath, content) with dlis.load(fpath) as (f, *_): channel = f.object("CHANNEL", "CHANN1") assert channel.curves() == None assert_info('no recorded curve-data') assert channel.frame == None assert_info('does not belong')
def test_absent_attribute(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'attribute_absent.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/invariant.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/absent.dlis.part' ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) assert obj.attic['INVARIANT_ATTRIBUTE'].value with pytest.raises(KeyError): _ = obj.attic['DEFAULT_ATTRIBUTE']
def test_object_name_bit_not_set_in_object(tmpdir, merge_files_oneLR, assert_log): path = os.path.join(str(tmpdir), 'no-object-name-bit.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/no-name-bit.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) assert obj.attic['DEFAULT_ATTRIBUTE'].value _ = obj['DEFAULT_ATTRIBUTE'] assert_log("Problem: OBJECT:name was not set\n" "Where: T.VERY_MUCH_TESTY_SET-I.OBJECT-O.1-C.1")
def test_label_bit_set_in_attribute(tmpdir, merge_files_oneLR, assert_log): path = os.path.join(str(tmpdir), 'label_bit_set_in_attribute.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/label-bit-set.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) assert obj.attic['DEFAULT_ATTRIBUTE'].value _ = obj['DEFAULT_ATTRIBUTE'] assert_log("Label bit")
def test_set_type_bit_not_set_in_set(tmpdir, merge_files_oneLR, assert_log): path = os.path.join(str(tmpdir), 'set-type-not-set.dlis') content = [ 'data/chap3/sul.dlis.part', 'data/chap3/set/no-type-flag.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) assert obj.attic['DEFAULT_ATTRIBUTE'].value assert_log("Problem: SET:type not set\n" "Where: object set of type 'VERY_MUCH_TESTY_SET' " "named ''")
def test_repcode_different_no_value(tmpdir, merge_files_oneLR, assert_log, assert_info): path = os.path.join(str(tmpdir), 'different-repcode-no-value.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/csingle-novalue.dlis.part' ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj['DEFAULT_ATTRIBUTE'] assert attr == [0j, 0j] assert_log("value is not explicitly set")
def test_invariant_attribute(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'invariant_attribute.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/invariant.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic['INVARIANT_ATTRIBUTE'] #assert attr.count == 3 #assert attr.reprc == dlisio.core.reprc.status assert attr.units == 'invariant units' assert attr.value == [False, False, True]
def test_all_attribute_bits(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'global-all-attribute-bits.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/all-set.dlis.part' ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic['DEFAULT_ATTRIBUTE'] #assert attr.count == 4 #assert attr.reprc == dlisio.core.reprc.ushort assert attr.units == 'overwritten units' assert attr.value == [1, 2, 3, 4]
def test_parse_major_errored(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'replacement-set.dlis') content = [ 'data/chap3/sul.dlis.part', 'data/chap3/set/replacement.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part' ] merge_files_oneLR(path, content) errorhandler = ErrorHandler( major=Actions.RAISE) with dlis.load(path, error_handler=errorhandler) as (f, *_): with pytest.raises(RuntimeError) as excinfo: _ = f.object('REPLACEMENT', 'OBJECT', 1, 1) assert "Replacement sets are not supported" in str(excinfo.value)
def test_default_attribute(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'default_attribute.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/empty.dlis.part' ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic['DEFAULT_ATTRIBUTE'] #assert attr.count == 2 #assert attr.reprc == dlisio.core.reprc.fdoubl assert attr.units == 'default attr units' assert attr.value == [-0.75, 10.0]
def test_set_redundant(tmpdir, merge_files_oneLR, assert_info, assert_message_count): path = os.path.join(str(tmpdir), 'redundant-set.dlis') content = [ 'data/chap3/sul.dlis.part', 'data/chap3/set/redundant.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/all-set.dlis.part' ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): msg = "Redundant sets are not supported" assert_message_count(msg, 0) _ = f.object('REDUNDANT', 'OBJECT', 1, 1) assert_info(msg) assert_message_count(msg, 1)
def test_invariant_attribute_in_object(tmpdir, merge_files_oneLR, assert_log): path = os.path.join(str(tmpdir), 'invariant-attribute-in-object.dlis') content = [ 'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', 'data/chap3/objattr/invariant.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *tail): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) attr = obj.attic['DEFAULT_ATTRIBUTE'] assert attr.value == [8.0] _ = obj['DEFAULT_ATTRIBUTE'] assert_log("Invariant attribute")
def test_set_name_bit_set_name_not_present(tmpdir, merge_files_oneLR, assert_log): # based on frequent situation for FILE-HEADER sets path = os.path.join(str(tmpdir), 'name-bit-set-name-not-present.dlis') content = [ 'data/chap3/sul.dlis.part', 'data/chap3/set/name-bit-set-no-name.dlis.part', 'data/chap3/template/default.dlis.part', 'data/chap3/object/object.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): with pytest.raises(RuntimeError) as excinfo: _ = f.object('FILE-HEADER', 'N', 2, 0) err = "object set of type 'FILE-HEADER' named 'SEQUENCE-NUMBER4ID" assert err in str(excinfo.value)
def test_dtype_fmt_class(): original = dlis.Frame.dtype_format try: # change dtype before the object itself is constructed, so it dlis.Frame.dtype_format = 'x-{:s} {:d}~{:d}' fpath = "data/chap4-7/eflr/frames-and-channels/mainframe.dlis" with dlis.load(fpath) as (f, *_): frame = f.object("FRAME", "MAINFRAME") expected_names = ('FRAMENO', 'x-TIME 0~0', 'TDEP', 'x-TIME 1~0') assert expected_names == frame.dtype().names assert 'ifDDD' == frame.fmtstr() finally: # even if the test fails, make sure the format string is reset to its # default, to not interfere with other tests dlis.Frame.dtype_format = original
def test_duplicated_mnemonics_get_unique_labels(): fpath = "data/chap4-7/eflr/frames-and-channels/mainframe.dlis" with dlis.load(fpath) as (f, *_): frame = f.object("FRAME", "MAINFRAME") assert 'ifDDD' == frame.fmtstr() dtype = frame.dtype() assert ('FRAMENO', 'TIME.0.0', 'TDEP', 'TIME.1.0') == dtype.names fields = [ 'FRAMENO', frame.channels[0].fingerprint, frame.channels[1].fingerprint, frame.channels[2].fingerprint, ] assert all(x in dtype.fields for x in fields)
def test_dimensions(): fpath = 'data/chap4-7/iflr/multidimensions-ints-various.dlis' with dlis.load(fpath) as (f, *_): frame = f.object('FRAME', 'FRAME-DIMENSION', 11, 0) curves = frame.curves() np.testing.assert_array_equal(curves[0][1], [[1, 2, 3], [4, 5, 6]]) np.testing.assert_array_equal(curves[0][2], [[1, 2], [3, 4], [5, 6]]) arr2 = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]], [[13, 14], [15, 16], [17, 18]], [[19, 20], [21, 22], [23, 24]]] np.testing.assert_array_equal(curves[0][3], arr2) np.testing.assert_array_equal(curves[0][4], [[1, 2]]) np.testing.assert_array_equal(curves[0][5], [[1], [2]]) np.testing.assert_array_equal(curves[0][6], [[1]]) np.testing.assert_array_equal(curves[0][7], [1, 2, 3, 4])
def test_values_wrong_dimensions(tmpdir, merge_files_oneLR, settype): path = os.path.join(str(tmpdir), 'values-wrong-dimensions.dlis') content = [ *assemble_set(settype), 'data/chap4-7/eflr/ndattrs/objattr/1-2-3-4-5.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/2.dlis.part', 'data/chap4-7/eflr/ndattrs/objattr/empty-OBNAME.dlis.part', ] merge_files_oneLR(path, content) with dlis.load(path) as (f, *_): obj = f.object(settype, 'OBJECT', 10, 0) msg = 'cannot reshape array of size 5 into shape [2]' with pytest.raises(ValueError) as error: _ = obj.values assert str(error.value) == msg assert np.array_equal(obj.attic['VALUES'].value, np.array([1, 2, 3, 4, 5]))
def test_duplicated_mnemonics_dtype_supports_buffer_protocol(): # Getting a buffer from a numpy array adds a :name: field after the label # name, and forbids the presence of :. Unfortunately, the full visible # (non-whitespace) ascii set is legal for the RP66 IDENT type, so in theory # it's possible that a similar mnemonic can be legally present. # # In practice, this is unlikely to be a problem. By default, dlisio uses # the full stop (.) as a separator, but for particularly nasty files this # would collide with a different channel mnemonic in the same frame. A # possible fix could be to use a blank character for mnemonic-origin-copy # separation, or lowercase letters (which are not supposed to be a part of # the IDENT type, but dlisio imposes no such restriction) # # https://github.com/equinor/dlisio/pull/97 fpath = "data/chap4-7/eflr/frames-and-channels/mainframe.dlis" with dlis.load(fpath) as (f, *_): frame = f.object("FRAME", "MAINFRAME") _ = memoryview(np.zeros(1, dtype=frame.dtype()))
def test_object_ducplicated_object(tmpdir_factory, merge_files_manyLR): # Spec violation: Two objects with the same signature AND identical content fpath = str(tmpdir_factory.mktemp('lf').join('same-id.dlis')) content = [ 'data/chap4-7/eflr/envelope.dlis.part', 'data/chap4-7/eflr/file-header.dlis.part', 'data/chap4-7/eflr/match/T.CHANNEL-I.MATCH1-O.127-C.0.dlis.part', 'data/chap4-7/eflr/match/T.CHANNEL-I.MATCH1-O.127-C.0.dlis.part', ] merge_files_manyLR(fpath, content) with dlis.load(fpath) as (f, *_): ch = f.object("CHANNEL", "MATCH1") assert ch.name == "MATCH1" assert ch.origin == 127 assert ch.copynumber == 0 assert ch == f.object("CHANNEL", "MATCH1", 127, 0)