Skip to content

Commit

Permalink
repositioned some warnings and resolved last merge
Browse files Browse the repository at this point in the history
- last merge introduced a double warning; resolved using @kain88-de's
  solution and applying it elsewhere
- test for warning for ResidueGroup.<resname> (FAILING)
  • Loading branch information
orbeckst committed Jun 16, 2017
1 parent f63c443 commit 75eade4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 9 additions & 12 deletions package/MDAnalysis/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,14 +1515,12 @@ def __getitem__(self, item):
#
# u.atoms['HT1'] access, otherwise default
if isinstance(item, string_types):
warnings.warn("Use of atom selection in [] operator is deprecated."
"Use `select_atoms('name {}')`".format(item))
warnings.warn("Instant selectors AtomGroup['<name>'] "
"will be removed in 1.0. "
"Use `select_atoms('name <name>')`.",
DeprecationWarning)
try:
atom = self._get_named_atom(item)
warnings.warn("Instant selectors AtomGroup['<name>'] "
"will be removed in 1.0",
DeprecationWarning)
return atom
return self._get_named_atom(item)
except (AttributeError, selection.SelectionError):
pass
return super(AtomGroup, self).__getitem__(item)
Expand All @@ -1538,13 +1536,12 @@ def __getattr__(self, attr):
# raise NDE(_ATTR_ERRORS[attr])
raise NoDataError("AtomGroup has no fragments; this requires Bonds")
elif hasattr(self.universe._topology, 'names'):
warnings.warn("Instant selectors AtomGroup.<name> "
"will be removed in 1.0",
DeprecationWarning)
# Ugly hack to make multiple __getattr__s work
try:
atom = self._get_named_atom(attr)
warnings.warn("Instant selectors AtomGroup.<name> "
"will be removed in 1.0",
DeprecationWarning)
return atom
return self._get_named_atom(attr)
except selection.SelectionError:
pass
raise AttributeError("{cls} has no attribute {attr}".format(
Expand Down
4 changes: 4 additions & 0 deletions testsuite/MDAnalysisTests/core/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,10 @@ def test_AtomGroup_warn_getattr(self):
name = self.u.atoms[0].name
assert_warns(DeprecationWarning, lambda x: getattr(self.u.atoms, x), name)

def test_ResidueGroup_warn_getattr_resname(self):
name = self.u.residues[0].resname
assert_warns(DeprecationWarning, lambda x: getattr(self.u.residues, x), name)

def test_Segment_warn_getattr_resname(self):
name = self.u.residues[0].resname
assert_warns(DeprecationWarning, lambda x: getattr(self.u.segments[0], x), name)
Expand Down

0 comments on commit 75eade4

Please sign in to comment.