def test_compare_nodes_not_equal(self): # given node = LatticeNode( index=(0, 2, 1), data=create_data_container()) reference = LatticeNode( index=(1, 2, 1), data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_lattice_nodes(node, reference, testcase=self) # given node = LatticeNode( index=(0, 2, 1), data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_lattice_nodes(node, reference, testcase=self) # given node = LatticeNode((0, 0, 0)) # when/then with self.assertRaises(AssertionError): compare_lattice_nodes(node, reference, testcase=self)
def test_compare_nodes_equal(self): # given node = LatticeNode(index=(0, 2, 1), data=create_data_container()) reference = LatticeNode(index=(0, 2, 1), data=create_data_container()) # this should pass without problems compare_lattice_nodes(node, reference, testcase=self)
def test_add_multiple_particles_with_unsupported_cuba(self): # given container = self.container particles = [] for i in xrange(10): data = create_data_container() particles.append( Particle([i, i*10, i*100], data=data)) # TODO. This is a fix so particles have the right attributes # for lammps (MD) material = self.configurator.materials[0] for p in particles: p.data[CUBA.MATERIAL_TYPE] = material.uid # when container.add(particles) # then for particle in particles: particle.data = create_data_container( restrict=self.supported_cuba()) # TODO. This is a fix so particles have the right attributes # for lammps (MD) particle.data[CUBA.MATERIAL_TYPE] = material.uid uid = particle.uid self.assertTrue(container.has(uid)) self.assertEqual(container.get(uid), particle)
def test_compare_data_containers_equal(self): data = create_data_container() expected = create_data_container() # This should pass without a problem compare_data_containers(data, expected, testcase=self) compare_data_containers( DataContainer(), DataContainer(), testcase=self) compare_data_containers({}, DataContainer(), testcase=self)
def test_compare_data_containers_equal(self): data = create_data_container() expected = create_data_container() # This should pass without a problem compare_data_containers(data, expected, testcase=self) compare_data_containers(DataContainer(), DataContainer(), testcase=self) compare_data_containers({}, DataContainer(), testcase=self)
def test_compare_data_containers_not_equal(self): expected = create_data_container() data = create_data_container(constant=1) with self.assertRaises(AssertionError): compare_data_containers(data, expected, testcase=self) data = create_data_container(restrict=[CUBA.MASS]) with self.assertRaises(AssertionError): compare_data_containers(data, expected, testcase=self)
def test_accumulate_with_empty_keys(self): accumulator = CUBADataAccumulator([]) accumulator.append(create_data_container(restrict=[CUBA.NAME])) accumulator.append( create_data_container(restrict=[CUBA.NAME, CUBA.VELOCITY, CUBA.LATTICE_VECTORS])) self.assertEqual(len(accumulator.keys), 0) vtk_data = tvtk.PointData() accumulator.load_onto_vtk(vtk_data) self.assertEqual(vtk_data.number_of_arrays, 0)
def test_container_data_update_with_unsupported_cuba(self): # given container = self.container data = create_data_container() expected_data = create_data_container(restrict=self.supported_cuba()) # when container.data = data # then self.assertEqual(container.data, expected_data)
def test_compare_points_equal(self): # given point = Point(uid=None, coordinates=(10.0, 0.0, 2.0), data=create_data_container()) reference = Point(uid=None, coordinates=(10.0, 0.0, 2.0), data=create_data_container()) # this should pass without problems compare_points(point, reference, testcase=self)
def test_compare_nodes_equal(self): # given node = LatticeNode( index=(0, 2, 1), data=create_data_container()) reference = LatticeNode( index=(0, 2, 1), data=create_data_container()) # this should pass without problems compare_lattice_nodes(node, reference, testcase=self)
def test_compare_bonds_equal(self): # given particles = [uuid.uuid4(), uuid.uuid4()], bond = Bond(uid=None, particles=particles, data=create_data_container()) reference = Bond(uid=None, particles=particles, data=create_data_container()) # this should pass without problems compare_bonds(bond, reference, testcase=self)
def test_compare_points_equal(self): # given point = Point( uid=None, coordinates=(10.0, 0.0, 2.0), data=create_data_container()) reference = Point( uid=None, coordinates=(10.0, 0.0, 2.0), data=create_data_container()) # this should pass without problems compare_points(point, reference, testcase=self)
def test_load_scalars_onto_vtk(self): accumulator = CUBADataAccumulator() accumulator.append(create_data_container(restrict=[CUBA.NAME])) accumulator.append( create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE])) vtk_data = tvtk.PointData() accumulator.load_onto_vtk(vtk_data) self.assertEqual(vtk_data.number_of_arrays, 1) expected = numpy.array( [None, dummy_cuba_value(CUBA.TEMPERATURE)], dtype=float) assert_array_equal(vtk_data.get_array(0), expected) assert_array_equal(vtk_data.get_array(CUBA.TEMPERATURE.name), expected)
def test_add_particles_with_unsupported_cuba(self): # given container = self.container particle = Particle(coordinates=(1, 2, -3), data=create_data_container()) # when uids = container.add_particles([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)
def test_add_item_with_unsuported_cuba(self): # given container = self.container expected = self.create_item(None) expected.data = create_data_container() # when uid = self.add_operation(container, [expected]) # then retrieved = self.get_operation(container, uid[0]) expected.data = create_data_container(restrict=self.supported_cuba()) self.assertEqual(retrieved, expected)
def test_compare_bonds_equal(self): # given particles = [uuid.uuid4(), uuid.uuid4()], bond = Bond( uid=None, particles=particles, data=create_data_container()) reference = Bond( uid=None, particles=particles, data=create_data_container()) # this should pass without problems compare_bonds(bond, reference, testcase=self)
def test_add_bonds_with_unsupported_cuba(self): # given container = self.container particles = self.particle_list[0].uid, self.particle_list[-1].uid bond = Bond(particles=particles, data=create_data_container()) # when uids = container.add_bonds([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)
def test_update_item_with_unsuported_cuba(self): # given container = self.container uids = self._add_items(container) item = self.get_operation(container, uids[2]) item.data = create_data_container() # when self.update_operation(container, [item]) # then retrieved = self.get_operation(container, item.uid) item.data = create_data_container(restrict=self.supported_cuba()) self.assertEqual(retrieved, item)
def test_load_vectors_onto_vtk(self): accumulator = CUBADataAccumulator() accumulator.append(create_data_container(restrict=[CUBA.NAME])) accumulator.append( create_data_container(restrict=[CUBA.NAME, CUBA.VELOCITY, CUBA.LATTICE_VECTORS])) vtk_data = tvtk.PointData() accumulator.load_onto_vtk(vtk_data) self.assertEqual(vtk_data.number_of_arrays, 1) expected = numpy.array( [[None, None, None], dummy_cuba_value(CUBA.VELOCITY)], dtype=float) assert_array_equal(vtk_data.get_array(0), expected) assert_array_equal(vtk_data.get_array(CUBA.VELOCITY.name), expected)
def test_accumulate_and_expand(self): accumulator = CUBADataAccumulator() accumulator.append(create_data_container(restrict=[CUBA.NAME])) accumulator.append( create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE])) self.assertEqual(len(accumulator), 2) self.assertEqual(accumulator.keys, set([CUBA.NAME, CUBA.TEMPERATURE])) assert_array_equal( accumulator[CUBA.TEMPERATURE], [None, dummy_cuba_value(CUBA.TEMPERATURE)]) assert_array_equal( accumulator[CUBA.NAME], [dummy_cuba_value(CUBA.NAME)] * 2)
def test_update_bonds_with_unsupported_cuba(self): # given container = self.container bond = container.get_bond(self.ids[1]) bond.particles = bond.particles[:-1] bond.data = create_data_container() # when container.update_bonds([bond]) # then bond.data = create_data_container(restrict=self.supported_cuba()) new_bond = container.get_bond(bond.uid) self.assertEqual(new_bond, bond) self.assertNotEqual(new_bond, self.bond_list[1])
def test_itersequence(self): # create sample data data = [] saved_keys = self.saved_keys for key in saved_keys[:-1]: data_container = create_data_container(restrict=saved_keys) del data_container[key] data.append(data_container) # add to data container table with self.open_table('my_data_table', mode='a') as table: uids = { table.append(data_container): data_container for data_container in data} self.assertEqual(len(table), len(saved_keys) - 1) # Iterate over a sequence of rows with self.open_table('my_data_table') as table: sequence = random.sample(uids, 4) loaded_data = [ container for container in table.itersequence(sequence)] self.assertEqual(len(loaded_data), 4) for index, container in enumerate(loaded_data): self.assertDataContainersEqual( container, uids[sequence[index]])
def item_list(self): item_list = [] for i in xrange(10): data = create_data_container(restrict=SUPPORTED_CUBA) data[CUBA.VELOCITY] = i item_list.append(_DummyItem(data=data, value=i)) return item_list
def test_update_multiple_item_with_unsuported_cuba(self): # given container = self.container self._add_items(container) items = list(self.iter_operation(container)) for item in items: item.data = create_data_container() # when self.update_operation(container, items) # then for item in items: retrieved = self.get_operation(container, item.uid) item.data = create_data_container(restrict=self.supported_cuba()) self.assertEqual(retrieved, item)
def test_accumulate_with_missing_values(self): accumulator = CUBADataAccumulator() accumulator.append(create_data_container()) accumulator.append( create_data_container(restrict=[CUBA.NAME, CUBA.TEMPERATURE])) self.assertEqual(len(accumulator), 2) self.assertEqual(accumulator.keys, set(CUBA)) for cuba in CUBA: if cuba in [CUBA.NAME, CUBA.TEMPERATURE]: assert_array_equal( accumulator[cuba], [dummy_cuba_value(cuba)] * 2) else: assert_array_equal( accumulator[cuba][0], dummy_cuba_value(cuba)) self.assertIsNone(accumulator[cuba][1])
def item_list(self): item_list = [] for i in xrange(10): data = create_data_container() data[CUBA.VELOCITY] = i item_list.append(_DummyItem(data=data, value=i)) return item_list
def test_get_with_invalid_uid(self): saved_keys = self.saved_keys data = create_data_container(restrict=saved_keys) with self.new_table('my_data_table') as table: table.append(data) with self.open_table('my_data_table') as table: with self.assertRaises(KeyError): table[uuid.uuid4()]
def test_set_with_invalid_index(self): saved_keys = self.saved_keys data = create_data_container(restrict=saved_keys) with self.new_table('my_data_table') as table: table.append(data) with self.open_table('my_data_table') as table: with self.assertRaises(IndexError): table[7] = data
def test_add_multiple_particles_with_unsupported_cuba(self): # given container = self.container particles = [] for i in xrange(10): data = create_data_container() particles.append(Particle([i, i * 10, i * 100], data=data)) # when container.add_particles(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)
def test_add_multiple_bonds_with_unsupported_cuba(self): # given container = self.container bonds = [] for i in xrange(5): data = create_data_container() ids = [uuid.uuid4() for x in xrange(5)] bonds.append(Bond(particles=ids, data=data)) # when container.add_bonds(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)
def test_compare_particles_datasets_not_equal(self): # given particles = Particles(name="test") reference = Particles(name="test_ref") particle_list = create_particles_with_id() bond_list = create_bonds() data = create_data_container() particles.add(particle_list) reference.add(particle_list) particles.add(bond_list) reference.add(bond_list) particles.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_particles = create_particles_with_id() particles = Particles(name=reference.name) particles.add(test_particles) particles.add(bond_list) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_bonds = create_bonds() particles = Particles(name=reference.name) particles.add(particle_list) particles.add(test_bonds) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_data = DataContainer() particles = Particles(name=reference.name) particles.add(particle_list) particles.add(bond_list) particles.data = test_data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self)
def test_compare_particles_datasets_not_equal(self): # given particles = Particles(name="test") reference = Particles(name="test_ref") particle_list = create_particles_with_id() bond_list = create_bonds() data = create_data_container() particles.add_particles(particle_list) reference.add_particles(particle_list) particles.add_bonds(bond_list) reference.add_bonds(bond_list) particles.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_particles = create_particles_with_id() particles = Particles(name=reference.name) particles.add_particles(test_particles) particles.add_bonds(bond_list) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_bonds = create_bonds() particles = Particles(name=reference.name) particles.add_particles(particle_list) particles.add_bonds(test_bonds) particles.data = data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self) # given test_data = DataContainer() particles = Particles(name=reference.name) particles.add_particles(particle_list) particles.add_bonds(bond_list) particles.data = test_data # when/then with self.assertRaises(AssertionError): compare_particles_datasets(particles, reference, testcase=self)
def test_update_multiple_bonds_with_unsupported_cuba(self): # given container = self.container updated_bonds = [] for uid in self.ids: bond = container.get_bond(uid) bond.particles = bond.particles[:-1] bond.data = create_data_container() updated_bonds.append(bond) # when container.update_bonds(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) self.assertEqual(new_bond, bond)
def test_compare_elements_not_equal(self): # given points = [uuid.uuid4(), uuid.uuid4(), uuid.uuid4()], element = Element( uid=uuid.uuid4(), points=points, data=create_data_container()) reference = Element( uid=uuid.uuid4(), points=points, data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self) # given element = Element( uid=reference.uid, points=points[1:], data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self) # given element = Element( uid=reference.uid, points=points, data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self) # given element = Element(points=[]) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self)
def test_compare_bonds_not_equal(self): # given particles = [uuid.uuid4(), uuid.uuid4()], bond = Bond( uid=uuid.uuid4(), particles=particles, data=create_data_container()) reference = Bond( uid=uuid.uuid4(), particles=particles, data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self) # given bond = Bond( uid=reference.uid, particles=particles[-1], data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self) # given bond = Bond( uid=uuid.uuid4(), particles=particles, data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self) # given bond = Bond([None]) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self)
def test_create_points_with_id(self): points = create_points_with_id(n=10) self.assertEqual(len(points), 10) for index, point in enumerate(points): self.assertIsInstance(point, Point) self.assertIsNotNone(point.uid) self.assertEqual(point.coordinates, (index, index * 10, index * 100)) compare_data_containers(point.data, create_data_container(), testcase=self)
def test_container_data_update(self): # given container = self.container data = create_data_container(restrict=self.supported_cuba()) # when container.data = data # then self.assertEqual(container.data, data) self.assertIsNot(container.data, data)
def test_compare_elements_equal(self): # given points = [uuid.uuid4(), uuid.uuid4(), uuid.uuid4()], element = Element(uid=None, points=points, data=create_data_container()) reference = Element(uid=None, points=points, data=create_data_container()) # this should pass without problems compare_elements(element, reference, testcase=self) # given element = Element(uid=None, points=list(reversed(points)), data=create_data_container()) # this should pass without problems compare_elements(element, reference, testcase=self)
def test_create_particles_with_id(self): particles = create_particles_with_id(n=9) self.assertEqual(len(particles), 9) for index, particle in enumerate(particles): self.assertIsInstance(particle, Particle) self.assertIsNotNone(particle.uid) self.assertEqual(particle.coordinates, (index, index * 10, index * 100)) compare_data_containers(particle.data, create_data_container(), testcase=self)
def test_compare_lattice_datasets_not_equal(self): # given lattice = make_cubic_lattice('test', 1.0, (2, 3, 4)) reference = make_cubic_lattice('test_ref', 1.0, ( 2, 3, 4, )) data = create_data_container() lattice.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_lattice_datasets(lattice, reference, testcase=self) # given test_data = DataContainer() lattice = make_cubic_lattice('test_ref', 1.0, (2, 3, 4)) lattice.data = test_data # when/then with self.assertRaises(AssertionError): compare_lattice_datasets(lattice, reference, testcase=self) # given lattice = make_cubic_lattice('test', 2.0, (2, 3, 4)) lattice.data = data # when/then with self.assertRaises(AssertionError): compare_lattice_datasets(lattice, reference, testcase=self) # given lattice = make_cubic_lattice('test_ref', 1.0, (4, 6, 8)) lattice.data = data # when/then with self.assertRaises(AssertionError): compare_lattice_datasets(lattice, reference, testcase=self) # given lattice = make_cubic_lattice('test_ref', 1.0, (2, 3, 4), (2.0, 2.0, 2.0)) lattice.data = data # when/then with self.assertRaises(AssertionError): compare_lattice_datasets(lattice, reference, testcase=self)
def test_create_bonds(self): n = 7 bonds = create_bonds(n=n) self.assertEqual(len(bonds), n) uids = set() for index, bond in enumerate(bonds): self.assertIsInstance(bond, Bond) compare_data_containers(bond.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(bond.particles), n) uids.update(bond.particles) self.assertEqual(len(uids), n * n)
def test_get_data(self): saved_keys = self.saved_keys data = create_data_container(restrict=saved_keys) data1 = DataContainer(data) key = saved_keys[0] data[key] = dummy_cuba_value(key) + dummy_cuba_value(key) with self.new_table('my_data_table') as table: table.append(data) table.append(data1) with self.open_table('my_data_table') as table: self.assertEqual(len(table), 2) self.assertDataContainersEqual(table[0], data) self.assertDataContainersEqual(table[1], data1)
def test_compare_nodes_not_equal(self): # given node = LatticeNode(index=(0, 2, 1), data=create_data_container()) reference = LatticeNode(index=(1, 2, 1), data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_lattice_nodes(node, reference, testcase=self) # given node = LatticeNode(index=(0, 2, 1), data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_lattice_nodes(node, reference, testcase=self) # given node = LatticeNode((0, 0, 0)) # when/then with self.assertRaises(AssertionError): compare_lattice_nodes(node, reference, testcase=self)
def test_compare_bonds_not_equal(self): # given particles = [uuid.uuid4(), uuid.uuid4()], bond = Bond(uid=uuid.uuid4(), particles=particles, data=create_data_container()) reference = Bond(uid=uuid.uuid4(), particles=particles, data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self) # given bond = Bond(uid=reference.uid, particles=particles[-1], data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self) # given bond = Bond(uid=uuid.uuid4(), particles=particles, data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self) # given bond = Bond([None]) # when/then with self.assertRaises(AssertionError): compare_bonds(bond, reference, testcase=self)
def test_compare_elements_not_equal(self): # given points = [uuid.uuid4(), uuid.uuid4(), uuid.uuid4()], element = Element(uid=uuid.uuid4(), points=points, data=create_data_container()) reference = Element(uid=uuid.uuid4(), points=points, data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self) # given element = Element(uid=reference.uid, points=points[1:], data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self) # given element = Element(uid=reference.uid, points=points, data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self) # given element = Element(points=[]) # when/then with self.assertRaises(AssertionError): compare_elements(element, reference, testcase=self)
def test_append_data(self): with self.new_table('my_data_table') as table: uids = {table.append(data): data for data in self.data_list} with self.open_table('my_data_table') as table: self.assertEqual(len(table), 4) for uid, data in uids.iteritems(): if len(data) <= len(self.saved_keys): self.assertDataContainersEqual(table[uid], data) else: # special case for custom records since they do not # store the full set of keys self.assertDataContainersEqual( table[uid], create_data_container(restrict=self.saved_keys))
def test_create_factory(self): n_containers = 7 n_items = self.itemsPerContainer containers = self.container_factory(n=n_containers, items=None) self.assertEqual(len(containers), n_containers) uids = set() for index, container in enumerate(containers): self.assertIsInstance(container, self.classtype) compare_data_containers(container.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(container.points), n_items) uids.update(container.points) self.assertLessEqual(len(uids), n_containers * n_items)
def test_delete_data(self): saved_keys = self.saved_keys data = create_data_container(restrict=saved_keys) with self.new_table('my_data_table') as table: uid0 = table.append(data) new_data = DataContainer(data) key = saved_keys[0] data[key] = dummy_cuba_value(key) + dummy_cuba_value(key) uid1 = table.append(new_data) with self.open_table('my_data_table', mode='a') as table: del table[uid0] loaded_data = table[uid1] self.assertEqual(len(table), 1) self.assertDataContainersEqual(loaded_data, new_data)
def test_compare_particles_not_equal(self): # given particle = Particle(uid=uuid.uuid4(), coordinates=(10.0, 0.0, 2.0), data=create_data_container()) reference = Particle(uid=uuid.uuid4(), coordinates=(10.0, 0.0, 2.0), data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_particles(particle, reference, testcase=self) # given particle = Particle(uid=reference.uid, coordinates=(340.0, 0.0, 2.0), data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_particles(particle, reference, testcase=self) # given particle = Particle(uid=reference.uid, coordinates=(10.0, 0.0, 2.0), data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_particles(particle, reference, testcase=self) # given particle = Particle() # when/then with self.assertRaises(AssertionError): compare_particles(particle, reference, testcase=self)
def test_compare_points_not_equal(self): # given point = Point(uid=uuid.uuid4(), coordinates=(10.0, 0.0, 2.0), data=create_data_container()) reference = Point(uid=uuid.uuid4(), coordinates=(10.0, 0.0, 2.0), data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_points(point, reference, testcase=self) # given point = Point(uid=reference.uid, coordinates=(10.0, 30.0, 2.0), data=create_data_container()) # when/then with self.assertRaises(AssertionError): compare_points(point, reference, testcase=self) # given point = Point(uid=reference.uid, coordinates=(10.0, 0.0, 2.0), data=DataContainer()) # when/then with self.assertRaises(AssertionError): compare_points(point, reference, testcase=self) # given point = Point((0, 0, 0)) # when/then with self.assertRaises(AssertionError): compare_points(point, reference, testcase=self)
def test_delete_data_with_invalid_uid(self): saved_keys = self.saved_keys data = create_data_container(restrict=saved_keys) with self.new_table('my_data_table') as table: uid0 = table.append(data) new_data = DataContainer(data) key = saved_keys[0] data[key] = dummy_cuba_value(key) + dummy_cuba_value(key) table.append(new_data) with self.open_table('my_data_table', mode='a') as table: del table[uid0] with self.assertRaises(KeyError): del table[uuid.uuid4()] with self.assertRaises(KeyError): del table[uid0]
def test_create_bonds_with_particles(self): n = 7 particles = create_particles(n=100) for particle in particles: particle.uid = uuid.uuid4() bonds = create_bonds(n=n, particles=particles) uids = set() self.assertEqual(len(bonds), n) for index, bond in enumerate(bonds): self.assertIsInstance(bond, Bond) compare_data_containers(bond.data, create_data_container(constant=index), testcase=self) self.assertEqual(len(bond.particles), n) uids.update(bond.particles) self.assertLessEqual(len(uids), n**2)
def test_delete_data_to_empty_table(self): data = create_data_container() with self.new_table('my_data_table') as table: uid = table.append(data) with closing(tables.open_file(self.filename, mode='a')) as handle: root = handle.root table = DataContainerTable( root, 'my_data_table', record=self.record) del table[uid] self.assertEqual(len(table), 0) # The table is recreated we need to make sure that the right # record is used. data_column = root.my_data_table.colinstances['data'] expected_column_names = [ key.name.lower() for key in self.saved_keys] self.assertItemsEqual( data_column._v_colnames, expected_column_names)
def test_update_data(self): with self.new_table('my_data_table') as table: uids = OrderedDict() for data in self.data_list: uids[table.append(data)] = data with self.open_table('my_data_table', mode='a') as table: updated_data = [data for data in reversed(self.data_list)] for uid in uids: for data in updated_data: table[uid] = data if len(data) <= len(self.saved_keys): self.assertDataContainersEqual(table[uid], data) else: # special case for custom records since they do not # store the full set of keys self.assertDataContainersEqual( table[uid], create_data_container(restrict=self.saved_keys))
def test_iteration(self): # create sample data data = [] saved_keys = self.saved_keys for key in saved_keys: data_container = create_data_container(restrict=saved_keys) del data_container[key] data.append(data_container) # add to data container table with self.new_table('my_data_table') as table: for data_container in data: table.append(data_container) self.assertEqual(len(table), len(saved_keys)) # Iterate over all the rows with self.open_table('my_data_table') as table: for index, loaded_data in enumerate(table): self.assertDataContainersEqual(loaded_data, data[index]) self.assertEqual(index, len(saved_keys) - 1)
def test_create_data_container_with_constant(self): data = create_data_container(constant=7) keys = set(CUBA) self.assertEqual(set(data), keys) for cuba, value in data.iteritems(): assert_array_equal(value, dummy_cuba_value(cuba, 7))