Skip to content

Commit

Permalink
Merge branch 'dev' into stacklevel
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 authored Aug 19, 2024
2 parents be21535 + 2f339d1 commit e4c5c18
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements
- Added support to append to a dataset of references for HDMF-Zarr. @mavaylon1 [#1157](https://github.com/hdmf-dev/hdmf/pull/1157)
- Adjusted stacklevel of warnings to point to user code when possible. @rly [#1166](https://github.com/hdmf-dev/hdmf/pull/1166)
- Improved "already exists" error message when adding a container to a `MultiContainerInterface`. @rly [#1165](https://github.com/hdmf-dev/hdmf/pull/1165)

## HDMF 3.14.3 (July 29, 2024)

Expand Down
4 changes: 3 additions & 1 deletion src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,9 @@ def _func(self, **kwargs):
# still need to mark self as modified
self.set_modified()
if tmp.name in d:
msg = "'%s' already exists in %s '%s'" % (tmp.name, cls.__name__, self.name)
msg = (f"Cannot add {tmp.__class__} '{tmp.name}' at 0x{id(tmp)} to dict attribute '{attr_name}' in "
f"{cls} '{self.name}'. {d[tmp.name].__class__} '{tmp.name}' at 0x{id(d[tmp.name])} "
f"already exists in '{attr_name}' and has the same name.")
raise ValueError(msg)
d[tmp.name] = tmp
return container
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_multicontainerinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ def test_add_single_dup(self):
"""Test that adding a container to the attribute dict correctly adds the container."""
obj1 = Container('obj1')
foo = Foo(obj1)
msg = "'obj1' already exists in Foo 'Foo'"
msg = (f"Cannot add <class 'hdmf.container.Container'> 'obj1' at 0x{id(obj1)} to dict attribute "
"'containers' in <class 'tests.unit.test_multicontainerinterface.Foo'> 'Foo'. "
f"<class 'hdmf.container.Container'> 'obj1' at 0x{id(obj1)} already exists in 'containers' "
"and has the same name.")
with self.assertRaisesWith(ValueError, msg):
foo.add_container(obj1)

Expand Down

0 comments on commit e4c5c18

Please sign in to comment.