refactor: Refactor arrayHelpers functions#223
Open
RomainBaville wants to merge 12 commits intomainfrom
Open
Conversation
paloma-martinez
requested changes
Feb 13, 2026
| - get the attribute and they number of component on one piece of a mesh (one for dataset, one for multiblockDataset and one for the both) | ||
| - get all the cells dimension of a mesh (for any meshes) | ||
| - get the GlobalIds array on one piece of a mesh (for any meshes) | ||
| - get the vtk or array data of an attribute (dataset and vtkFieldData only) |
Collaborator
There was a problem hiding this comment.
Suggested change
| - get the vtk or array data of an attribute (dataset and vtkFieldData only) | |
| - get the vtk or data array of an attribute (dataset and vtkFieldData only) |
| piece: Piece, | ||
| ) -> tuple[ list[ Any ], list[ Any ] ]: | ||
| """Check if each value is valid , ie if that value is a data of the attribute in at least one dataset of the multiblock. | ||
| """Check if each value is valid, ie if that value is a data of the mesh's attribute. |
Collaborator
There was a problem hiding this comment.
Suggested change
| """Check if each value is valid, ie if that value is a data of the mesh's attribute. | |
| """Check if each value is valid, ie if that value is a data of the mesh attribute. |
| dict[str, int]: Dictionary of the names of the attributes as keys, and number of components as values. | ||
| Raises: | ||
| ValueError: The piece must be cells or points only | ||
| AttributeError: One attribute one the mesh is null. |
Collaborator
There was a problem hiding this comment.
Suggested change
| AttributeError: One attribute one the mesh is null. | |
| AttributeError: One attribute of the mesh is null. |
geos-mesh/tests/test_arrayHelpers.py
Outdated
Comment on lines
142
to
156
| def test_getAttributesWithNumberOfComponentsRaises() -> None: | ||
| """Test the fails of the function getAttributesWithNumberOfComponents.""" | ||
| # ValueError | ||
| with pytest.raises( ValueError ): | ||
| arrayHelpers.getAttributesWithNumberOfComponents( vtkPolyData(), Piece.BOTH ) | ||
|
|
||
| # AttributeError | ||
| mesh: vtkPolyData = vtkPolyData() | ||
| mesh.GetCellData().AddArray( vtkDoubleArray() ) | ||
| with pytest.raises( AttributeError ): | ||
| arrayHelpers.getAttributesWithNumberOfComponents( mesh, Piece.CELLS ) | ||
|
|
||
| # TypeError | ||
| with pytest.raises( TypeError ): | ||
| arrayHelpers.getAttributesWithNumberOfComponents( vtkCellData(), Piece.CELLS ) |
Collaborator
There was a problem hiding this comment.
In order to improve maintainability and clarity, I would avoid testing several test case in the same function as you're doing here.
geos-mesh/tests/test_arrayHelpers.py
Outdated
Comment on lines
276
to
285
| def test_checkValidValuesInObjectRaises( dataSetTest: Any ) -> None: | ||
| """Test the fails of checkValidValuesInObject.""" | ||
| # AttributeError | ||
| mesh: vtkMultiBlockDataSet = dataSetTest( "multiblock" ) | ||
| with pytest.raises( AttributeError ): | ||
| arrayHelpers.checkValidValuesInObject( mesh, "PORO", [], Piece.CELLS ) | ||
|
|
||
| @pytest.mark.parametrize( "piece, expected", [ ( Piece.POINTS, { | ||
| 'GLOBAL_IDS_POINTS': 1, | ||
| 'PointAttribute': 3, | ||
| } ), ( Piece.CELLS, { | ||
| 'CELL_MARKERS': 1, | ||
| 'PERM': 3, | ||
| 'PORO': 1, | ||
| 'FAULT': 1, | ||
| 'GLOBAL_IDS_CELLS': 1, | ||
| 'CellAttribute': 3, | ||
| } ) ] ) | ||
| def test_getAttributesFromDataSet( dataSetTest: vtkDataSet, piece: Piece, expected: dict[ str, int ] ) -> None: | ||
| """Test getting attribute list as dict from dataset.""" | ||
| vtkDataSetTest: vtkDataSet = dataSetTest( "dataset" ) | ||
| attributes: dict[ str, int ] = arrayHelpers.getAttributesFromDataSet( vtkDataSetTest, piece ) | ||
| assert attributes == expected | ||
| # TypeError | ||
| with pytest.raises( TypeError ): | ||
| arrayHelpers.checkValidValuesInObject( vtkCellData(), "AttributeName", [], Piece.CELLS ) |
Collaborator
There was a problem hiding this comment.
Same remark, please split the test cases.
geos-mesh/tests/test_arrayHelpers.py
Outdated
Comment on lines
368
to
377
| def test_getVtkArrayTypeInObjectRaises( dataSetTest: Any ) -> None: | ||
| """Test the fails of the function getVtkArrayTypeInObject.""" | ||
| # AttributeError | ||
| mesh: vtkDataSet = dataSetTest( "dataset" ) | ||
| with pytest.raises( AttributeError ): | ||
| arrayHelpers.getVtkArrayTypeInObject( mesh, "attributeName", Piece.CELLS ) | ||
|
|
||
| assert ( obtained == expected ) | ||
| # TypeError | ||
| with pytest.raises( TypeError ): | ||
| arrayHelpers.getVtkArrayTypeInObject( vtkCellData(), "PORO", Piece.CELLS ) |
geos-mesh/tests/test_arrayHelpers.py
Outdated
Comment on lines
418
to
432
| def test_getNumberOfComponentsRaises( dataSetTest: Any, ) -> None: | ||
| """Test getNumberOfComponents fails.""" | ||
| # TypeError | ||
| meshWrongType: vtkCellData = vtkCellData() | ||
| with pytest.raises( TypeError ): | ||
| arrayHelpers.getNumberOfComponents( mesh, "attribute", Piece.CELLS ) | ||
| arrayHelpers.getNumberOfComponents( meshWrongType, "PORO", Piece.CELLS ) | ||
|
|
||
| # AttributeError | ||
| mesh: vtkDataSet = dataSetTest( "multiblockGeosOutput" ) | ||
| with pytest.raises( AttributeError ): | ||
| arrayHelpers.getNumberOfComponents( mesh, "attributeName", Piece.POINTS ) | ||
|
|
||
| @pytest.mark.parametrize( "attributeName, piece, expected", [ | ||
| ( "PERM", Piece.CELLS, ( "AX1", "AX2", "AX3" ) ), | ||
| ( "PORO", Piece.CELLS, () ), | ||
| ] ) | ||
| def test_getComponentNamesDataSet( dataSetTest: vtkDataSet, attributeName: str, piece: Piece, | ||
| expected: tuple[ str, ...] ) -> None: | ||
| """Test getting the component names of an attribute from a dataset.""" | ||
| vtkDataSetTest: vtkDataSet = dataSetTest( "dataset" ) | ||
| obtained: tuple[ str, ...] = arrayHelpers.getComponentNamesDataSet( vtkDataSetTest, attributeName, piece ) | ||
| assert obtained == expected | ||
| # ValueError | ||
| with pytest.raises( ValueError ): | ||
| arrayHelpers.getNumberOfComponents( mesh, "ghostRank", Piece.BOTH ) |
geos-mesh/tests/test_arrayHelpers.py
Outdated
Comment on lines
449
to
465
| def test_getComponentNamesRaises( dataSetTest: Any, ) -> None: | ||
| """Test getting the component names fails.""" | ||
| # TypeError | ||
| meshWrongType: vtkFieldData = vtkFieldData() | ||
| with pytest.raises( TypeError ): | ||
| arrayHelpers.getComponentNames( meshWrongType, "PORO", Piece.CELLS ) | ||
|
|
||
| # AttributeError | ||
| mesh: vtkDataSet = dataSetTest( "multiblockGeosOutput" ) | ||
| with pytest.raises( AttributeError ): | ||
| arrayHelpers.getComponentNames( mesh, "attributeName", Piece.POINTS ) | ||
|
|
||
| # ValueError | ||
| with pytest.raises( ValueError ): | ||
| arrayHelpers.getComponentNames( mesh, "ghostRank", Piece.BOTH ) | ||
|
|
||
|
|
…nction Update to the last version of the main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr aims to refactor arrayHelpers functions to have just one function dealing with dataset or multiblock dataset instead of multiple functions.
During the factorisation of the arrayHelpers functions, a small clean is made in the tests to.