Beispiel #1
0
def test_broken_utf8_obname_value(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'broken_utf8_obname_value.dlis')
    content = [
        'data/chap3/start.dlis.part',
        'data/chap3/template/default.dlis.part',
        'data/chap3/object/object.dlis.part',
        'data/chap3/objattr/broken-utf8-obname-value.dlis.part',
    ]
    merge_files_oneLR(path, content)
    with pytest.warns(UnicodeWarning):
        with dlisio.load(path):
            pass
    prev_encodings = dlisio.get_encodings()
    try:
        dlisio.set_encodings(['koi8_r'])
        with dlisio.load(path) as (f, *_):
            obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
            obname = (2, 2, 'КОТ')
            assert obj.attic['DEFAULT_ATTRIBUTE'] == [obname]
    finally:
        dlisio.set_encodings(prev_encodings)
Beispiel #2
0
def test_dimensions_tuple():
    fpath = 'data/chap4-7/iflr/multidimensions-validated.dlis'

    with dlisio.load(fpath) as (f, *_):
        frame = f.object('FRAME', 'FRAME-VALIDATE', 10, 0)
        curves = frame.curves()

        assert curves[0][1].size == 3

        assert curves[0][1][0] == (56, 0.0625, 0.0625)
        assert curves[0][1][1] == (43, 0.0625, 0.0625)
        assert curves[0][1][2] == (71, 0.5, 0.5)
Beispiel #3
0
def test_cut_before_object(tmpdir, merge):
    path = os.path.join(str(tmpdir), 'cut-before-object.dlis')
    content = [
        'data/parse/start.dlis.part',
        'data/parse/template/default.dlis.part',
    ]
    merge(path, content)
    with dlisio.load(path) as (f, ):
        objects = {}
        for v in f.indexedobjects.values():
            objects.update(v)
        assert len(objects) == 0
Beispiel #4
0
def test_describe(fpath):
    # Because the .describe() i.e. returns long descriptive textual string,
    # they are hard to test. But the very least test that it is callable.

    with dlisio.load(fpath) as batch:
        _ = batch.describe()

        for f in batch:
            _ = f.describe()

            for obj in f.match('.*', '.*'):
                _ = obj.describe(indent='   ', width=70, exclude='e')
def test_repcode_different_no_value(tmpdir, merge_files_oneLR):
    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 dlisio.load(path) as (f, *_):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert obj.attic['DEFAULT_ATTRIBUTE'] == [0j, 0j]
Beispiel #6
0
def test_no_object_name_bit(tmpdir, merge):
    path = os.path.join(str(tmpdir), 'no-object-name-bit.dlis')
    content = [
        'data/parse/start.dlis.part',
        'data/parse/template/default.dlis.part',
        'data/parse/object/no-name-bit.dlis.part',
    ]
    merge(path, content)

    with dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert obj.attic['DEFAULT_ATTRIBUTE']
def test_findfdata_many_in_same_VR():
    with dlisio.load('data/chap3/implicit/fdata-many-in-same-vr.dlis') as (f,
                                                                           *_):
        assert len(f.fdata_index) == 3
        assert f.fdata_index['T.FRAME-I.DLIS-FRAME-O.3-C.1'] == [0, 48]

        fingerprint = 'T.FRAME-I.-O.3-C.1'
        assert f.fdata_index[fingerprint] == [144]

        ident = '3' * 255
        fingerprint = 'T.FRAME-I.' + ident + '-O.1073741823-C.255'
        assert f.fdata_index[fingerprint] == [192]
def test_novalue_more_count(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'novalue-more-count.dlis')
    content = [
        'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part',
        'data/chap3/object/object.dlis.part',
        'data/chap3/objattr/count9-novalue.dlis.part'
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *_):
        with pytest.raises(NotImplementedError):
            f.load()
def test_linking():
    path = 'data/chap4-7/many-logical-files.dlis'
    with dlisio.load(path) as (f1, f2, _):
        frame1 = f1.object('FRAME', 'FRAME1', 10, 0)
        frame2 = f2.object('FRAME', 'FRAME1', 10, 0)
        channel = f1.object('CHANNEL', 'CHANN1', 10, 0)

        # The same frame is present in two different logical files. The
        # channels in frame.channel are only present in the first
        # logical file. Thus links are not available in the second file.
        assert channel in frame1.channels
        assert channel not in frame2.channels
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 dlisio.load(fpath) as (f, *_):
        with pytest.raises(ValueError) as exc:
            _ = f.object("CHANNEL", "MATCH1")
        assert "Candidates are" in str(exc.value)
