Skip to content

Commit

Permalink
Merge pull request #95 from vincentschut/fix_88
Browse files Browse the repository at this point in the history
raise AttributeError in __getattr__ if lookup fails
  • Loading branch information
alimanfoo committed Dec 5, 2016
2 parents befd48d + a7b0850 commit 70f7c1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion zarr/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ def _delitem_nosync(self, item):

def __getattr__(self, item):
# allow access to group members via dot notation
return self.__getitem__(item)
try:
return self.__getitem__(item)
except KeyError:
raise AttributeError

def group_keys(self):
"""Return an iterator over member names for groups only.
Expand Down
1 change: 1 addition & 0 deletions zarr/tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def _test_decode_lossy(self, arr, decimal, **kwargs):
order=order)
assert_array_almost_equal(arr, out, decimal=decimal)


test_arrays = [
np.arange(1000, dtype='i4'),
np.linspace(1000, 1001, 1000, dtype='f8'),
Expand Down
2 changes: 2 additions & 0 deletions zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ def test_getattr(self):
# test
eq(g1['foo'], g1.foo)
eq(g2['bar'], g2.bar)
# test that hasattr returns False instead of an exception (issue #88)
assert_false(hasattr(g1, 'unexistingattribute'))

def test_group_repr(self):
g = self.create_group()
Expand Down

0 comments on commit 70f7c1d

Please sign in to comment.