Skip to content

Commit

Permalink
Fix test, improve msg
Browse files Browse the repository at this point in the history
  • Loading branch information
rly committed Aug 8, 2024
1 parent 60ce5b3 commit 16c0d06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,9 @@ def _func(self, **kwargs):
# still need to mark self as modified
self.set_modified()
if tmp.name in d:
msg = (f"Cannot add {tmp.__class__} '{tmp.name}' to {cls} '{self.name}' in "
f"attribute '{attr_name}'. {d[tmp.name].__class__} '{tmp.name}' "
f"already exists in the attribute and has the same 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 16c0d06

Please sign in to comment.