def test_complex(create_very_broken_file, tmpdir):

    path = os.path.join(str(tmpdir), 'complex.dlis')
    create_very_broken_file(path)

    errorhandler = ErrorHandler()

    with pytest.raises(RuntimeError):
        with dlisio.load(path, error_handler=errorhandler) as (f, *_):
            pass

    # escape errors on load
    errorhandler.critical = Actions.LOG_ERROR
    with dlisio.load(path, error_handler=errorhandler) as (f, *_):

        # fail again on parsing objects not parsed on load
        errorhandler.critical = Actions.RAISE
        with pytest.raises(RuntimeError) as excinfo:
            _ = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert "object set" in str(excinfo.value)

        # escape errors on parsing
        errorhandler.critical = Actions.LOG_ERROR
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)

        errorhandler.critical = Actions.RAISE
        # set is parsed, but user should get error anyway
        with pytest.raises(RuntimeError) as excinfo:
            _ = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert "object set" in str(excinfo.value)

        # fail on attribute access
        errorhandler.critical = Actions.RAISE
        with pytest.raises(RuntimeError):
            _ = obj['INVALID']

        # retrieve whatever value from errored attribute
        errorhandler.critical = Actions.LOG_ERROR
        _ = obj['INVALID']
Beispiel #12
0
def test_curves(fpath):
    with dlisio.load(fpath) as (_, f2, _):
        key = dlisio.core.fingerprint('FRAME', 'FRAME-REPRCODE', 10, 0)
        frame = f2.objects[key]
        curves = frame.curves()

        # Read the first value of the first frame of channel CH01
        assert curves['CH01'][0][0] == 153.0
        assert curves[0]['CH01'][0] == 153.0

        # Read the first value of the second frame of channel CH01
        assert curves['CH01'][1][0] == 153.0
        assert curves[1]['CH01'][0] == 153.0
Beispiel #13
0
def test_values_one_sample(tmpdir, merge_files_oneLR, settype):
    path = os.path.join(str(tmpdir), 'values-one-sample.dlis')
    content = [
        *assemble_set(settype),
        'data/chap4-7/eflr/ndattrs/objattr/1-2.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 dlisio.load(path) as (f, *_):
        obj = f.object(settype, 'OBJECT', 10, 0)
        assert list(obj.values[0]) == [1, 2]
Beispiel #14
0
def test_set_replacement(tmpdir, merge_files_oneLR, assert_log):
    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',
        'data/chap3/objattr/all-set.dlis.part'
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *tail):
        _ = f.object('REPLACEMENT', 'OBJECT', 1, 1)
        assert_log("Replacement sets are not supported")
Beispiel #15
0
def test_dtype():
    fpath = "data/chap4-7/eflr/frames-and-channels/mainframe.dlis"
    with dlisio.load(fpath) as (f, *_):
        frame = f.object("FRAME", "MAINFRAME")

        dtype = np.dtype([
            ('FRAMENO', np.int32),
            ((frame.channels[0].fingerprint, 'TIME.0.0'), np.float32),
            ((frame.channels[1].fingerprint, 'TDEP'), np.int16, (2, )),
            ((frame.channels[2].fingerprint, 'TIME.1.0'), np.int16),
        ])

        assert frame.dtype() == dtype
