Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #260 from simphony/fix-add-material
Browse files Browse the repository at this point in the history
Add check for adding existing material
  • Loading branch information
nathanfranklin committed Jan 8, 2016
2 parents 8ad05c0 + 804da97 commit 627321a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions simphony/cuds/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ def add_material(self, material):
If a material with the same uid already exists
"""
try:
if material.uid in self._materials:
raise ValueError(
"Material (uid:{}) already exists.".format(material.uid))
else:
self._materials[material.uid] = Material.from_material(material)
except KeyError:
raise ValueError

def remove_material(self, uid):
""" Remove a material
Expand Down
6 changes: 6 additions & 0 deletions simphony/cuds/tests/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def test_add_get_material(self):
self.example_materials[0].uid),
self.example_materials[0])

def test_add_existing_material(self):
self.materials.add_material(self.example_materials[0])

with self.assertRaises(ValueError):
self.materials.add_material(self.example_materials[0])

def test_get_missing_material(self):
with self.assertRaises(KeyError):
self.materials.get_material(uuid.uuid4())
Expand Down

0 comments on commit 627321a

Please sign in to comment.