Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Duplicate names in tree_namespace #128

Merged
merged 4 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion hutch_python/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def tree_namespace(scope=None):
if not hasattr(upper_space, key):
setattr(upper_space, key, IterableNamespace())
upper_space = getattr(upper_space, key)
setattr(upper_space, name, obj)
if hasattr(upper_space, name):
logger.warning(('Tried to add {} to {}, but something was '
'already there. Two devices share the same '
'name!'.format(name, upper_space)))
else:
setattr(upper_space, name, obj)
logger.debug('Created tree namespace %s', tree_space)
return tree_space
8 changes: 8 additions & 0 deletions hutch_python/tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ def test_tree_namespace():
assert mfx.dg2.obj3 == 3
assert mfx.obj4 == 4
assert xpp.sb2.obj5 == 5


def test_conflicting_name():
logger.debug('test_conflicting_name')
# This should be ok, but make sure the warning is covered
scope = SimpleNamespace(hutch_stand=SimpleNamespace(dev=1),
hutch_stand_dev=2)
tree_namespace(scope=scope)