Beispiel #16
0
def test_objattr_same_as_default_no_value(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'same-as-default-but-no-value.dlis')
    content = [
        'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part',
        'data/chap3/object/object.dlis.part',
        'data/chap3/objattr/repeat-default-novalue.dlis.part'
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        attr = obj.attic['DEFAULT_ATTRIBUTE'].values
        assert attr == [-0.75, 10.0]
Beispiel #17
0
def test_set_type_bit_not_set_in_set(tmpdir, merge_files_oneLR):
    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 dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert obj.attic['DEFAULT_ATTRIBUTE'].values
Beispiel #18
0
def test_label_bit_set_in_attribute(tmpdir, merge_files_oneLR):
    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 dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert obj.attic['DEFAULT_ATTRIBUTE'].values
Beispiel #19
0
def test_set_type_not_set(tmpdir, merge):
    path = os.path.join(str(tmpdir), 'incorrect_set_header.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(path, content)

    with dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert obj.attic['DEFAULT_ATTRIBUTE']
Beispiel #20
0
def test_absent_attribute_in_template(tmpdir, merge):
    path = os.path.join(str(tmpdir), 'absent-attribute-in-template.dlis')
    content = [
        'data/chap3/start.dlis.part',
        'data/chap3/template/absent.dlis.part',
        'data/chap3/template/default.dlis.part',
        'data/chap3/object/object.dlis.part',
    ]
    merge(path, content)

    with dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        assert obj.attic['DEFAULT_ATTRIBUTE']
Beispiel #21
0
def test_channel_curves():
    fpath = 'data/chap4-7/iflr/all-reprcodes.dlis'
    with dlisio.load(fpath) as (f, *_):
        channel = f.object('CHANNEL', 'CH26', 10, 0)
        curves = channel.curves()
        assert curves[0] == True

        channel = f.object('CHANNEL', 'CH22', 10, 0)
        curves22 = channel.curves()
        assert curves22[0] == 16777217

        frame_curves = load_curves(fpath)
        assert frame_curves['CH22'] == curves22
Beispiel #22
0
def test_measurement_non_corresponding_values(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir),
                        'measurement-non-corresponding-values.dlis')
    content = [
        'data/chap4-7/eflr/envelope.dlis.part',
        'data/chap4-7/eflr/ndattrs/set/calibration-measurement.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/measurement.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/maximum-deviation.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/standard-deviation.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/reference.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/plus-tolerance.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/minus-tolerance.dlis.part',
        'data/chap4-7/eflr/ndattrs/template/dimension.dlis.part',
        'data/chap4-7/eflr/ndattrs/object.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/1-2-3-4-5.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/1-2-3.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/1-2.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/2-3.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/1.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/0.5-1.5-2.5.dlis.part',
        'data/chap4-7/eflr/ndattrs/objattr/4.dlis.part',
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *_):
        m = f.object('CALIBRATION-MEASUREMENT', 'OBJECT', 10, 0)

        msg = 'cannot reshape array of size {} into shape 4'
        with pytest.raises(ValueError) as error:
            _ = m.samples
            assert error.value == msg.format(5)

        with pytest.raises(ValueError) as error:
            _ = m.max_deviation
            assert error.value == msg.format(3)

        with pytest.raises(ValueError) as error:
            _ = m.std_deviation
            assert error.value == msg.format(2)

        with pytest.raises(ValueError) as error:
            _ = m.reference
            assert error.value == msg.format(2)

        with pytest.raises(ValueError) as error:
            _ = m.plus_tolerance
            assert error.value == msg.format(1)

        with pytest.raises(ValueError) as error:
            _ = m.minus_tolerance
            assert error.value == msg.format(3)
Beispiel #23
0
def test_invariant_attribute_in_object(tmpdir, merge_files_oneLR):
    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 dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        attr = obj.attic['DEFAULT_ATTRIBUTE'].values
        assert attr == [8.0]
Beispiel #24
0
def test_unexpected_attribute_instead_of_object(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'unexpected-attr-instead-of-object.dlis')
    content = [
        'data/chap3/start.dlis.part',
        'data/chap3/template/invariant.dlis.part',
        'data/chap3/object/object.dlis.part',
        'data/chap3/objattr/empty.dlis.part',
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *_):
        with pytest.raises(ValueError) as excinfo:
            f.load()
    assert "expected OBJECT" in str(excinfo.value)
Beispiel #25
0
def test_label_bit_not_set_in_template(tmpdir, merge_files_oneLR):
    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 dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        attr = obj.attic['NEW_ATTRIBUTE'].values
        dt = datetime(2033, 4, 19, 20, 39, 58, 103000)
        assert attr == [dt]
Beispiel #26
0
def test_count0_value_bit(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'count0-value-bit.dlis')
    content = [
        'data/chap3/start.dlis.part', 'data/chap3/template/default.dlis.part',
        'data/chap3/object/object.dlis.part',
        'data/chap3/objattr/count0-value-bit.dlis.part'
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        attr = obj.attic['DEFAULT_ATTRIBUTE'].values
        #assert attr.count == 0
        assert attr == None
Beispiel #27
0
def test_repcode_invalid_in_objects(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'invalid-repcode-object.dlis')
    content = [
        'data/chap3/start.dlis.part',
        'data/chap3/template/default.dlis.part',
        'data/chap3/object/object.dlis.part',
        'data/chap3/objattr/reprcode-invalid.dlis.part',
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *_):
        with pytest.raises(RuntimeError) as excinfo:
            f.load()
    assert "unknown representation code" in str(excinfo.value)
Beispiel #28
0
def test_repcode_invalid_in_template_no_value(tmpdir, merge_files_oneLR):
    path = os.path.join(str(tmpdir), 'invalid-repcode-template.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/all-set.dlis.part',
    ]
    merge_files_oneLR(path, content)

    with dlisio.load(path) as (f, *_):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        attr = obj.attic['INVALID'].values
        assert attr == [1, 2, 3, 4]
Beispiel #29
0
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 dlisio.load(path) as (f, *tail):
        obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
        with pytest.raises(RuntimeError) as excinfo:
            _ = obj.attic['DTIME']
        assert "month must be" in str(excinfo.value)
Beispiel #30
0
def test_unknowns_multiple_sets(tmpdir_factory, merge_files_manyLR):
    # Multiple sets of the same type are loaded correctly. All objects are
    # unique.
    fpath = str(tmpdir_factory.mktemp('lf').join('two-ch-sets.dlis'))
    content = [
        'data/chap4-7/eflr/envelope.dlis.part',
        'data/chap4-7/eflr/file-header.dlis.part',
        'data/chap4-7/eflr/unknown.dlis.part',
        'data/chap4-7/eflr/unknown2.dlis.part',
    ]
    merge_files_manyLR(fpath, content)

    with dlisio.load(fpath) as (f, *_):
        assert len(f.unknowns['UNKNOWN_SET']) == 2