File: test_compress_decompress.py

package info (click to toggle)
python-laspy 2.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,928 kB
  • sloc: python: 9,065; makefile: 20
file content (126 lines) | stat: -rw-r--r-- 3,272 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import numpy as np
import pytest

import laspy

from ..test_common import skip_if_no_laz_backend
from . import skip_if_cli_deps_are_not_installed

skip_if_cli_deps_are_not_installed()

pytestmark = skip_if_no_laz_backend

from typer.testing import CliRunner

runner = CliRunner()
from laspy.cli.core import app


def test_cli_compress(tmp_path):
    input_path = "tests/data/simple.las"
    output_path = tmp_path / "simple.laz"
    result = runner.invoke(
        app,
        [
            "compress",
            input_path,
            "--output-path",
            str(output_path),
        ],
    )
    assert result.exit_code == 0, "{}".format(result.stdout)

    with laspy.open(output_path) as f:
        assert f.header.are_points_compressed is True

    original_las = laspy.read(input_path)
    compressed_las = laspy.read(output_path)

    assert original_las.point_format == compressed_las.point_format
    assert original_las.vlrs == compressed_las.vlrs
    assert np.all(original_las.points == compressed_las.points)


def test_cli_compress_cannot_overwrite(tmp_path):
    input_path = "tests/data/simple.las"
    output_path = tmp_path / "simple.laz"
    result = runner.invoke(
        app,
        [
            "compress",
            input_path,
            "--output-path",
            input_path,
        ],
    )
    assert result.exit_code != 0, "{}".format(result.stdout)


def test_cli_compress_non_existing_file(tmp_path):
    input_path = "tests/data/i-do-not-exist.las"
    output_path = tmp_path / "i-do-not-exist.laz"
    result = runner.invoke(
        app,
        [
            "compress",
            input_path,
            "--output-path",
            str(output_path),
        ],
    )
    assert result.exit_code != 0, "{}".format(result.stdout)


def test_cli_decompress(tmp_path):
    input_path = "tests/data/simple.laz"
    output_path = tmp_path / "simple.las"
    result = runner.invoke(
        app,
        [
            "decompress",
            input_path,
            "--output-path",
            str(output_path),
        ],
    )
    assert result.exit_code == 0, "{}".format(result.stdout)

    with laspy.open(output_path) as f:
        assert f.header.are_points_compressed is False

    original_las = laspy.read(input_path)
    compressed_las = laspy.read(output_path)

    assert original_las.point_format == compressed_las.point_format
    assert original_las.vlrs == compressed_las.vlrs
    assert np.all(original_las.points == compressed_las.points)


def test_cli_decompress_cannot_overwrite(tmp_path):
    input_path = "tests/data/simple.laz"
    output_path = tmp_path / "simple.las"
    result = runner.invoke(
        app,
        [
            "decompress",
            input_path,
            "--output-path",
            input_path,
        ],
    )
    assert result.exit_code != 0, "{}".format(result.stdout)


def test_cli_decompress_non_existing_file(tmp_path):
    input_path = "tests/data/i-do-not-exist.laz"
    output_path = tmp_path / "i-do-not-exist.las"
    result = runner.invoke(
        app,
        [
            "decompress",
            input_path,
            "--output-path",
            str(output_path),
        ],
    )
    assert result.exit_code != 0, "{}".format(result.stdout)