-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mesh-io): add emscripten test_vtk
- Loading branch information
Showing
4 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
packages/mesh-io/python/itkwasm-mesh-io-emscripten/test/test_vtk_poly_data.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
|
||
if sys.version_info < (3,10): | ||
pytest.skip("Skipping pyodide tests on older Python", allow_module_level=True) | ||
|
||
from pytest_pyodide import run_in_pyodide | ||
from .fixtures import package_wheel, input_data | ||
|
||
@run_in_pyodide(packages=['micropip', 'numpy']) | ||
async def test_vtk_poly_data_async(selenium, package_wheel, input_data): | ||
import micropip | ||
await micropip.install(package_wheel) | ||
def write_input_data_to_fs(input_data, filename): | ||
with open(filename, 'wb') as fp: | ||
fp.write(input_data[filename]) | ||
|
||
from pathlib import Path | ||
from itkwasm import FloatTypes, IntTypes | ||
import numpy as np | ||
|
||
from itkwasm_mesh_io_emscripten import vtk_poly_data_read_mesh_async, vtk_poly_data_write_mesh_async | ||
|
||
def verify_mesh(mesh): | ||
assert mesh.meshType.dimension == 3 | ||
assert mesh.meshType.pointComponentType == FloatTypes.Float32 | ||
assert mesh.meshType.pointPixelComponentType == IntTypes.Int8 | ||
assert mesh.numberOfPoints == 2903 | ||
assert np.allclose(mesh.points.ravel()[0], 3.71636) | ||
assert np.allclose(mesh.points.ravel()[1], 2.34339) | ||
assert mesh.numberOfCells == 3263 | ||
assert mesh.cellBufferSize == 18856 | ||
assert mesh.cells[0] == 4 | ||
assert mesh.cells[1] == 4 | ||
assert mesh.cells[2] == 250 | ||
|
||
test_file_path = 'cow.vtk' | ||
write_input_data_to_fs(input_data, test_file_path) | ||
|
||
assert Path(test_file_path).exists() | ||
|
||
could_read, mesh = await vtk_poly_data_read_mesh_async(test_file_path) | ||
assert could_read | ||
verify_mesh(mesh) | ||
|
||
test_output_file_path = 'cow_out.vtk' | ||
|
||
use_compression = False | ||
could_write = await vtk_poly_data_write_mesh_async(mesh, test_output_file_path, use_compression) | ||
assert could_write | ||
|
||
could_read, mesh = await vtk_poly_data_read_mesh_async(test_output_file_path) | ||
assert could_read | ||
verify_mesh(mesh) |
This file contains 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