don't litter tmpdir when testing
import tempfile
+from pathlib import Path
import helpers
import numpy as np
@@ -17,20 +18,31 @@ def is_same_mesh(mesh0, mesh1, atol):
def test_info():
input_mesh = helpers.tri_mesh
- infile = tempfile.NamedTemporaryFile().name
+ with tempfile.TemporaryDirectory() as tmpdir:
+ tmpdir = Path(tmpdir)
+ infile = tmpdir / "out.msh"
meshio.write(infile, input_mesh, file_format="gmsh")
- meshio._cli.info([infile, "--input-format", "gmsh"])
+ meshio._cli.info([str(infile), "--input-format", "gmsh"])
def test_convert():
input_mesh = helpers.tri_mesh
- infile = tempfile.NamedTemporaryFile().name
- meshio.write(infile, input_mesh, file_format="gmsh")
- outfile = tempfile.NamedTemporaryFile().name
+ with tempfile.TemporaryDirectory() as tmpdir:
+ tmpdir = Path(tmpdir)
+ infile = tmpdir / "in.msh"
+ meshio.write(infile, input_mesh, file_format="gmsh")
+ outfile = tmpdir / "out.msh"
meshio._cli.convert(
- [infile, outfile, "--input-format", "gmsh", "--output-format", "vtk"]
+ [
+ str(infile),
+ str(outfile),
+ "--input-format",
+ "gmsh",
+ "--output-format",
+ "vtk",
+ ]
)
mesh = meshio.read(outfile, file_format="vtk")
@@ -45,27 +57,33 @@ def test_convert():
def test_compress():
input_mesh = helpers.tri_mesh
- infile = tempfile.NamedTemporaryFile(suffix=".vtu").name
+
+ with tempfile.TemporaryDirectory() as tmpdir:
+ tmpdir = Path(tmpdir)
+ infile = tmpdir / "in.vtu"
meshio.write(infile, input_mesh)
- meshio._cli.decompress([infile])
+ meshio._cli.decompress([str(infile)])
mesh = meshio.read(infile)
assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)
- meshio._cli.compress([infile])
+ meshio._cli.compress([str(infile)])
mesh = meshio.read(infile)
assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)
def test_ascii_binary():
input_mesh = helpers.tri_mesh
- infile = tempfile.NamedTemporaryFile(suffix=".vtk").name
+
+ with tempfile.TemporaryDirectory() as tmpdir:
+ tmpdir = Path(tmpdir)
+ infile = tmpdir / "in.vtu"
meshio.write(infile, input_mesh)
- meshio._cli.ascii([infile])
+ meshio._cli.ascii([str(infile)])
mesh = meshio.read(infile)
- assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)
+ assert is_same_mesh(input_mesh, mesh, atol=1.0e-12)
- meshio._cli.binary([infile])
+ meshio._cli.binary([str(infile)])
mesh = meshio.read(infile)
- assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)
+ assert is_same_mesh(input_mesh, mesh, atol=1.0e-12)
