Skip to content

Commit

Permalink
Fix writevtk: pass str to write_data fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinvis committed Nov 24, 2022
1 parent a8e5da7 commit 7229449
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions pymech/vtksuite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for converting :class:`pymech.core.HexaData` objects to vtk"""
import os
from itertools import product
from pathlib import Path

Expand Down Expand Up @@ -188,8 +189,9 @@ def writevtk(fname, data):
"""
ext = ".vtp"
fname = Path(fname)
if not fname.suffix != ext:
if fname.suffix != ext:
logger.info(f"Renaming {fname} with extension .vtp")
fname = fname.with_suffix(ext)

vtk_dataset = exa2vtk(data)
write_data(vtk_dataset, fname)
write_data(vtk_dataset, os.fspath(fname))
12 changes: 7 additions & 5 deletions tests/test_vtk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests experimental vtksuite"""
from pathlib import Path
import pytest

try:
Expand All @@ -13,11 +14,12 @@
not TVTK_INSTALLED, reason="Package mayavi / tvtk is not installed "
)
@pytest.mark.parametrize("downsample", (True, False))
def test_writevtk(test_data_dir, downsample):
def test_writevtk(downsample, test_data_dir, tmpdir):
from pymech import readnek
from pymech.vtksuite import writevtk

fname = f"{test_data_dir}/nek/channel3D_0.f00001"
field = readnek(fname)
writevtk(fname, field)
assert fname.with_suffix(".vtp").exists()
in_fname = Path(test_data_dir) / "nek" / "channel3D_0.f00001"
out_fname = Path(tmpdir / in_fname.name)
field = readnek(in_fname)
writevtk(out_fname, field)
assert out_fname.with_suffix(".vtp").exists()

0 comments on commit 7229449

Please sign in to comment.