Skip to content

Commit

Permalink
Improve the representation of H5Group. (#182)
Browse files Browse the repository at this point in the history
* Improve the representation of `H5Group`.

* Update changelog.

* Test repr(<H5Group>).

* Test identity of `repr(eval(repr(..)))`.

* Declare __all__ for contrib.h5store module.
  • Loading branch information
csadorf committed May 2, 2019
1 parent b35cc5c commit ee29e47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ next
- Add command line options ``--sp`` and ``--doc`` for ``signac find`` that allow users to display key-value pairs of the state point and document in combination with the job id (#97, #146).
- Fix: Searches for whole numbers will match all numerically matching integers regardless of whether they are stored as decimals or whole numbers (#169).
- Fix: Passing an instance of dict to `H5Store.setdefault()` will return an instance of `H5Group` instead of a dict (#180).
- Improve the representation (return value of `repr()`) of instances of `H5Group`.


[1.0.0] -- 2019-02-28
Expand Down
10 changes: 10 additions & 0 deletions signac/core/h5store.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from collections.abc import MutableMapping


__all__ = [
'H5Store', 'H5Group', 'H5StoreManager',
'H5StoreClosedError', 'H5StoreAlreadyOpenError',
]


def _group_is_pandas_type(group):
return 'pandas_type' in group.attrs

Expand Down Expand Up @@ -180,6 +186,10 @@ def __init__(self, store, path):
self._store = store
self._path = path

def __repr__(self):
return '{}(store={}, path={})'.format(
type(self).__name__, repr(self._store), repr(self._path))

@property
def _group(self):
return self._store.file[self._path]
Expand Down
13 changes: 11 additions & 2 deletions tests/test_h5store.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def test_set_get_explicit_nested(self):
def test_repr(self):
with self.open_h5store() as h5s:
key = 'test_repr'
self.assertEqual(repr(h5s), repr(eval(repr(h5s))))
h5s[key] = self.get_testdata()
repr(h5s) # open
repr(h5s) # closed
self.assertEqual(repr(h5s), repr(eval(repr(h5s))))

def test_str(self):
with self.open_h5store() as h5s:
Expand Down Expand Up @@ -537,6 +537,15 @@ class H5StoreNestedDataTest(H5StoreTest):
def get_testdata(self, size=None):
return dict(a=super(H5StoreNestedDataTest, self).get_testdata(size))

def test_repr(self):
from signac.core.h5store import H5Store, H5Group # noqa:F401
with self.open_h5store() as h5s:
key = 'test_repr'
self.assertEqual(repr(h5s), repr(eval(repr(h5s))))
h5s[key] = self.get_testdata()
self.assertEqual(repr(h5s[key]), repr(eval(repr(h5s[key]))))
self.assertEqual(repr(h5s), repr(eval(repr(h5s))))


class H5StoreBytesDataTest(H5StoreTest):

Expand Down

0 comments on commit ee29e47

Please sign in to comment.