File: test_cli.py

package info (click to toggle)
python-meshio 4.3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,464 kB
  • sloc: python: 13,177; makefile: 50
file content (71 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import tempfile

import helpers
import numpy as np

import meshio


def is_same_mesh(mesh0, mesh1, atol):
    if not np.allclose(mesh0.points, mesh1.points, atol=atol, rtol=0.0):
        return False
    for cells0, cells1 in zip(mesh0.cells, mesh1.cells):
        if cells0.type != cells1.type or not np.allclose(cells0.data, cells1.data):
            return False
    return True


def test_info():
    input_mesh = helpers.tri_mesh
    infile = tempfile.NamedTemporaryFile().name
    meshio.write(infile, input_mesh, file_format="gmsh")
    meshio._cli.info([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

    meshio._cli.convert(
        [infile, outfile, "--input-format", "gmsh", "--output-format", "vtk"]
    )

    mesh = meshio.read(outfile, file_format="vtk")

    atol = 1.0e-15
    assert np.allclose(input_mesh.points, mesh.points, atol=atol, rtol=0.0)

    for cells0, cells1 in zip(input_mesh.cells, mesh.cells):
        assert cells0.type == cells1.type
        assert np.allclose(cells0.data, cells1.data)


def test_compress():
    input_mesh = helpers.tri_mesh
    infile = tempfile.NamedTemporaryFile(suffix=".vtu").name
    meshio.write(infile, input_mesh)

    meshio._cli.decompress([infile])
    mesh = meshio.read(infile)
    assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)

    meshio._cli.compress([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
    meshio.write(infile, input_mesh)

    meshio._cli.ascii([infile])
    mesh = meshio.read(infile)
    assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)

    meshio._cli.binary([infile])
    mesh = meshio.read(infile)
    assert is_same_mesh(input_mesh, mesh, atol=1.0e-15)