def test_validate_dataset_reports_problem_when_expected_dataset_is_not_present( ): nexus_wrapper = NexusWrapper() nexus_wrapper.set_field_value(nexus_wrapper.nexus_file, "a_dataset", 0) dataset_name = "test_dataset" validator = ValidateDataset(dataset_name) problems = [] validator.check(nexus_wrapper.nexus_file, problems) assert ( len(problems) > 0 ), "Expected there to be a reported problem because dataset is not present"
def test_validate_dataset_reports_problem_when_expected_attribute_is_not_present( ): nexus_wrapper = NexusWrapper() dataset_name = "test_dataset" nexus_wrapper.set_field_value(nexus_wrapper.nexus_file, dataset_name, 0) validator = ValidateDataset(dataset_name, attributes={"test_attribute": None}) problems = [] validator.check(nexus_wrapper.nexus_file, problems) assert ( len(problems) > 0 ), "Expected there to be a reported problem because attribute is not present"
def record_faces_in_file(nexus_wrapper: nx.NexusWrapper, group: h5py.Group, new_faces: List[List[int]]): """ Record face data in file :param nexus_wrapper: Wrapper for the file the data will be stored in :param group: The shape group node :param new_faces: The new face data, list of list for each face with indices of vertices in face """ winding_order = [index for new_face in new_faces for index in new_face] nexus_wrapper.set_field_value(group, "winding_order", winding_order) faces_length = [0] faces_length.extend([len(new_face) for new_face in new_faces[:-1]]) faces_start_indices = np.cumsum(faces_length) nexus_wrapper.set_field_value(group, "faces", faces_start_indices)
def test_validate_dataset_does_not_report_problem_when_dataset_has_expected_shape( ): nexus_wrapper = NexusWrapper() dataset_name = "test_dataset" dataset_value = np.array(list(range(12))) dataset_shape = (3, 4) dataset_value = np.reshape(dataset_value, dataset_shape) nexus_wrapper.set_field_value(nexus_wrapper.nexus_file, dataset_name, dataset_value) validator = ValidateDataset(dataset_name, shape=dataset_shape) problems = [] validator.check(nexus_wrapper.nexus_file, problems) assert ( len(problems) == 0 ), "Expected there to be no reported problem because dataset has expected shape"
def record_vertices_in_file(nexus_wrapper: nx.NexusWrapper, group: h5py.Group, new_vertices: List[QVector3D]): """ Record vertex data in file :param nexus_wrapper: Wrapper for the file the data will be stored in :param group: The shape group node :param new_vertices: The new vertices data, list of cartesian coords for each vertex """ vertices = [qvector3d_to_numpy_array(vertex) for vertex in new_vertices] vertices_node = nexus_wrapper.set_field_value(group, CommonAttrs.VERTICES, vertices) nexus_wrapper.set_attribute_value(vertices_node, CommonAttrs.UNITS, "m")
def test_validate_dataset_does_not_report_problem_when_attribute_has_expected_value( ): nexus_wrapper = NexusWrapper() dataset_name = "test_dataset" dataset = nexus_wrapper.set_field_value(nexus_wrapper.nexus_file, dataset_name, 0) attr_name = "test_attribute" attr_value = 42 nexus_wrapper.set_attribute_value(dataset, attr_name, attr_value) validator = ValidateDataset(dataset_name, attributes={attr_name: attr_value}) problems = [] validator.check(nexus_wrapper.nexus_file, problems) assert ( len(problems) == 0 ), "Expected there to be no reported problem because attribute has expected value"