diff --git a/simphony/cuds/abc_lattice.py b/simphony/cuds/abc_lattice.py index 79b60428..83a59ba9 100644 --- a/simphony/cuds/abc_lattice.py +++ b/simphony/cuds/abc_lattice.py @@ -2,7 +2,6 @@ from ..core import CUBA from .abc_dataset import ABCDataset -from .utils import deprecated class ABCLattice(ABCDataset): @@ -137,62 +136,6 @@ def __len__(self): """ return self.count_of(CUBA.NODE) - @deprecated - def get_node(self, index): # pragma: no cover - """ - Deprecated. Use get() instead. - - Get the lattice node corresponding to the given index. - - Parameters - ---------- - index : int[3] - node index coordinate - - Returns - ------- - node : LatticeNode - - """ - return self.get(index) - - @deprecated - def update_nodes(self, nodes): # pragma: no cover - """ - Deprecated. Use update() instead. - - Update the corresponding lattice nodes. - - Parameters - ---------- - nodes : iterator of LatticeNodes - - """ - self.update(nodes) - - @deprecated - def iter_nodes(self, indices=None): # pragma: no cover - """ - Deprecated. Use iter() instead. - - Get an iterator over the LatticeNodes described by the indices. - - Parameters - ---------- - indices : iterable set of int[3], optional - When indices (i.e. node index coordinates) are provided, then nodes - are returned in the same order of the provided indices. If indices - is None, there is no restriction on the order of the returned - nodes. - - Returns - ------- - iterator: - An iterator over LatticeNode objects - - """ - return self.iter(indices) - @property def primitive_cell(self): return self._primitive_cell diff --git a/simphony/cuds/abc_mesh.py b/simphony/cuds/abc_mesh.py index 1c097a6f..cd93d18a 100644 --- a/simphony/cuds/abc_mesh.py +++ b/simphony/cuds/abc_mesh.py @@ -3,7 +3,6 @@ from ..core import CUBA from .abc_dataset import ABCDataset -from .utils import deprecated from .mesh_items import Point, Edge, Face, Cell @@ -256,434 +255,6 @@ def __len__(self): [CUBA.POINT, CUBA.EDGE, CUBA.FACE, CUBA.CELL])) - # Deprecated methods. - - @deprecated - def get_point(self, uid): # pragma: no cover - """ - Deprecated. Use get() instead. - - Returns a point with a given uid. - - Returns the point stored in the mesh - identified by uid. If such point do not - exists an exception is raised. - - Parameters - ---------- - uid : uuid.UUID - uid of the desired point. - - Returns - ------- - point : Point - Mesh point identified by uuid - - Raises - ------ - KeyError : - If the point identified by uid was not found - TypeError : - When ``uid`` is not uuid.UUID - - """ - return self.get(uid) - - @deprecated - def get_edge(self, uid): # pragma: no cover - """ Returns an edge with a given uid. - - Returns the edge stored in the mesh - identified by uid. If such edge do not - exists an exception is raised. - - Parameters - ---------- - uid : uuid.UUID - uid of the desired edge. - - Returns - ------- - edge : Edge - Edge identified by uid - - Raises - ------ - KeyError : - If the edge identified by uid was not found - TypeError : - When ``uid`` is not uuid.UUID - - """ - return self.get(uid) - - @deprecated - def get_face(self, uid): # pragma: no cover - """ - Deprecated. Use get() instead. - - Returns a face with a given uid. - - Returns the face stored in the mesh - identified by uid. If such a face does - not exists an exception is raised. - - Parameters - ---------- - uid : uuid.UUID - uid of the desired face. - - Returns - ------- - face : Face - Face identified by uid - - Raises - ------ - KeyError : - If the face identified by uid was not found - TypeError : - When ``uid`` is not uuid.UUID - """ - return self.get(uid) - - @deprecated - def get_cell(self, uid): # pragma: no cover - """ - Deprecated. Use get() instead. - - Returns a cell with a given uid. - - Returns the cell stored in the mesh - identified by uid. If such a cell does not - exists an exception is raised. - - Parameters - ---------- - uid : uuid.UUID - uid of the desired cell. - - Returns - ------- - cell : Cell - Cell identified by uid - - Raises - ------ - KeyError : - If the cell identified by uuid was not found - TypeError : - When ``uid`` is not uuid.UUID - """ - return self.get(uid) - - @deprecated - def add_points(self, points): # pragma: no cover - """ - Deprecated. use add() instead. - - Adds a set of new points to the mesh. - - Parameters - ---------- - points : iterable of Point - Points to be added to the mesh - - Raises - ------ - ValueError : - If other point with a duplicated uid was already - in the mesh. - """ - return self.add(points) - - @deprecated - def add_edges(self, edges): - """ - Deprecated. Use add() instead. - - Adds a set of new edges to the mesh. - - Parameters - ---------- - edges : iterable of Edge - Edge to be added to the mesh - - Raises - ------ - ValueError : - If other edge with a duplicated uid was already - in the mesh - """ - return self.add(edges) - - @deprecated - def add_faces(self, faces): # pragma: no cover - """ - Deprecated. Use add() instead. - - Adds a set of new faces to the mesh. - - Parameters - ---------- - faces : iterable of Face - Face to be added to the mesh - - Raises - ------ - ValueError : - If other face with a duplicated uid was already - in the mesh - """ - return self.add(faces) - - @deprecated - def add_cells(self, cells): # pragma: no cover - """ - Deprecated. Use add() instead. - - Adds a set of new cells to the mesh. - - Parameters - ---------- - cells : iterable of Cell - Cell to be added to the mesh - - Raises - ------ - ValueError : - If other cell with a duplicated uid was already - in the mesh - """ - return self.add(cells) - - @deprecated - def update_points(self, points): # pragma: no cover - """ - Deprecated. Use update() instead. - - Updates the information of a set of points. - - Gets the mesh point identified by the same - uid as the provided point and updates its information - with the one provided with the new point. - - Parameters - ---------- - points : iterable of Point - Point to be updated - - Raises - ------ - ValueError : - If the any point was not found in the mesh - """ - self.update(points) - - @deprecated - def update_edges(self, edges): # pragma: no cover - """ - Deprecated. Use update() instead. - - Updates the information of a set of edges. - - Gets the mesh edge identified by the same - uid as the provided edge and updates its information - with the one provided with the new edge. - - Parameters - ---------- - edges : iterable of Edge - Edge to be updated - - Raises - ------ - ValueError : - If the any edge was not found in the mesh - """ - self.update(edges) - - @deprecated - def update_faces(self, faces): # pragma: no cover - """ - Deprecated. Use update() instead. - - Updates the information of a set of faces. - - Gets the mesh face identified by the same - uid as the provided face and updates its information - with the one provided with the new face. - - Parameters - ---------- - faces : iterable of Face - Face to be updated - - Raises - ------ - ValueError : - If the any face was not found in the mesh - """ - self.update(faces) - - @deprecated - def update_cells(self, cells): # pragma: no cover - """ - Deprecated. Use update() instead. - - Updates the information of a set of cells. - - Gets the mesh cell identified by the same - uid as the provided cell and updates its information - with the one provided with the new cell. - - Parameters - ---------- - cells : iterable of Cell - Cell to be updated - - Raises - ------ - ValueError : - If the any cell was not found in the mesh - """ - self.update(cells) - - @deprecated - def iter_points(self, uids=None): # pragma: no cover - """ - Deprecated. Use iter() instead. - - Returns an iterator over points. - - Parameters - ---------- - uids : iterable of uuid.UUID or None - When the uids are provided, then the points are returned in the - same order the uids are returned by the iterable. If uids is None, - then all points are returned by the iterable and there is no - restriction on the order that they are returned. - - Yields - ------ - point : Point - """ - return self.iter(uids, CUBA.POINT) - - @deprecated - def iter_edges(self, uids=None): # pragma: no cover - """ - Deprecated. Use iter() instead. - - Returns an iterator over edges. - - Parameters - ---------- - uids : iterable of uuid.UUID or None - When the uids are provided, then the edges are returned in the same - order the uids are returned by the iterable. If uids is None, then - all edges are returned by the iterable and there is no restriction - on the order that they are returned. - - Yields - ------ - edge : Edge - - """ - return self.iter(uids, CUBA.EDGE) - - @deprecated - def iter_faces(self, uids=None): # pragma: no cover - """ - Deprecated. Use iter() instead. - - Returns an iterator over faces. - - Parameters - ---------- - uids : iterable of uuid.UUID or None - When the uids are provided, then the faces are returned in the same - order the uids are returned by the iterable. If uids is None, then - all faces are returned by the iterable and there is no restriction - on the order that they are returned. - - Yields - ------ - face : Face - - """ - return self.iter(uids, item_type=CUBA.FACE) - - @deprecated - def iter_cells(self, uids=None): # pragma: no cover - """ - Deprecated. Use iter() instead. - - Returns an iterator over cells. - - Parameters - ---------- - uids : iterable of uuid.UUID or None - When the uids are provided, then the cells are returned in the same - order the uids are returned by the iterable. If uids is None, then - all cells are returned by the iterable and there is no restriction - on the order that they are returned. - - Yields - ------ - cell : Cell - - """ - return self.iter(uids, item_type=CUBA.CELL) - - @deprecated - def has_points(self): # pragma: no cover - """ Check if the mesh has points - - Returns - ------- - result : bool - True of there are points inside the mesh, - False otherwise - """ - return self.has_type(CUBA.POINT) - - @deprecated - def has_edges(self): # pragma: no cover - """ Check if the mesh has edges - - Returns - ------- - result : bool - True of there are edges inside the mesh, - False otherwise - """ - return self.has_type(CUBA.EDGE) - - @deprecated - def has_faces(self): # pragma: no cover - """ Check if the mesh has faces - - Returns - ------- - result : bool - True of there are faces inside the mesh, - False otherwise - """ - return self.has_type(CUBA.FACE) - - @deprecated - def has_cells(self): # pragma: no cover - """ Check if the mesh has cells - - Returns - ------- - result : bool - True of there are cells inside the mesh, - False otherwise - """ - return self.has_type(CUBA.CELL) - # Private. Need to be reimplemented by subclasses # # These methods documented behavior is as the deprecated diff --git a/simphony/cuds/abc_particles.py b/simphony/cuds/abc_particles.py index 59768bf2..03e80b94 100644 --- a/simphony/cuds/abc_particles.py +++ b/simphony/cuds/abc_particles.py @@ -5,7 +5,6 @@ from ..core import CUBA from .particles_items import Particle, Bond from .abc_dataset import ABCDataset -from .utils import deprecated class ABCParticles(ABCDataset): @@ -272,375 +271,6 @@ def __len__(self): return sum(map(lambda x: self.count_of(x), [CUBA.PARTICLE, CUBA.BOND])) - # Deprecated API. Will go away. Uses the generic API instead of direct - # call to the internal methods to guarantee the behavior is unchanged - # through the generic interface. - - @deprecated - def add_particles(self, iterable): # pragma: no cover - """ - Deprecated. Use add() instead. - - Adds a set of particles from the provided iterable - to the container. - - If any particle have no uids, the container - will generate a new uids for it. If the particle has - already an uids, it won't add the particle if a particle - with the same uid already exists. If the user wants to replace - an existing particle in the container there is an 'update_particles' - method for that purpose. - - Parameters - ---------- - iterable : iterable of Particle objects - the new set of particles that will be included in the container. - - Returns - ------- - uids : list of uuid.UUID - The uids of the added particles. - - Raises - ------ - ValueError : - when there is a particle with an uids that already exists - in the container. - - Examples - -------- - Add a set of particles to a Particles container. - - >>> particle_list = [Particle(), Particle()] - >>> particles = Particles(name="foo") - >>> uids = particles.add_particles(particle_list) - - """ - return self.add(iterable) - - @deprecated - def add_bonds(self, iterable): # pragma: no cover - """ - Deprecated. Use add() instead. - - Adds a set of bonds to the container. - - Also like with particles, if any bond has a defined uid, - it won't add the bond if a bond with the same uid already exists, and - if the bond has no uid the particle container will generate an - uid. If the user wants to replace an existing bond in the - container there is an 'update_bonds' method for that purpose. - - Parameters - ---------- - iterable : iterable of Bond objects - the new bond that will be included in the container. - - Returns - ------- - uuid : list of uuid.UUID - The uuids of the added bonds. - - Raises - ------ - ValueError : - when there is a bond with an uuid that already exists - in the container. - - Examples - -------- - Add a set of bonds to a Particles container. - - >>> bonds_list = [Bond(), Bond()] - >>> particles = Particles(name="foo") - >>> particles.add_bonds(bonds_list) - - """ - return self.add(iterable) - - @deprecated - def update_particles(self, iterable): # pragma: no cover - """ - Deprecated. use update() instead. - - Updates a set of particles from the provided iterable. - - Takes the uids of the particles and searches inside the container for - those particles. If the particles exists, they are replaced in the - container. If any particle doesn't exist, it will raise an exception. - - Parameters - ---------- - - iterable : iterable of Particle objects - the particles that will be replaced. - - Raises - ------ - ValueError : - If any particle inside the iterable does not exist. - - Examples - -------- - Given a set of Particle objects that already exists in the container - (taken with the 'get_particle' method for example), just call the - function passing the Particle items as parameter. - - >>> part_container = Particles(name="foo") - >>> ... #do whatever you want with the particles - >>> part_container.update_particles([part1, part2]) - - """ - self.update(iterable) - - @deprecated - def update_bonds(self, iterable): # pragma: no cover - """Deprecated. use update() instead. - - Updates a set of bonds from the provided iterable. - - Takes the uids of the bonds and searches inside the container for - those bond. If the bonds exists, they are replaced in the container. - If any bond doesn't exist, it will raise an exception. - - Parameters - ---------- - iterable : iterable of Bond objects - the bonds that will be replaced. - - Raises - ------ - ValueError : - If any bond doesn't exist. - - Examples - -------- - Given a set of Bond objects that already exists in the container - (taken with the 'get_bond' method for example) just call the - function passing the set of Bond as parameter. - - >>> particles = Particles(name="foo") - >>> ... - >>> bond1 = particles.get_bond(uid1) - >>> bond2 = particles.get_bond(uid2) - >>> ... #do whatever you want with the bonds - >>> particles.update_bonds([bond1, bond2]) - """ - self.update(iterable) - - @deprecated - def get_particle(self, uid): # pragma: no cover - """ - Deprecated. use get() instead. - - Returns a copy of the particle with the 'particle_id' id. - - Parameters - ---------- - - uid : uuid.UUID - the uid of the particle - - Raises - ------ - KeyError : - when the particle is not in the container. - - Returns - ------- - particle : Particle - A copy of the internally stored particle info. - """ - return self.get(uid) - - @deprecated - def get_bond(self, uid): # pragma: no cover - """ - Deprecated. Use uid instead. - - Returns a copy of the bond with the 'bond_id' id. - - Parameters - ---------- - uid : uuid.UUID - the uid of the bond - - Raises - ------ - KeyError : - when the bond is not in the container. - - Returns - ------- - bond : Bond - A copy of the internally stored bond info. - """ - return self.get(uid) - - @deprecated - def remove_particles(self, uids): # pragma: no cover - """ - Deprecated. use remove() instead. - - Remove the particles with the provided uids from the container. - - The uids inside the iterable should exists in the container. Otherwise - an exception will be raised. - - Parameters - ---------- - uids : iterable of uuid.UUID - the uids of the particles to be removed. - - Raises - ------ - KeyError : - If any particle doesn't exist. - - Examples - -------- - Having a set of uids of existing particles, pass it to the method. - - >>> particles = Particles(name="foo") - >>> ... - >>> particles.remove_particles([uid1, uid2]) - """ - self.remove(uids) - - @deprecated - def remove_bonds(self, uids): # pragma: no cover - """ - Deprecated. use remove() instead. - - Remove the bonds with the provided uids. - - The uids passed as parameter should exists in the container. If - any uid doesn't exist, an exception will be raised. - - Parameters - ---------- - uids : iterable of uuid.UUID - the uids of the bond to be removed. - - Raises - ------ - KeyError : - If any bond doesn't exist. - - Examples - -------- - Having a set of uids of existing bonds, pass it to the method. - - >>> particles = Particles(name="foo") - >>> ... - >>> particles.remove_bonds([uid1, uid2]) - """ - self.remove(uids) - - @deprecated - def iter_particles(self, uids=None): # pragma: no cover - """ - Deprecated. use iter() instead. - - Generator method for iterating over the particles of the container. - - It can receive any kind of sequence of particle uids to iterate over - those concrete particles. If nothing is passed as parameter, it will - iterate over all the particles. - - Parameters - ---------- - uids : iterable of uuid.UUID, optional - sequence containing the uids of the particles that will be - iterated. When the uids are provided, then the particles are - returned in the same order the uids are returned by the iterable. - If uids is None, then all particles are returned by the iterable - and there is no restriction on the order that they are returned. - - Yields - ------ - particle : Particle - The Particle item. - - Raises - ------ - KeyError : - if any of the ids passed as parameters are not in the container. - - Examples - -------- - It can be used with a sequence as parameter or without it: - - >>> particles = Particles(name="foo") - >>> ... - >>> for particle in particles.iter_particles([uid1, uid2, uid3]): - ... #do stuff - >>> for particle in particles.iter_particles(): - ... #do stuff - """ - return self.iter(uids, item_type=CUBA.PARTICLE) - - @deprecated - def iter_bonds(self, uids=None): # pragma: no cover - """ - Deprecated. use iter() instead. - - Generator method for iterating over the bonds of the container. - - It can receive any kind of sequence of bond ids to iterate over - those concrete bond. If nothing is passed as parameter, it will - iterate over all the bonds. - - Parameters - ---------- - - uids : iterable of uuid.UUID, optional - sequence containing the id's of the bond that will be iterated. - When the uids are provided, then the bonds are returned in - the same order the uids are returned by the iterable. If uids is - None, then all bonds are returned by the iterable and there - is no restriction on the order that they are returned. - - Yields - ------ - bond : Bond - The next Bond item - - Raises - ------ - KeyError : - if any of the ids passed as parameters are not in the container. - - Examples - -------- - It can be used with a sequence as parameter or without it: - - >>> particles = Particles(name="foo") - >>> ... - >>> for bond in particles.iter_bonds([id1, id2, id3]): - ... #do stuff - - >>> for bond in particles.iter_bond(): - ... #do stuff; it will iterate over all the bond - """ - return self.iter(uids, item_type=CUBA.BOND) - - @deprecated - def has_particle(self, uid): # pragma: no cover - """Deprecated. use has() instead. - - Checks if a particle with the given uid already exists - in the container.""" - return self.has(uid) - - @deprecated - def has_bond(self, uid): # pragma: no cover - """Deprecated. Use has() instead. - - Checks if a bond with the given uid already exists - in the container.""" - return self.has(uid) - # Internal per-type implementation. Mirrors the above but must be # reimplemented by subclasses. diff --git a/simphony/cuds/lattice.py b/simphony/cuds/lattice.py index d72fd21b..f481241c 100644 --- a/simphony/cuds/lattice.py +++ b/simphony/cuds/lattice.py @@ -133,10 +133,10 @@ def _iter_nodes(self, indices=None): """ if indices is None: for index, val in np.ndenumerate(self._dcs): - yield self.get_node(index) + yield self.get(index) else: for index in indices: - yield self.get_node(index) + yield self.get(index) def make_cubic_lattice(name, h, size, origin=(0, 0, 0)): diff --git a/simphony/cuds/tests/test_cuds.py b/simphony/cuds/tests/test_cuds.py index f42eff9a..6bef0eaf 100644 --- a/simphony/cuds/tests/test_cuds.py +++ b/simphony/cuds/tests/test_cuds.py @@ -111,7 +111,7 @@ def test_get_named_cuds_component(self): def test_add_named_dataset(self): ps = Particles('my particles') - ps.add_particles([Particle(), Particle()]) + ps.add([Particle(), Particle()]) c = CUDS() c.add(ps) @@ -120,7 +120,7 @@ def test_add_named_dataset(self): def test_add_nameless_dataset(self): ps = Particles(None) - ps.add_particles([Particle(), Particle()]) + ps.add([Particle(), Particle()]) c = CUDS() self.assertRaises(TypeError, c.add, ps) @@ -160,7 +160,7 @@ def test_remove_nameless_component_by_uid(self): def test_remove_dataset(self): ps = Particles('my particles') - ps.add_particles([Particle(), Particle()]) + ps.add([Particle(), Particle()]) c = CUDS() c.add(ps) c.remove(ps.name) @@ -170,8 +170,8 @@ def test_remove_dataset(self): def test_get_dataset_names(self): ps1 = Particles('M1') ps2 = Particles('M2') - ps1.add_particles([Particle(), Particle()]) - ps2.add_particles([Particle(), Particle()]) + ps1.add([Particle(), Particle()]) + ps2.add([Particle(), Particle()]) c = CUDS() c.add(ps1) c.add(ps2) @@ -191,8 +191,8 @@ def test_cuds_component_names(self): def test_iter_datasets_dimention(self): ps1 = Particles('M1') ps2 = Particles('M2') - ps1.add_particles([Particle(), Particle()]) - ps2.add_particles([Particle(), Particle()]) + ps1.add([Particle(), Particle()]) + ps2.add([Particle(), Particle()]) c = CUDS() c.add(ps1) c.add(ps2) @@ -204,8 +204,8 @@ def test_iter_datasets_dimention(self): def test_iter_datasets_types(self): dataset = Particles('M1') - dataset.add_particles([Particle(), - Particle()]) + dataset.add([Particle(), + Particle()]) c = CUDS() c.add(dataset) diff --git a/simphony/io/h5_cuds.py b/simphony/io/h5_cuds.py index af347dc6..861ae159 100644 --- a/simphony/io/h5_cuds.py +++ b/simphony/io/h5_cuds.py @@ -263,20 +263,19 @@ def _add_particles(self, particles, cuba_keys): h5_particles.data = particles.data if cuba_keys is not None: - for item in particles.iter_particles(): + for item in particles.iter(item_type=CUBA.PARTICLE): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.PARTICLE]}) - h5_particles.add_particles([item]) + h5_particles.add([item]) - for item in particles.iter_bonds(): + for item in particles.iter(item_type=CUBA.BOND): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.BOND]}) - h5_particles.add_bonds([item]) + h5_particles.add([item]) else: - h5_particles.add_particles(particles.iter_particles()) - h5_particles.add_bonds(particles.iter_bonds()) + h5_particles.add(particles.iter()) def _add_mesh(self, mesh, cuba_keys): """Add a mesh to the file. @@ -304,34 +303,31 @@ def _add_mesh(self, mesh, cuba_keys): h5_mesh.data = mesh.data if cuba_keys is not None: - for item in mesh.iter_points(): + for item in mesh.iter(item_type=CUBA.POINT): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.POINT]}) - h5_mesh.add_points([item]) + h5_mesh.add([item]) - for item in mesh.iter_edges(): + for item in mesh.iter(item_type=CUBA.EDGE): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.EDGE]}) - h5_mesh.add_edges([item]) + h5_mesh.add([item]) - for item in mesh.iter_faces(): + for item in mesh.iter(item_type=CUBA.FACE): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.FACE]}) - h5_mesh.add_faces([item]) + h5_mesh.add([item]) - for item in mesh.iter_cells(): + for item in mesh.iter(item_type=CUBA.CELL): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.CELL]}) - h5_mesh.add_cells([item]) + h5_mesh.add([item]) else: - h5_mesh.add_points(mesh.iter_points()) - h5_mesh.add_edges(mesh.iter_edges()) - h5_mesh.add_faces(mesh.iter_faces()) - h5_mesh.add_cells(mesh.iter_cells()) + h5_mesh.add(mesh.iter()) def _add_lattice(self, lattice, cuba_keys): """Add lattice to the file. @@ -359,13 +355,13 @@ def _add_lattice(self, lattice, cuba_keys): h5_lattice.data = lattice.data if cuba_keys is not None: - for item in lattice.iter_nodes(): + for item in lattice.iter(item_type=CUBA.NODE): item.data = DataContainer( {key: item.data[key] for key in item.data if key in cuba_keys[CUBA.NODE]}) - h5_lattice.update_nodes([item]) + h5_lattice.update([item]) else: - h5_lattice.update_nodes(lattice.iter_nodes()) + h5_lattice.update(lattice.iter(item_type=CUBA.NODE)) def _get_particles(self, name): """Get particle container from file. diff --git a/simphony/io/h5_lattice.py b/simphony/io/h5_lattice.py index 907fe625..c12b2366 100644 --- a/simphony/io/h5_lattice.py +++ b/simphony/io/h5_lattice.py @@ -194,4 +194,4 @@ def _iter_nodes(self, indices=None): yield LatticeNode(index, data) else: for index in indices: - yield self.get_node(index) + yield self._get_node(index) diff --git a/simphony/io/h5_mesh.py b/simphony/io/h5_mesh.py index eedb577b..9066ada0 100644 --- a/simphony/io/h5_mesh.py +++ b/simphony/io/h5_mesh.py @@ -115,11 +115,7 @@ class H5Mesh(ABCMesh): See Also -------- - get_point, get_edge, get_face, get_cell - add_point, add_edge, add_face, add_cell - update_point, update_edge, update_face, update_cell - iter_points, iter_edges, iter_faces, iter_cells - has_edges, has_faces, has_cells + get, add, update, iter, has, _create_points_table, _create_edges_table _create_faces_table, _create_cells_table @@ -677,7 +673,7 @@ def _iter_points(self, uids=None): ) else: for uid in uids: - yield self.get_point(uid) + yield self._get_point(uid) def _iter_edges(self, uids=None): """ Returns an iterator over edges. @@ -706,7 +702,7 @@ def _iter_edges(self, uids=None): ) else: for uid in uids: - yield self.get_edge(uid) + yield self._get_edge(uid) def _iter_faces(self, uids=None): """ Returns an iterator over faces. @@ -735,7 +731,7 @@ def _iter_faces(self, uids=None): ) else: for uid in uids: - yield self.get_face(uid) + yield self._get_face(uid) def _iter_cells(self, uids=None): """ Returns an iterator over cells. @@ -764,7 +760,7 @@ def _iter_cells(self, uids=None): ) else: for uid in uids: - yield self.get_cell(uid) + yield self._get_cell(uid) def _has_points(self): """ Check if the mesh container has edges diff --git a/simphony/io/tests/test_h5_cuds.py b/simphony/io/tests/test_h5_cuds.py index 538795c4..ba3094da 100644 --- a/simphony/io/tests/test_h5_cuds.py +++ b/simphony/io/tests/test_h5_cuds.py @@ -141,10 +141,10 @@ def test_add_get_dataset_with_cuba_keys_argument(self): # Add some CUBA data for particle in items: particle.data = DataContainer({CUBA.VELOCITY: [1, 0, 0]}) - expected.add_particles([particle]) + expected.add([particle]) particle.data = DataContainer( {CUBA.VELOCITY: [1, 0, 0], CUBA.MASS: 1}) - reference.add_particles([particle]) + reference.add([particle]) # Store reference dataset along with its data engine.add_dataset(reference, {CUBA.PARTICLE: [CUBA.VELOCITY]}) @@ -189,22 +189,22 @@ def test_add_get_dataset_with_cuba_keys_argument(self): # Add some CUBA data for point in [p for p in items if isinstance(p, Point)]: point.data = DataContainer({CUBA.VELOCITY: [1, 0, 0]}) - expected.add_points([point]) + expected.add([point]) point.data = DataContainer( {CUBA.VELOCITY: [1, 0, 0], CUBA.MASS: 1}) - reference.add_points([point]) + reference.add([point]) for edge in [e for e in items if isinstance(e, Edge)]: - expected.add_edges([edge]) - reference.add_edges([edge]) + expected.add([edge]) + reference.add([edge]) for face in [f for f in items if isinstance(f, Face)]: - expected.add_faces([face]) - reference.add_faces([face]) + expected.add([face]) + reference.add([face]) for cell in [c for c in items if isinstance(c, Cell)]: - expected.add_cells([cell]) - reference.add_cells([cell]) + expected.add([cell]) + reference.add([cell]) # Store reference dataset along with its data engine.add_dataset(reference, {CUBA.POINT: [CUBA.VELOCITY]}) @@ -246,12 +246,12 @@ def test_add_get_dataset_with_cuba_keys_argument(self): expected = self.create_dataset(name='test') # Add some CUBA data - for node in reference.iter_nodes(): + for node in reference.iter(item_type=CUBA.NODE): node.data = DataContainer({CUBA.NAME: 'test_container'}) - expected.update_nodes([node]) + expected.update([node]) node.data = DataContainer({CUBA.NAME: 'test_container', CUBA.DENSITY: 2}) - reference.update_nodes([node]) + reference.update([node]) # Store reference dataset along with its data engine.add_dataset(reference, {CUBA.NODE: [CUBA.NAME]}) diff --git a/simphony/testing/abc_check_lattice.py b/simphony/testing/abc_check_lattice.py index 6eb5ac47..c4e6b89d 100644 --- a/simphony/testing/abc_check_lattice.py +++ b/simphony/testing/abc_check_lattice.py @@ -141,18 +141,19 @@ def test_iter_nodes(self): container = self.container # number of nodes - number_of_nodes = sum(1 for node in container.iter_nodes()) + number_of_nodes = sum(1 for node in container.iter( + item_type=CUBA.NODE)) self.assertEqual(number_of_nodes, numpy.prod(self.size)) # data - for node in container.iter_nodes(): + for node in container.iter(item_type=CUBA.NODE): self.assertEqual(node.data, DataContainer()) # indexes x, y, z = numpy.meshgrid( range(self.size[0]), range(self.size[1]), range(self.size[2])) expected = set(zip(x.flat, y.flat, z.flat)) - indexes = {node.index for node in container.iter_nodes()} + indexes = {node.index for node in container.iter(item_type=CUBA.NODE)} self.assertEqual(indexes, expected) def test_iter_nodes_subset(self): @@ -165,62 +166,63 @@ def test_iter_nodes_subset(self): expected = set(zip(x.flat, y.flat, z.flat)) # data - for node in container.iter_nodes(expected): + for node in container.iter(expected, item_type=CUBA.NODE): self.assertEqual(node.data, DataContainer()) # indexes - indexes = {node.index for node in container.iter_nodes(expected)} + indexes = {node.index for node in container.iter(expected, + item_type=CUBA.NODE)} self.assertEqual(indexes, expected) def test_get_node(self): container = self.container index = 2, 3, 4 - node = container.get_node(index) + node = container.get(index) expected = LatticeNode(index) self.assertEqual(node, expected) # check that mutating the node does not change internal info node.data = create_data_container() - self.assertNotEqual(container.get_node(index), node) + self.assertNotEqual(container.get(index), node) def test_get_node_with_invalid_index(self): container = self.container index = 2, 300, 4 with self.assertRaises(IndexError): - container.get_node(index) + container.get(index) index = 2, 3, -4 with self.assertRaises(IndexError): - container.get_node(index) + container.get(index) def test_update_nodes_with_invalid_index(self): container = self.container index = 2, 3, 4 - node = container.get_node(index) + node = container.get(index) node.index = 2, 300, 4 with self.assertRaises(IndexError): - container.update_nodes((node,)) + container.update((node,)) node.index = 2, 3, -4 with self.assertRaises(IndexError): - container.update_nodes((node,)) + container.update((node,)) def test_update_nodes(self): container = self.container indices = ((2, 3, 4), (1, 2, 3)) - nodes = [container.get_node(index) for index in indices] + nodes = [container.get(index) for index in indices] for node in nodes: node.data = create_data_container(restrict=self.supported_cuba()) - container.update_nodes(nodes) + container.update(nodes) for n in xrange(len(indices)): index = indices[n] - new_node = container.get_node(index) + new_node = container.get(index) self.assertEqual(new_node, nodes[n]) # Check that `new_node` is not the same instance as `node` self.assertIsNot(new_node, nodes[n]) @@ -229,15 +231,15 @@ def test_update_nodes_with_extra_keywords(self): container = self.container indices = ((2, 3, 4), (1, 2, 3)) - nodes = [container.get_node(index) for index in indices] + nodes = [container.get(index) for index in indices] # Update with full DataContainer. for node in nodes: node.data = create_data_container() - container.update_nodes(nodes) + container.update(nodes) for n in xrange(len(indices)): index = indices[n] - new_node = container.get_node(index) + new_node = container.get(index) # We expect only the supported CUBA to be stored. expected = LatticeNode( index=nodes[n].index, diff --git a/simphony/testing/abc_check_mesh.py b/simphony/testing/abc_check_mesh.py index f9bdbdd2..41e2a4b9 100644 --- a/simphony/testing/abc_check_mesh.py +++ b/simphony/testing/abc_check_mesh.py @@ -82,10 +82,12 @@ class CheckMeshItemOperations(object): __metaclass__ = abc.ABCMeta operation_mapping = { - 'get item': 'none', - 'add item': 'none', - 'update item': 'none', - 'iter items': 'none'} + 'get item': 'get', + 'add item': 'add', + 'update item': 'update', + 'iter items': 'iter', + 'has items': 'has_type', + 'count items': 'count_of'} def setUp(self): self.item_list = self.create_items() @@ -107,6 +109,12 @@ def create_item(self, uid): """ + @abc.abstractproperty + def item_type(self): + """ + The item type this subclass handles + """ + @abc.abstractmethod def container_factory(self, name): """ Create and return the container object @@ -252,7 +260,7 @@ def test_update_multiple_item_data(self): # given container = self.container self._add_items(container) - items = list(self.iter_operation(container)) + items = list(self.iter_operation(container, item_type=self.item_type)) for item in items: item.data = create_data_container(restrict=self.supported_cuba()) @@ -283,7 +291,7 @@ def test_update_multiple_item_with_unsuported_cuba(self): # given container = self.container self._add_items(container) - items = list(self.iter_operation(container)) + items = list(self.iter_operation(container, item_type=self.item_type)) for item in items: item.data = create_data_container() @@ -343,7 +351,8 @@ def test_snapshot_principle_on_iteration(self): item.data = DataContainer() # then - retrieved = tuple(self.iter_operation(container))[0] + retrieved = tuple(self.iter_operation(container, + item_type=self.item_type))[0] self.assertNotEqual(retrieved, item) self.assertNotEqual(retrieved.data, item.data) @@ -370,7 +379,8 @@ def test_iterate_all_items(self): # when iterated_items = [ - item for item in self.iter_operation(container)] + item for item in self.iter_operation(container, + item_type=self.item_type)] # then # The order of iteration is not important in this case. @@ -427,12 +437,9 @@ def create_item(self, uid): coordinates=(0.1, -3.5, 44), data=create_data_container(restrict=self.supported_cuba())) - operation_mapping = { - 'get item': 'get_point', - 'add item': 'add_points', - 'update item': 'update_points', - 'iter items': 'iter_points', - 'count items': 'count_of'} + @property + def item_type(self): + return CUBA.POINT def count_items_operation(self, container, *args, **kwrds): method = getattr(container, self.operation_mapping['count items']) @@ -526,22 +533,12 @@ def setUp(self): for uid, point in zip(self.uids, self.points): point.uid = uid CheckMeshItemOperations.setUp(self) - self.container.add_points(self.points) - - operation_mapping = { - 'get item': 'none', - 'add item': 'none', - 'update item': 'none', - 'iter items': 'none', - 'has items': 'none', - 'count items': 'none'} + self.container.add(self.points) points_range = None point_groups = [1] - item_type = None - def has_items_operation(self, container, *args, **kwrds): method = getattr(container, self.operation_mapping['has items']) return method(*args, **kwrds) @@ -554,11 +551,13 @@ def test_has_items(self): container = self.container # container without items - self.assertFalse(self.has_items_operation(container)) + self.assertFalse(self.has_items_operation(container, + item_type=self.item_type)) # container with items self.add_operation(container, [self.item_list[0]]) - self.assertTrue(self.has_items_operation(container)) + self.assertTrue(self.has_items_operation(container, + item_type=self.item_type)) def test_count_items(self): container = self.container @@ -589,7 +588,7 @@ def test_update_item_points(self): container = self.container uids = self._add_items(container) item = self.get_operation(container, uids[2]) - point_uids = container.add_points([ + point_uids = container.add([ Point((1.0 * i, 1.0 * i, 1.0 * i)) for i in range(self.points_range[-1])]) @@ -622,9 +621,10 @@ def test_update_multiple_items_points(self): container = self.container self._add_items(container) items = [ - i for i in self.iter_operation(container)] + i for i in self.iter_operation(container, + item_type=self.item_type)] - point_uids = container.add_points([ + point_uids = container.add([ Point((1.0 * i, 1.0 * i, 1.0 * i)) for i in range(self.points_range[-1])]) @@ -664,19 +664,13 @@ def setUp(self): self.addTypeEqualityFunc( Edge, partial(compare_elements, testcase=self)) - operation_mapping = { - 'get item': 'get_edge', - 'add item': 'add_edges', - 'update item': 'update_edges', - 'iter items': 'iter_edges', - 'has items': 'has_edges', - 'count items': 'count_of'} - points_range = [2] point_groups = [1, 2] - item_type = CUBA.EDGE + @property + def item_type(self): + return CUBA.EDGE def create_items(self): uids = self.uids @@ -700,19 +694,13 @@ def setUp(self): self.addTypeEqualityFunc( Face, partial(compare_elements, testcase=self)) - operation_mapping = { - 'get item': 'get_face', - 'add item': 'add_faces', - 'update item': 'update_faces', - 'iter items': 'iter_faces', - 'has items': 'has_faces', - 'count items': 'count_of'} - points_range = [3, 4] point_groups = [1, 2, 3, 4] - item_type = CUBA.FACE + @property + def item_type(self): + return CUBA.FACE def create_items(self): uids = self.uids @@ -736,19 +724,13 @@ def setUp(self): self.addTypeEqualityFunc( Cell, partial(compare_elements, testcase=self)) - operation_mapping = { - 'get item': 'get_cell', - 'add item': 'add_cells', - 'update item': 'update_cells', - 'iter items': 'iter_cells', - 'has items': 'has_cells', - 'count items': 'count_of'} - points_range = range(4, 8) point_groups = [1, 2, 3, 4] - item_type = CUBA.CELL + @property + def item_type(self): + return CUBA.CELL def create_items(self): uids = self.uids diff --git a/simphony/testing/abc_check_particles.py b/simphony/testing/abc_check_particles.py index 2e2aa98d..dd903024 100644 --- a/simphony/testing/abc_check_particles.py +++ b/simphony/testing/abc_check_particles.py @@ -90,7 +90,7 @@ def setUp(self): Particle, partial(compare_particles, testcase=self)) self.particle_list = create_particles(restrict=self.supported_cuba()) self.container = self.container_factory('foo') - self.ids = self.container.add_particles(self.particle_list) + self.ids = self.container.add(self.particle_list) @abc.abstractmethod def container_factory(self, name): @@ -108,8 +108,8 @@ def test_has_particle(self): container = self.container # then - self.assertTrue(container.has_particle(self.ids[6])) - self.assertFalse(container.has_particle(uuid.UUID(int=1234))) + self.assertTrue(container.has(self.ids[6])) + self.assertFalse(container.has(uuid.UUID(int=1234))) def test_add_particles(self): # given and the setUp @@ -117,7 +117,7 @@ def test_add_particles(self): # then for index, particle in enumerate(self.particle_list): - self.assertTrue(container.has_particle(particle.uid)) + self.assertTrue(container.has(particle.uid)) self.assertEqual(particle.uid, self.ids[index]) def test_add_particles_with_unsupported_cuba(self): @@ -128,13 +128,13 @@ def test_add_particles_with_unsupported_cuba(self): data=create_data_container()) # when - uids = container.add_particles([particle]) + uids = container.add([particle]) uid = uids[0] # then particle.data = create_data_container(restrict=self.supported_cuba()) - self.assertTrue(container.has_particle(uid)) - self.assertEqual(container.get_particle(uid), particle) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), particle) def test_add_multiple_particles_with_unsupported_cuba(self): # given @@ -146,15 +146,15 @@ def test_add_multiple_particles_with_unsupported_cuba(self): Particle([i, i*10, i*100], data=data)) # when - container.add_particles(particles) + container.add(particles) # then for particle in particles: particle.data = create_data_container( restrict=self.supported_cuba()) uid = particle.uid - self.assertTrue(container.has_particle(uid)) - self.assertEqual(container.get_particle(uid), particle) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), particle) def test_add_particles_with_id(self): # given @@ -166,13 +166,13 @@ def test_add_particles_with_id(self): data=create_data_container(restrict=self.supported_cuba())) # when - uids = container.add_particles([particle]) + uids = container.add([particle]) particle_uid = uids[0] # then self.assertEqual(particle_uid, uid) - self.assertTrue(container.has_particle(uid)) - self.assertEqual(container.get_particle(uid), particle) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), particle) def test_add_multiple_particles_with_id(self): # given @@ -180,14 +180,14 @@ def test_add_multiple_particles_with_id(self): particles = create_particles_with_id(restrict=self.supported_cuba()) # when - uids = container.add_particles(particles) + uids = container.add(particles) # then for particle in particles: uid = particle.uid self.assertIn(uid, uids) - self.assertTrue(container.has_particle(uid)) - self.assertEqual(container.get_particle(uid), particle) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), particle) def test_exception_when_adding_particle_twice(self): # given @@ -196,7 +196,7 @@ def test_exception_when_adding_particle_twice(self): # then with self.assertRaises(ValueError): # when - container.add_particles([self.particle_list[3]]) + container.add([self.particle_list[3]]) def test_exception_when_adding_multiple_particles_twice(self): # given @@ -205,7 +205,7 @@ def test_exception_when_adding_multiple_particles_twice(self): # then with self.assertRaises(ValueError): # when - container.add_particles(self.particle_list) + container.add(self.particle_list) class CheckManipulatingParticles(object): @@ -230,7 +230,7 @@ def setUp(self): self.particle_list = create_particles(restrict=self.supported_cuba()) self.particle_list[0].uid = uuid.uuid4() self.container = self.container_factory('foo') - self.ids = self.container.add_particles(self.particle_list) + self.ids = self.container.add(self.particle_list) def test_get_particle(self): # given @@ -238,19 +238,19 @@ def test_get_particle(self): # when/then for uid, particle in map(None, self.ids, self.particle_list): - self.assertEqual(container.get_particle(uid), particle) + self.assertEqual(container.get(uid), particle) def test_update_particles(self): # given container = self.container - particle = container.get_particle(self.ids[2]) + particle = container.get(self.ids[2]) particle.coordinates = (123, 456, 789) # when - container.update_particles([particle]) + container.update([particle]) # then - retrieved = container.get_particle(particle.uid) + retrieved = container.get(particle.uid) self.assertEqual(retrieved, particle) def test_update_multiple_particles(self): @@ -258,16 +258,16 @@ def test_update_multiple_particles(self): container = self.container particles = [] for uid in self.ids: - particle = container.get_particle(uid) + particle = container.get(uid) particle.coordinates = (123, 456, 789) particles.append(particle) # when - container.update_particles(particles) + container.update(particles) # then for uid, particle in map(None, self.ids, particles): - retrieved = container.get_particle(uid) + retrieved = container.get(uid) self.assertEqual(retrieved, particle) def test_exception_when_update_particles_when_wrong_id(self): @@ -278,7 +278,7 @@ def test_exception_when_update_particles_when_wrong_id(self): # then with self.assertRaises(ValueError): # when - container.update_particles([particle]) + container.update([particle]) # given particle = Particle() @@ -286,7 +286,7 @@ def test_exception_when_update_particles_when_wrong_id(self): # then with self.assertRaises(ValueError): # when - container.update_particles([particle]) + container.update([particle]) def test_exception_when_update_multiple_particles_when_wrong_id(self): # given @@ -296,7 +296,7 @@ def test_exception_when_update_multiple_particles_when_wrong_id(self): # then with self.assertRaises(ValueError): # when - container.update_particles(particles) + container.update(particles) # given particles = create_particles_with_id() @@ -304,7 +304,7 @@ def test_exception_when_update_multiple_particles_when_wrong_id(self): # then with self.assertRaises(ValueError): # when - container.update_particles(particles) + container.update(particles) def test_remove_particles(self): # given @@ -313,16 +313,16 @@ def test_remove_particles(self): uid = particle.uid # when - container.remove_particles([particle.uid]) + container.remove([particle.uid]) # then particles = self.particle_list[:] ids = self.ids del particles[1] del ids[1] - self.assertFalse(self.container.has_particle(uid)) + self.assertFalse(self.container.has(uid)) for uid, particle in map(None, ids, particles): - self.assertEqual(container.get_particle(uid), particle) + self.assertEqual(container.get(uid), particle) def test_remove_multiple_particles(self): # given @@ -330,7 +330,7 @@ def test_remove_multiple_particles(self): uids = [self.particle_list[1].uid, self.particle_list[3].uid] # when - container.remove_particles(uids) + container.remove(uids) # then particles = self.particle_list[:] @@ -339,10 +339,10 @@ def test_remove_multiple_particles(self): del particles[1] del ids[3] del ids[1] - self.assertFalse(self.container.has_particle(uids[0])) - self.assertFalse(self.container.has_particle(uids[1])) + self.assertFalse(self.container.has(uids[0])) + self.assertFalse(self.container.has(uids[1])) for uid, particle in map(None, ids, particles): - self.assertEqual(container.get_particle(uid), particle) + self.assertEqual(container.get(uid), particle) def test_exception_when_removing_particle_with_bad_id(self): # given @@ -351,12 +351,12 @@ def test_exception_when_removing_particle_with_bad_id(self): # then with self.assertRaises(KeyError): # when - container.remove_particles([uuid.UUID(int=23325)]) + container.remove([uuid.UUID(int=23325)]) # then with self.assertRaises(KeyError): # when - container.remove_particles([None]) + container.remove([None]) def test_exception_when_removing_multiple_particles_with_bad_id(self): # given @@ -367,12 +367,12 @@ def test_exception_when_removing_multiple_particles_with_bad_id(self): # then with self.assertRaises(KeyError): # when - container.remove_particles(uids) + container.remove(uids) # then with self.assertRaises(KeyError): # when - container.remove_particles([None]) + container.remove([None]) def test_iter_particles_when_passing_ids(self): # given @@ -381,7 +381,9 @@ def test_iter_particles_when_passing_ids(self): # when iterated_particles = [ - particle for particle in self.container.iter_particles(ids)] + particle for particle in self.container.iter( + ids, + item_type=CUBA.PARTICLE)] # then for particle, reference in map(None, iterated_particles, particles): @@ -393,7 +395,8 @@ def test_iter_all_particles(self): # when iterated_particles = [ - particle for particle in self.container.iter_particles()] + particle for particle in self.container.iter( + item_type=CUBA.PARTICLE)] # then # The order of iteration is not important in this case. @@ -408,7 +411,7 @@ def test_exception_on_iter_particles_when_passing_wrong_ids(self): # when with self.assertRaises(KeyError): - for particle in self.container.iter_particles(ids): + for particle in self.container.iter(ids): pass # then @@ -453,18 +456,18 @@ def setUp(self): Bond, partial(compare_bonds, testcase=self)) self.particle_list = create_particles(restrict=self.supported_cuba()) self.container = self.container_factory("foo") - self.container.add_particles(self.particle_list) + self.container.add(self.particle_list) self.bond_list = create_bonds( restrict=self.supported_cuba(), particles=self.particle_list) - self.ids = self.container.add_bonds(self.bond_list) + self.ids = self.container.add(self.bond_list) def test_has_bond(self): # given and setUp container = self.container # then - self.assertTrue(container.has_bond(self.ids[2])) - self.assertFalse(container.has_bond(uuid.UUID(int=2122))) + self.assertTrue(container.has(self.ids[2])) + self.assertFalse(container.has(uuid.UUID(int=2122))) def test_add_bonds(self): # given and setUp @@ -472,7 +475,7 @@ def test_add_bonds(self): # then for index, bond in enumerate(self.bond_list): - self.assertTrue(container.has_bond(bond.uid)) + self.assertTrue(container.has(bond.uid)) self.assertEqual(bond.uid, self.ids[index]) def test_add_bonds_with_unsupported_cuba(self): @@ -484,13 +487,13 @@ def test_add_bonds_with_unsupported_cuba(self): data=create_data_container()) # when - uids = container.add_bonds([bond]) + uids = container.add([bond]) uid = uids[0] # then bond.data = create_data_container(restrict=self.supported_cuba()) - self.assertTrue(container.has_bond(uid)) - self.assertEqual(container.get_bond(uid), bond) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), bond) def test_add_multiple_bonds_with_unsupported_cuba(self): # given @@ -502,15 +505,15 @@ def test_add_multiple_bonds_with_unsupported_cuba(self): bonds.append(Bond(particles=ids, data=data)) # when - container.add_bonds(bonds) + container.add(bonds) # then for bond in bonds: bond.data = create_data_container( restrict=self.supported_cuba()) uid = bond.uid - self.assertTrue(container.has_bond(uid)) - self.assertEqual(container.get_bond(uid), bond) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), bond) def test_add_bonds_with_id(self): # given @@ -523,12 +526,12 @@ def test_add_bonds_with_id(self): data=create_data_container(restrict=self.supported_cuba())) # when - uids = container.add_bonds([bond]) + uids = container.add([bond]) bond_uid = uids[0] # then self.assertEqual(bond_uid, uid) - self.assertTrue(container.has_bond(uid)) + self.assertTrue(container.has(uid)) def test_add_multiple_bonds_with_id(self): # given @@ -537,32 +540,32 @@ def test_add_multiple_bonds_with_id(self): bonds = create_bonds_with_id(restrict=self.supported_cuba()) # when - uids = container.add_bonds(bonds) + uids = container.add(bonds) # then for bond in bonds: uid = bond.uid self.assertIn(uid, uids) - self.assertTrue(container.has_bond(uid)) - self.assertEqual(container.get_bond(uid), bond) + self.assertTrue(container.has(uid)) + self.assertEqual(container.get(uid), bond) def test_exception_when_adding_bond_twice(self): # then with self.assertRaises(ValueError): # when - self.container.add_bonds([self.bond_list[4]]) + self.container.add([self.bond_list[4]]) def test_exception_when_adding_multiple_bonds_twice(self): # then with self.assertRaises(ValueError): # when - self.container.add_bonds(self.bond_list) + self.container.add(self.bond_list) def test_exception_when_adding_bond_with_invalid_id(self): # then with self.assertRaises(AttributeError): # when - self.container.add_bonds([Bond(uid=object(), + self.container.add([Bond(uid=object(), particles=[uuid.uuid4()])]) def test_exception_when_adding_multiple_bonds_with_invalid_id(self): @@ -572,7 +575,7 @@ def test_exception_when_adding_multiple_bonds_with_invalid_id(self): # then with self.assertRaises(AttributeError): # when - self.container.add_bonds(bonds) + self.container.add(bonds) class CheckManipulatingBonds(object): @@ -595,10 +598,10 @@ def setUp(self): Bond, partial(compare_bonds, testcase=self)) self.particle_list = create_particles(restrict=self.supported_cuba()) self.container = self.container_factory("foo") - self.container.add_particles(self.particle_list) + self.container.add(self.particle_list) self.bond_list = create_bonds( restrict=self.supported_cuba(), particles=self.particle_list) - self.ids = self.container.add_bonds(self.bond_list) + self.ids = self.container.add(self.bond_list) def test_get_bond(self): # given @@ -606,20 +609,20 @@ def test_get_bond(self): # when/then for uid, bond in map(None, self.ids, self.bond_list): - self.assertEqual(container.get_bond(uid), bond) + self.assertEqual(container.get(uid), bond) def test_update_bonds(self): # given container = self.container - bond = container.get_bond(self.ids[1]) + bond = container.get(self.ids[1]) bond.particles = bond.particles[:-1] bond.data = DataContainer() # when - container.update_bonds([bond]) + container.update([bond]) # then - new_bond = container.get_bond(bond.uid) + new_bond = container.get(bond.uid) self.assertEqual(new_bond, bond) self.assertNotEqual(new_bond, self.bond_list[1]) @@ -632,26 +635,26 @@ def test_update_multiple_bonds(self): bond.particles = (uid,) # when - container.update_bonds(bonds) + container.update(bonds) # then for uid, bond in map(None, self.ids, bonds): - retrieved = container.get_bond(uid) + retrieved = container.get(uid) self.assertEqual(retrieved, bond) def test_update_bonds_with_unsupported_cuba(self): # given container = self.container - bond = container.get_bond(self.ids[1]) + bond = container.get(self.ids[1]) bond.particles = bond.particles[:-1] bond.data = create_data_container() # when - container.update_bonds([bond]) + container.update([bond]) # then bond.data = create_data_container(restrict=self.supported_cuba()) - new_bond = container.get_bond(bond.uid) + new_bond = container.get(bond.uid) self.assertEqual(new_bond, bond) self.assertNotEqual(new_bond, self.bond_list[1]) @@ -660,19 +663,19 @@ def test_update_multiple_bonds_with_unsupported_cuba(self): container = self.container updated_bonds = [] for uid in self.ids: - bond = container.get_bond(uid) + bond = container.get(uid) bond.particles = bond.particles[:-1] bond.data = create_data_container() updated_bonds.append(bond) # when - container.update_bonds(updated_bonds) + container.update(updated_bonds) # then for bond in updated_bonds: bond.data = create_data_container(restrict=self.supported_cuba()) for uid, bond in map(None, self.ids, updated_bonds): - new_bond = container.get_bond(uid) + new_bond = container.get(uid) self.assertEqual(new_bond, bond) def test_exeception_when_updating_bond_with_incorrect_id(self): @@ -682,7 +685,7 @@ def test_exeception_when_updating_bond_with_incorrect_id(self): # then with self.assertRaises(ValueError): # when - self.container.update_bonds([bond]) + self.container.update([bond]) def test_exeception_when_updating_multiple_bonds_with_incorrect_id(self): # given @@ -691,7 +694,7 @@ def test_exeception_when_updating_multiple_bonds_with_incorrect_id(self): # then with self.assertRaises(ValueError): # when - self.container.update_bonds(bonds) + self.container.update(bonds) def test_remove_bonds(self): # given @@ -699,16 +702,16 @@ def test_remove_bonds(self): uid = self.ids[1] # when - container.remove_bonds([uid]) + container.remove([uid]) # then bonds = self.bond_list[:] ids = self.ids del bonds[1] del ids[1] - self.assertFalse(self.container.has_bond(uid)) + self.assertFalse(self.container.has(uid)) for uid, bond in map(None, ids, bonds): - self.assertEqual(container.get_bond(uid), bond) + self.assertEqual(container.get(uid), bond) def test_remove_multiple_bonds(self): # given @@ -716,7 +719,7 @@ def test_remove_multiple_bonds(self): uids = [self.ids[1], self.ids[3]] # when - container.remove_bonds(uids) + container.remove(uids) # then bonds = self.bond_list[:] @@ -725,23 +728,23 @@ def test_remove_multiple_bonds(self): del bonds[1] del ids[3] del ids[1] - self.assertFalse(self.container.has_bond(uids[0])) - self.assertFalse(self.container.has_bond(uids[1])) + self.assertFalse(self.container.has(uids[0])) + self.assertFalse(self.container.has(uids[1])) for uid, bond in map(None, ids, bonds): - self.assertEqual(container.get_bond(uid), bond) + self.assertEqual(container.get(uid), bond) def test_exception_removing_bond_with_missing_id(self): # then with self.assertRaises(KeyError): # when - self.container.remove_bonds([uuid.UUID(int=12124124)]) + self.container.remove([uuid.UUID(int=12124124)]) def test_exception_removing_multiple_bonds_with_missing_id(self): # then with self.assertRaises(KeyError): # when - self.container.remove_bonds([uuid.UUID(int=12124124), - uuid.UUID(int=19373737)]) + self.container.remove([uuid.UUID(int=12124124), + uuid.UUID(int=19373737)]) def test_iter_bonds_when_passing_ids(self): # given @@ -750,7 +753,7 @@ def test_iter_bonds_when_passing_ids(self): # when iterated_bonds = [ - bond for bond in self.container.iter_bonds(ids)] + bond for bond in self.container.iter(ids)] # then for bond, reference in map(None, iterated_bonds, bonds): @@ -762,7 +765,7 @@ def test_iter_all_bonds(self): # when iterated_bonds = [ - bond for bond in self.container.iter_bonds()] + bond for bond in self.container.iter(item_type=CUBA.BOND)] # then # The order of iteration is not important in this case. @@ -777,7 +780,7 @@ def test_exception_on_iter_bonds_when_passing_wrong_ids(self): # when with self.assertRaises(KeyError): - for bond in self.container.iter_bonds(bonds_ids): + for bond in self.container.iter(bonds_ids): pass # then diff --git a/simphony/testing/tests/test_utils.py b/simphony/testing/tests/test_utils.py index 7e0bde06..b1772626 100644 --- a/simphony/testing/tests/test_utils.py +++ b/simphony/testing/tests/test_utils.py @@ -37,11 +37,11 @@ def test_compare_particles_datasets_equal(self): bond_list = create_bonds() data = DataContainer() - particles.add_particles(particle_list) - reference.add_particles(particle_list) + particles.add(particle_list) + reference.add(particle_list) - particles.add_bonds(bond_list) - reference.add_bonds(bond_list) + particles.add(bond_list) + reference.add(bond_list) particles.data = data reference.data = data @@ -58,11 +58,11 @@ def test_compare_particles_datasets_not_equal(self): bond_list = create_bonds() data = create_data_container() - particles.add_particles(particle_list) - reference.add_particles(particle_list) + particles.add(particle_list) + reference.add(particle_list) - particles.add_bonds(bond_list) - reference.add_bonds(bond_list) + particles.add(bond_list) + reference.add(bond_list) particles.data = data reference.data = data @@ -75,8 +75,8 @@ def test_compare_particles_datasets_not_equal(self): test_particles = create_particles_with_id() particles = Particles(name=reference.name) - particles.add_particles(test_particles) - particles.add_bonds(bond_list) + particles.add(test_particles) + particles.add(bond_list) particles.data = data # when/then @@ -87,8 +87,8 @@ def test_compare_particles_datasets_not_equal(self): test_bonds = create_bonds() particles = Particles(name=reference.name) - particles.add_particles(particle_list) - particles.add_bonds(test_bonds) + particles.add(particle_list) + particles.add(test_bonds) particles.data = data # when/then @@ -99,8 +99,8 @@ def test_compare_particles_datasets_not_equal(self): test_data = DataContainer() particles = Particles(name=reference.name) - particles.add_particles(particle_list) - particles.add_bonds(bond_list) + particles.add(particle_list) + particles.add(bond_list) particles.data = test_data # when/then @@ -122,15 +122,15 @@ def test_compare_mesh_datasets_equal(self): data = DataContainer() - mesh.add_points(point_list) - mesh.add_edges(edge_list) - mesh.add_faces(face_list) - mesh.add_cells(cell_list) + mesh.add(point_list) + mesh.add(edge_list) + mesh.add(face_list) + mesh.add(cell_list) - reference.add_points(point_list) - reference.add_edges(edge_list) - reference.add_faces(face_list) - reference.add_cells(cell_list) + reference.add(point_list) + reference.add(edge_list) + reference.add(face_list) + reference.add(cell_list) mesh.data = data reference.data = data @@ -150,15 +150,15 @@ def test_compare_mesh_datasets_not_equal(self): data = create_data_container() - mesh.add_points(point_list) - mesh.add_edges(edge_list) - mesh.add_faces(face_list) - mesh.add_cells(cell_list) + mesh.add(point_list) + mesh.add(edge_list) + mesh.add(face_list) + mesh.add(cell_list) - reference.add_points(point_list) - reference.add_edges(edge_list) - reference.add_faces(face_list) - reference.add_cells(cell_list) + reference.add(point_list) + reference.add(edge_list) + reference.add(face_list) + reference.add(cell_list) mesh.data = data reference.data = data @@ -172,10 +172,10 @@ def test_compare_mesh_datasets_not_equal(self): mesh = Mesh(name=reference.name) - mesh.add_points(test_points) - mesh.add_edges(edge_list) - mesh.add_faces(face_list) - mesh.add_cells(cell_list) + mesh.add(test_points) + mesh.add(edge_list) + mesh.add(face_list) + mesh.add(cell_list) mesh.data = data @@ -188,10 +188,10 @@ def test_compare_mesh_datasets_not_equal(self): mesh = Mesh(name=reference.name) - mesh.add_points(point_list) - mesh.add_edges(test_edges) - mesh.add_faces(face_list) - mesh.add_cells(cell_list) + mesh.add(point_list) + mesh.add(test_edges) + mesh.add(face_list) + mesh.add(cell_list) mesh.data = data @@ -204,10 +204,10 @@ def test_compare_mesh_datasets_not_equal(self): mesh = Mesh(name=reference.name) - mesh.add_points(point_list) - mesh.add_edges(edge_list) - mesh.add_faces(test_faces) - mesh.add_cells(cell_list) + mesh.add(point_list) + mesh.add(edge_list) + mesh.add(test_faces) + mesh.add(cell_list) mesh.data = data @@ -220,10 +220,10 @@ def test_compare_mesh_datasets_not_equal(self): mesh = Mesh(name=reference.name) - mesh.add_points(point_list) - mesh.add_edges(edge_list) - mesh.add_faces(face_list) - mesh.add_cells(test_cells) + mesh.add(point_list) + mesh.add(edge_list) + mesh.add(face_list) + mesh.add(test_cells) mesh.data = data @@ -236,10 +236,10 @@ def test_compare_mesh_datasets_not_equal(self): mesh = Mesh(name=reference.name) - mesh.add_points(point_list) - mesh.add_edges(edge_list) - mesh.add_faces(face_list) - mesh.add_cells(cell_list) + mesh.add(point_list) + mesh.add(edge_list) + mesh.add(face_list) + mesh.add(cell_list) mesh.data = test_data diff --git a/simphony/testing/utils.py b/simphony/testing/utils.py index 45d58341..105dfbf7 100644 --- a/simphony/testing/utils.py +++ b/simphony/testing/utils.py @@ -16,9 +16,11 @@ def compare_particles_datasets(particles, reference, testcase=None): self = testcase self.assertEqual(particles.name, reference.name) - for b, r in zip(particles.iter_bonds(), reference.iter_bonds()): + for b, r in zip(particles.iter(item_type=CUBA.BOND), + reference.iter(item_type=CUBA.BOND)): compare_bonds(b, r, testcase=self) - for p, r in zip(particles.iter_particles(), reference.iter_particles()): + for p, r in zip(particles.iter(item_type=CUBA.PARTICLE), + reference.iter(item_type=CUBA.PARTICLE)): compare_particles(p, r, testcase=self) compare_data_containers(particles.data, reference.data, testcase=self) @@ -26,13 +28,17 @@ def compare_particles_datasets(particles, reference, testcase=None): def compare_mesh_datasets(mesh, reference, testcase=None): self = testcase self.assertEqual(mesh.name, reference.name) - for p, r in zip(mesh.iter_points(), reference.iter_points()): + for p, r in zip(mesh.iter(item_type=CUBA.POINT), + reference.iter(item_type=CUBA.POINT)): compare_points(p, r, testcase=self) - for e, r in zip(mesh.iter_edges(), reference.iter_edges()): + for e, r in zip(mesh.iter(item_type=CUBA.EDGE), + reference.iter(item_type=CUBA.EDGE)): compare_elements(e, r, testcase=self) - for f, r in zip(mesh.iter_faces(), reference.iter_faces()): + for f, r in zip(mesh.iter(item_type=CUBA.FACE), + reference.iter(item_type=CUBA.FACE)): compare_elements(f, r, testcase=self) - for c, r in zip(mesh.iter_cells(), reference.iter_cells()): + for c, r in zip(mesh.iter(item_type=CUBA.CELL), + reference.iter(item_type=CUBA.CELL)): compare_elements(c, r, testcase=self) compare_data_containers(mesh.data, reference.data, testcase=self) @@ -40,7 +46,8 @@ def compare_mesh_datasets(mesh, reference, testcase=None): def compare_lattice_datasets(lattice, reference, testcase=None): self = testcase self.assertEqual(lattice.name, reference.name) - for l, r in zip(lattice.iter_nodes(), reference.iter_nodes()): + for l, r in zip(lattice.iter(item_type=CUBA.NODE), + reference.iter(item_type=CUBA.NODE)): compare_lattice_nodes(l, r, testcase=self) compare_data_containers(lattice.data, reference.data, testcase=self) self.assertEqual(lattice.primitive_cell.bravais_lattice,