From d25e873b0c40bb025cb2e6b27e9abb03ad1b0e08 Mon Sep 17 00:00:00 2001 From: Shikha Mishra Date: Tue, 17 Mar 2020 23:56:56 +0100 Subject: [PATCH] Report a warning for diff repcode When representation code is overwritten in object and not value a warning will be given to users.This situation occurs in actual files. Representation code is overwritten, but looks like value is not important for the users. Hence we set the value to a default one of new type. --- lib/src/parse.cpp | 3 ++- python/tests/test_logical_record.py | 34 ++++++++++++----------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/src/parse.cpp b/lib/src/parse.cpp index 80e2efddb..2041a0e11 100644 --- a/lib/src/parse.cpp +++ b/lib/src/parse.cpp @@ -934,7 +934,8 @@ object_vector parse_objects( const object_template& tmpl, const auto msg = "count ({}) isn't 0 and representation " "code ({}) changed, but value is not explicitly set"; const auto code = static_cast< int >(attr.reprc); - throw std::runtime_error(fmt::format(msg, count, code)); + user_warning(fmt::format(msg, count, code)); + attr.value = mpark::monostate{}; } patch_missing_value( attr.value, count, attr.reprc ); diff --git a/python/tests/test_logical_record.py b/python/tests/test_logical_record.py index a9b67f9d1..eb104c0ec 100644 --- a/python/tests/test_logical_record.py +++ b/python/tests/test_logical_record.py @@ -113,8 +113,6 @@ def test_absent_attribute_in_template(tmpdir, merge_files_oneLR): obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1) assert obj.attic['DEFAULT_ATTRIBUTE'] - - @pytest.mark.future_test_attributes def test_global_default_attribute(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'global-default-attribute.dlis') @@ -237,24 +235,6 @@ def test_repcode(tmpdir, merge_files_oneLR, filename_p, attr_n, attr_reprc, attr #assert attr.reprc == attr_reprc assert attr == [attr_v] - -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, *_): - with pytest.raises(RuntimeError) as excinfo: - # Load all objects - f.load() - assert "value is not explicitly set" in str(excinfo.value) - - def test_repcode_invalid_in_template_value(tmpdir, merge_files_oneLR): path = os.path.join(str(tmpdir), 'invalid-repcode.dlis') content = [ @@ -302,6 +282,20 @@ def test_repcode_invalid_in_objects(tmpdir, merge_files_oneLR): f.load() assert "unknown representation code" in str(excinfo.value) +@pytest.mark.future_warning_repcode_different_no_value +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] @pytest.mark.future_test_attributes def test_count0_novalue(tmpdir, merge_files_oneLR):