Skip to content

Commit

Permalink
Merge pull request #110 from achaikou/same_value_as_in_template
Browse files Browse the repository at this point in the history
Permit reprcode change to the same reprcode
  • Loading branch information
achaikou authored May 16, 2019
2 parents 2b70150 + 3284667 commit ae63c6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ object_vector parse_objects( const object_template& tmpl,
* certain codes (ident -> ascii), but is no need for now
*/

if (flags.reprc) {
const auto msg = "count ({}) and representation code "
"({}) changed, but value is not explicitly set";
if (flags.reprc && attr.reprc != template_attr.reprc) {
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));
}
Expand Down
1 change: 1 addition & 0 deletions python/data/parse/objattr/repeat-default-novalue.dlis.part
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.default attr units
17 changes: 17 additions & 0 deletions python/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ def test_different_repcode_no_value(tmpdir, merge):
assert "value is not explicitly set" in str(excinfo.value)


def test_same_as_default_no_value(tmpdir, merge):
path = os.path.join(str(tmpdir), 'same-as-default-but-no-value.dlis')
content = [
'data/parse/start.dlis.part',
'data/parse/template/default.dlis.part',
'data/parse/object/object.dlis.part',
'data/parse/objattr/repeat-default-novalue.dlis.part'
]
merge(path, content)

with dlisio.load(path) as f:
key = dlisio.core.fingerprint('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
obj = f.objects[key]
attr = obj.attic['DEFAULT_ATTRIBUTE']
assert attr == [-0.75, 10.0]


@pytest.mark.future_test_attributes
def test_novalue_less_count(tmpdir, merge):
path = os.path.join(str(tmpdir), 'novalue-less-count.dlis')
Expand Down

0 comments on commit ae63c6f

Please sign in to comment.