{"action":"created","comment":{"url":"https://api.github.com/repos/simphony/simphony-common/pulls/comments/49177034","id":49177034,"diff_hunk":"@@ -255,5 +259,85 @@ def tearDown(self):\n             engine.close()\n \n \n+class TestMaterialsOperations(unittest.TestCase):\n+\n+    def setUp(self):\n+        self.temp_dir = tempfile.mkdtemp()\n+        self.filename = os.path.join(self.temp_dir, 'test.cuds')\n+        self.addTypeEqualityFunc(\n+            Material, partial(compare_materials, testcase=self))\n+\n+        self.expected = Materials()\n+        for i in xrange(5):\n+            self.expected.add_material(\n+                Material(description=\"Material {}\".format(i),\n+                         data=create_data_container()))\n+\n+    def tearDown(self):\n+        shutil.rmtree(self.temp_dir)\n+\n+    def file_factory(self):\n+        return H5CUDS.open(self.filename)\n+\n+    def cleanup(self):\n+        os.remove(self.filename)\n+\n+    def test_add_get_materials(self):\n+        handle = self.file_factory()\n+        expected_materials_dict = {}\n+        for material in self.expected.iter_materials():\n+            expected_materials_dict[material.uid] = material\n+\n+        handle.add_materials(self.expected)\n+\n+        # Closing and reopening the file\n+        handle.close()\n+        handle = self.file_factory()\n+\n+        stored = handle.get_materials()\n+\n+        stored_materials = [material for material in stored.iter_materials()]\n+\n+        self.assertEqual(len(expected_materials_dict), len(stored_materials))\n+        for material in stored_materials:\n+            self.assertEqual(\n+                material, expected_materials_dict[material.uid])\n+\n+        handle.close()\n+        self.cleanup()\n+\n+    def test_remove_materials(self):\n+        handle = self.file_factory()\n+        handle.add_materials(self.expected)\n+\n+        handle.remove_materials()\n+\n+        # Closing and reopening the file\n+        handle.close()\n+        handle = self.file_factory()\n+\n+        stored = handle.get_materials()\n+        stored_materials = [material for material in stored.iter_materials()]\n+\n+        # The file should not contain any materials\n+        self.assertEqual(len(stored_materials), 0)\n+\n+        handle.close()\n+        self.cleanup()\n+\n+    def test_error_when_adding_existing_materials(self):\n+        handle = self.file_factory()\n+        handle.add_materials(self.expected)\n+\n+        handle.close()\n+        handle = self.file_factory()\n+\n+        with self.assertRaises(ValueError):\n+            handle.add_materials(self.expected)\n+\n+        handle.close()\n+        self.cleanup()\n+\n+","path":"simphony/io/tests/test_h5_cuds.py","position":null,"original_position":102,"commit_id":"5c72e6c248d458529f9361a34638c9937ac29ac0","original_commit_id":"99f1b63535b9c963d0fa8fb9d1dd546b62401ab0","user":{"login":"nathanfranklin","id":8287580,"avatar_url":"https://avatars.githubusercontent.com/u/8287580?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanfranklin","html_url":"https://github.com/nathanfranklin","followers_url":"https://api.github.com/users/nathanfranklin/followers","following_url":"https://api.github.com/users/nathanfranklin/following{/other_user}","gists_url":"https://api.github.com/users/nathanfranklin/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanfranklin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanfranklin/subscriptions","organizations_url":"https://api.github.com/users/nathanfranklin/orgs","repos_url":"https://api.github.com/users/nathanfranklin/repos","events_url":"https://api.github.com/users/nathanfranklin/events{/privacy}","received_events_url":"https://api.github.com/users/nathanfranklin/received_events","type":"User","site_admin":false},"body":">Maybe there's something in the big picture that I'm missing, so follow-up comments are very much appreciated.\r\n\r\nMostly, I feel that `MaterialRelations` is a different beast than the datasets. \r\n\r\n For our datasets we defined abstract base classes (`ABCMesh`, `ABCParticles`, `ABCLattice`) and then have concrete implementations (e.g. `Particles`, `H5Particles`, `LammpsPaticles`...) that provide this \"proxy\" behavior (*\"the a CUDS container is returned as a result of a ``get`` operation in a modelling engine the returned Container is a proxy to the information stored in the internal memory if the wrapper/modelling engine.\"*).  This allows for optimizations in each of the implementations for certain situations (e.g. a mesh had millions of points but user is only accessing a few hundred of them).\r\n\r\nFor `MaterialRelations`, we don't have such defined behavior as the class represents something much smaller (~ a few dozen materials).  So creating `H5Materials` seems unneeded.\r\n\r\nMy suggestion to remove `H5Materials` is just to simplify things in the short term.  I see your point about cluttering `H5Cuds` though.  Regardless, we shouldn't spend to much time thinking about it.  If others are happy with the current approach, lets just merge :)  \r\n\r\n(if we do keep H5Materials, we need to rework the testing so that we don't repeat ourselves in the testing performed in `simphony/io/tests/test_h5_materials.py`` and 'simphony/cuds/tests/test_materials.py')","created_at":"2016-01-08T10:50:22Z","updated_at":"2016-01-08T10:50:22Z","html_url":"https://github.com/simphony/simphony-common/pull/259#discussion_r49177034","pull_request_url":"https://api.github.com/repos/simphony/simphony-common/pulls/259","_links":{"self":{"href":"https://api.github.com/repos/simphony/simphony-common/pulls/comments/49177034"},"html":{"href":"https://github.com/simphony/simphony-common/pull/259#discussion_r49177034"},"pull_request":{"href":"https://api.github.com/repos/simphony/simphony-common/pulls/259"}}},"pull_request":{"url":"https://api.github.com/repos/simphony/simphony-common/pulls/259","id":54984292,"html_url":"https://github.com/simphony/simphony-common/pull/259","diff_url":"https://github.com/simphony/simphony-common/pull/259.diff","patch_url":"https://github.com/simphony/simphony-common/pull/259.patch","issue_url":"https://api.github.com/repos/simphony/simphony-common/issues/259","number":259,"state":"open","locked":false,"title":"PR: H5_Materials (missing some documentation)","user":{"login":"tuopuu","id":8424971,"avatar_url":"https://avatars.githubusercontent.com/u/8424971?v=3","gravatar_id":"","url":"https://api.github.com/users/tuopuu","html_url":"https://github.com/tuopuu","followers_url":"https://api.github.com/users/tuopuu/followers","following_url":"https://api.github.com/users/tuopuu/following{/other_user}","gists_url":"https://api.github.com/users/tuopuu/gists{/gist_id}","starred_url":"https://api.github.com/users/tuopuu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuopuu/subscriptions","organizations_url":"https://api.github.com/users/tuopuu/orgs","repos_url":"https://api.github.com/users/tuopuu/repos","events_url":"https://api.github.com/users/tuopuu/events{/privacy}","received_events_url":"https://api.github.com/users/tuopuu/received_events","type":"User","site_admin":false},"body":"H5_Materials class for working with HDF5 backed Material data. H5CUDS has high level functions to saving and loading the whole Materials class to and from the file.","created_at":"2016-01-04T15:12:09Z","updated_at":"2016-01-08T10:50:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6888826a39cc37079152b8fe590c7934ef7def1a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/simphony/simphony-common/pulls/259/commits","review_comments_url":"https://api.github.com/repos/simphony/simphony-common/pulls/259/comments","review_comment_url":"https://api.github.com/repos/simphony/simphony-common/pulls/comments{/number}","comments_url":"https://api.github.com/repos/simphony/simphony-common/issues/259/comments","statuses_url":"https://api.github.com/repos/simphony/simphony-common/statuses/5c72e6c248d458529f9361a34638c9937ac29ac0","head":{"label":"simphony:feature_h5_materials","ref":"feature_h5_materials","sha":"5c72e6c248d458529f9361a34638c9937ac29ac0","user":{"login":"simphony","id":8048249,"avatar_url":"https://avatars.githubusercontent.com/u/8048249?v=3","gravatar_id":"","url":"https://api.github.com/users/simphony","html_url":"https://github.com/simphony","followers_url":"https://api.github.com/users/simphony/followers","following_url":"https://api.github.com/users/simphony/following{/other_user}","gists_url":"https://api.github.com/users/simphony/gists{/gist_id}","starred_url":"https://api.github.com/users/simphony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simphony/subscriptions","organizations_url":"https://api.github.com/users/simphony/orgs","repos_url":"https://api.github.com/users/simphony/repos","events_url":"https://api.github.com/users/simphony/events{/privacy}","received_events_url":"https://api.github.com/users/simphony/received_events","type":"Organization","site_admin":false},"repo":{"id":22651892,"name":"simphony-common","full_name":"simphony/simphony-common","owner":{"login":"simphony","id":8048249,"avatar_url":"https://avatars.githubusercontent.com/u/8048249?v=3","gravatar_id":"","url":"https://api.github.com/users/simphony","html_url":"https://github.com/simphony","followers_url":"https://api.github.com/users/simphony/followers","following_url":"https://api.github.com/users/simphony/following{/other_user}","gists_url":"https://api.github.com/users/simphony/gists{/gist_id}","starred_url":"https://api.github.com/users/simphony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simphony/subscriptions","organizations_url":"https://api.github.com/users/simphony/orgs","repos_url":"https://api.github.com/users/simphony/repos","events_url":"https://api.github.com/users/simphony/events{/privacy}","received_events_url":"https://api.github.com/users/simphony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/simphony/simphony-common","description":"The native implementation of the Simphony cuds objects","fork":false,"url":"https://api.github.com/repos/simphony/simphony-common","forks_url":"https://api.github.com/repos/simphony/simphony-common/forks","keys_url":"https://api.github.com/repos/simphony/simphony-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simphony/simphony-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simphony/simphony-common/teams","hooks_url":"https://api.github.com/repos/simphony/simphony-common/hooks","issue_events_url":"https://api.github.com/repos/simphony/simphony-common/issues/events{/number}","events_url":"https://api.github.com/repos/simphony/simphony-common/events","assignees_url":"https://api.github.com/repos/simphony/simphony-common/assignees{/user}","branches_url":"https://api.github.com/repos/simphony/simphony-common/branches{/branch}","tags_url":"https://api.github.com/repos/simphony/simphony-common/tags","blobs_url":"https://api.github.com/repos/simphony/simphony-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simphony/simphony-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simphony/simphony-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/simphony/simphony-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simphony/simphony-common/statuses/{sha}","languages_url":"https://api.github.com/repos/simphony/simphony-common/languages","stargazers_url":"https://api.github.com/repos/simphony/simphony-common/stargazers","contributors_url":"https://api.github.com/repos/simphony/simphony-common/contributors","subscribers_url":"https://api.github.com/repos/simphony/simphony-common/subscribers","subscription_url":"https://api.github.com/repos/simphony/simphony-common/subscription","commits_url":"https://api.github.com/repos/simphony/simphony-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/simphony/simphony-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/simphony/simphony-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/simphony/simphony-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/simphony/simphony-common/contents/{+path}","compare_url":"https://api.github.com/repos/simphony/simphony-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simphony/simphony-common/merges","archive_url":"https://api.github.com/repos/simphony/simphony-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simphony/simphony-common/downloads","issues_url":"https://api.github.com/repos/simphony/simphony-common/issues{/number}","pulls_url":"https://api.github.com/repos/simphony/simphony-common/pulls{/number}","milestones_url":"https://api.github.com/repos/simphony/simphony-common/milestones{/number}","notifications_url":"https://api.github.com/repos/simphony/simphony-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simphony/simphony-common/labels{/name}","releases_url":"https://api.github.com/repos/simphony/simphony-common/releases{/id}","created_at":"2014-08-05T17:05:12Z","updated_at":"2015-12-03T12:39:17Z","pushed_at":"2016-01-08T10:26:10Z","git_url":"git://github.com/simphony/simphony-common.git","ssh_url":"git@github.com:simphony/simphony-common.git","clone_url":"https://github.com/simphony/simphony-common.git","svn_url":"https://github.com/simphony/simphony-common","homepage":null,"size":5228,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":19,"forks":3,"open_issues":19,"watchers":6,"default_branch":"master"}},"base":{"label":"simphony:master","ref":"master","sha":"8ad05c0b5c7b7ff09ac7c4b76813e6a4e2aa2591","user":{"login":"simphony","id":8048249,"avatar_url":"https://avatars.githubusercontent.com/u/8048249?v=3","gravatar_id":"","url":"https://api.github.com/users/simphony","html_url":"https://github.com/simphony","followers_url":"https://api.github.com/users/simphony/followers","following_url":"https://api.github.com/users/simphony/following{/other_user}","gists_url":"https://api.github.com/users/simphony/gists{/gist_id}","starred_url":"https://api.github.com/users/simphony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simphony/subscriptions","organizations_url":"https://api.github.com/users/simphony/orgs","repos_url":"https://api.github.com/users/simphony/repos","events_url":"https://api.github.com/users/simphony/events{/privacy}","received_events_url":"https://api.github.com/users/simphony/received_events","type":"Organization","site_admin":false},"repo":{"id":22651892,"name":"simphony-common","full_name":"simphony/simphony-common","owner":{"login":"simphony","id":8048249,"avatar_url":"https://avatars.githubusercontent.com/u/8048249?v=3","gravatar_id":"","url":"https://api.github.com/users/simphony","html_url":"https://github.com/simphony","followers_url":"https://api.github.com/users/simphony/followers","following_url":"https://api.github.com/users/simphony/following{/other_user}","gists_url":"https://api.github.com/users/simphony/gists{/gist_id}","starred_url":"https://api.github.com/users/simphony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simphony/subscriptions","organizations_url":"https://api.github.com/users/simphony/orgs","repos_url":"https://api.github.com/users/simphony/repos","events_url":"https://api.github.com/users/simphony/events{/privacy}","received_events_url":"https://api.github.com/users/simphony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/simphony/simphony-common","description":"The native implementation of the Simphony cuds objects","fork":false,"url":"https://api.github.com/repos/simphony/simphony-common","forks_url":"https://api.github.com/repos/simphony/simphony-common/forks","keys_url":"https://api.github.com/repos/simphony/simphony-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simphony/simphony-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simphony/simphony-common/teams","hooks_url":"https://api.github.com/repos/simphony/simphony-common/hooks","issue_events_url":"https://api.github.com/repos/simphony/simphony-common/issues/events{/number}","events_url":"https://api.github.com/repos/simphony/simphony-common/events","assignees_url":"https://api.github.com/repos/simphony/simphony-common/assignees{/user}","branches_url":"https://api.github.com/repos/simphony/simphony-common/branches{/branch}","tags_url":"https://api.github.com/repos/simphony/simphony-common/tags","blobs_url":"https://api.github.com/repos/simphony/simphony-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simphony/simphony-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simphony/simphony-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/simphony/simphony-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simphony/simphony-common/statuses/{sha}","languages_url":"https://api.github.com/repos/simphony/simphony-common/languages","stargazers_url":"https://api.github.com/repos/simphony/simphony-common/stargazers","contributors_url":"https://api.github.com/repos/simphony/simphony-common/contributors","subscribers_url":"https://api.github.com/repos/simphony/simphony-common/subscribers","subscription_url":"https://api.github.com/repos/simphony/simphony-common/subscription","commits_url":"https://api.github.com/repos/simphony/simphony-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/simphony/simphony-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/simphony/simphony-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/simphony/simphony-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/simphony/simphony-common/contents/{+path}","compare_url":"https://api.github.com/repos/simphony/simphony-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simphony/simphony-common/merges","archive_url":"https://api.github.com/repos/simphony/simphony-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simphony/simphony-common/downloads","issues_url":"https://api.github.com/repos/simphony/simphony-common/issues{/number}","pulls_url":"https://api.github.com/repos/simphony/simphony-common/pulls{/number}","milestones_url":"https://api.github.com/repos/simphony/simphony-common/milestones{/number}","notifications_url":"https://api.github.com/repos/simphony/simphony-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simphony/simphony-common/labels{/name}","releases_url":"https://api.github.com/repos/simphony/simphony-common/releases{/id}","created_at":"2014-08-05T17:05:12Z","updated_at":"2015-12-03T12:39:17Z","pushed_at":"2016-01-08T10:26:10Z","git_url":"git://github.com/simphony/simphony-common.git","ssh_url":"git@github.com:simphony/simphony-common.git","clone_url":"https://github.com/simphony/simphony-common.git","svn_url":"https://github.com/simphony/simphony-common","homepage":null,"size":5228,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":19,"forks":3,"open_issues":19,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/simphony/simphony-common/pulls/259"},"html":{"href":"https://github.com/simphony/simphony-common/pull/259"},"issue":{"href":"https://api.github.com/repos/simphony/simphony-common/issues/259"},"comments":{"href":"https://api.github.com/repos/simphony/simphony-common/issues/259/comments"},"review_comments":{"href":"https://api.github.com/repos/simphony/simphony-common/pulls/259/comments"},"review_comment":{"href":"https://api.github.com/repos/simphony/simphony-common/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/simphony/simphony-common/pulls/259/commits"},"statuses":{"href":"https://api.github.com/repos/simphony/simphony-common/statuses/5c72e6c248d458529f9361a34638c9937ac29ac0"}}}}