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 project data interface and add unittests for job and project data interfaces #278

Merged
merged 26 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dd172f2
Fix issue 274 with project.data.
bdice Jan 22, 2020
fe90065
Added test for numpy arrays project.data
klywang Jan 23, 2020
057101b
Inherited h5store to test_project.
klywang Jan 23, 2020
e6a2786
Diamond nest tests
klywang Jan 23, 2020
2526d4c
Merge branch 'master' into fix/project-data-interface
bdice Jan 27, 2020
af1093c
Merge branch 'master' into fix/project-data-interface
bdice Jan 29, 2020
2c9b28f
Added kwargs. Get open errors. Without open, no errors but can't take…
klywang Jan 31, 2020
d0d33a4
Merge branch 'master' into fix/project-data-interface
klywang Jan 31, 2020
a917ddf
Added project interface tests with variable.
klywang Feb 1, 2020
0b09ab0
Forgot Store in base class
klywang Feb 1, 2020
1f2d98e
Add open for other arguments.
klywang Feb 1, 2020
661296e
unittest left over.
klywang Feb 1, 2020
de77476
Corrected test inheritance.
klywang Feb 1, 2020
03624b6
Add kwargs to Project init. Tests fail otherwise.
klywang Feb 1, 2020
69762e6
h5storemanager takes arguments without explicitly opening file to pre…
klywang Feb 1, 2020
43aa19a
removed line.
klywang Feb 2, 2020
dff3b73
Undid kwargs thing.
klywang Feb 2, 2020
e49d4e8
Added arguments to open h5store
klywang Feb 9, 2020
8601639
Merge branch 'master' into fix/project-data-interface
klywang Feb 9, 2020
f35bba0
Pass failing tests. Meant to open multiple instances of H5Store object.
klywang Feb 9, 2020
2373274
Message about why tests are passed.
klywang Feb 9, 2020
e85d431
Merge remote-tracking branch 'origin/master' into fix/project-data-in…
bdice Feb 16, 2020
f043336
Update changelog.
bdice Feb 16, 2020
db798db
Update tests/test_project.py
klywang Feb 18, 2020
df26044
Update tests/test_project.py
klywang Feb 18, 2020
df20250
Merge branch 'master' into fix/project-data-interface
zhou-pj Feb 18, 2020
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
1 change: 1 addition & 0 deletions signac/contrib/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Job(object):
"The job's document filename."

KEY_DATA = 'signac_data'
"The job's datastore key."

def __init__(self, project, statepoint, _id=None):
self._project = project
Expand Down
5 changes: 4 additions & 1 deletion signac/contrib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def __init__(self, config=None, _ignore_schema_version=False):
self._fn_doc = os.path.join(self._rd, self.FN_DOCUMENT)
self._document = None

# Prepare project h5-stores
self._stores = H5StoreManager(self._rd)

# Prepare Workspace Directory
if not os.path.isdir(self._wd):
try:
Expand Down Expand Up @@ -378,7 +381,7 @@ def stores(self):
:return: The HDF5-Store manager for this project.
:rtype: :class:`~..core.h5store.H5StoreManager`
"""
return H5StoreManager(self._rd)
return self._stores

@property
def data(self):
Expand Down
50 changes: 50 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
import pickle
import string
import warnings
from tarfile import TarFile
from zipfile import ZipFile
from tempfile import TemporaryDirectory
Expand All @@ -30,6 +31,7 @@
from signac.common.config import get_config

from test_job import BaseJobTest
import test_h5store


try:
Expand All @@ -45,6 +47,11 @@
except ImportError:
H5PY = False

try:
import numpy # noqa
NUMPY = True
except ImportError:
NUMPY = False

# Skip linked view tests on Windows
WINDOWS = (sys.platform == 'win32')
Expand Down Expand Up @@ -155,6 +162,7 @@ def test_doc(self):
self.assertEqual(self.project.doc, {'a': {'b': 45}})

@unittest.skipIf(not H5PY, 'test requires the h5py package')
@unittest.skipIf(not NUMPY, 'test requires the numpy package')
def test_data(self):
with self.project.data:
self.assertFalse(self.project.data)
Expand All @@ -178,6 +186,7 @@ def test_data(self):
self.assertEqual(self.project.data, {'a': {'b': 43}})
self.project.data.a.b = 44
self.assertEqual(self.project.data, {'a': {'b': 44}})
self.project.data['c'] = numpy.zeros(10)
# This setter will overwrite the file. We leave the context manager so
# that the file is closed before overwriting it.
self.project.data = {'a': {'b': 45}}
Expand Down Expand Up @@ -2110,5 +2119,46 @@ def test_input_args(self):
tmp_project.detect_schema()


class BaseProjectStoreTest(test_h5store.BaseH5StoreTest):

project_class = signac.Project

def setUp(self):
self._tmp_dir = TemporaryDirectory(prefix='signac_')
self.addCleanup(self._tmp_dir.cleanup)
self._tmp_pr = os.path.join(self._tmp_dir.name, 'pr')
self._tmp_wd = os.path.join(self._tmp_dir.name, 'wd')
os.mkdir(self._tmp_pr)
self.config = signac.common.config.load_config()
self.project = self.project_class.init_project(
name='testing_test_project',
root=self._tmp_pr,
workspace=self._tmp_wd)

warnings.filterwarnings('ignore', category=DeprecationWarning, module='signac')

def get_h5store(self):
return self.project.data

def get_other_h5store(self):
return self.project.stores['other']


class ProjectStoreTest(BaseProjectStoreTest, test_h5store.H5StoreTest):
pass


class ProjectStoreNestedTest(BaseProjectStoreTest, test_h5store.H5StoreNestedDataTest):
pass


class ProjectStoreNestedClosedTest(BaseProjectStoreTest, test_h5store.H5StoreNestedDataClosedTest):
pass


class ProjectStorePandasTest(BaseProjectStoreTest, test_h5store.H5StorePandasDataTest):
pass


if __name__ == '__main__':
unittest.main()