File: test_non_seekable.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 (90 lines) | stat: -rw-r--r-- 2,891 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
import pytest

import laspy
from laspy import VLR

from .conftest import (
    LAS_1_4_WITH_EVLRS_FILE_PATH,
    LAZ_1_4_WITH_EVLRS_FILE_PATH,
    NonSeekableStream,
    las_file_path,
    laz_file_path,
)
from .test_chunk_read_write import check_chunked_reading_gives_expected_points

EXPECTED_EVLRS = [
    VLR(
        user_id="pylastest",
        record_id=42,
        description="just a test evlr",
        record_data=b"Test 1 2 ... 1 2",
    )
]


@pytest.mark.skipif(
    not laspy.LazBackend.Lazrs.is_available(),
    reason="None seekable laz is only supported by lazrs",
)
def test_laz_reading_non_seekable_stream(laz_file_path):
    with open(laz_file_path, mode="rb") as f:
        stream = NonSeekableStream(f)
        laspy.read(stream, closefd=False)


def test_las_reading_non_seekable_stream(las_file_path):
    with open(las_file_path, mode="rb") as f:
        stream = NonSeekableStream(f)
        laspy.read(stream, closefd=False)


@pytest.mark.skipif(
    not laspy.LazBackend.Lazrs.is_available(),
    reason="Non seekable laz is only supported by lazrs",
)
def test_laz_selective_decompression_reading_non_seekable_stream():
    with open(LAZ_1_4_WITH_EVLRS_FILE_PATH, mode="rb") as f:
        stream = NonSeekableStream(f)
        selection = laspy.DecompressionSelection.base()
        las = laspy.read(stream, closefd=False, decompression_selection=selection)
        assert las.evlrs == EXPECTED_EVLRS


@pytest.mark.skipif(
    not laspy.LazBackend.Lazrs.is_available(),
    reason="Non seekable laz is only supported by lazrs",
)
def test_laz_with_evlr_reading_non_seekable_stream():
    with open(LAZ_1_4_WITH_EVLRS_FILE_PATH, mode="rb") as f:
        stream = NonSeekableStream(f)
        las = laspy.read(stream, closefd=False)
        assert las.evlrs == EXPECTED_EVLRS


def test_las_with_evlr_reading_non_seekable_stream(las_file_path):
    with open(LAS_1_4_WITH_EVLRS_FILE_PATH, mode="rb") as f:
        stream = NonSeekableStream(f)
        las = laspy.read(stream, closefd=False)
        assert las.evlrs == EXPECTED_EVLRS


def test_non_seekable_chunked_las_reading(las_file_path):
    ground_truth = laspy.read(las_file_path)
    with open(las_file_path, mode="rb") as raw_file:
        las_reader = laspy.open(NonSeekableStream(raw_file), closefd=False)
        check_chunked_reading_gives_expected_points(
            ground_truth, las_reader, iter_size=130
        )


@pytest.mark.skipif(
    not laspy.LazBackend.Lazrs.is_available(),
    reason="Non seekable laz is only supported by lazrs",
)
def test_non_seekable_chunked_laz_reading(laz_file_path):
    ground_truth = laspy.read(laz_file_path)
    with open(laz_file_path, mode="rb") as raw_file:
        las_reader = laspy.open(NonSeekableStream(raw_file), closefd=False)
        check_chunked_reading_gives_expected_points(
            ground_truth, las_reader, iter_size=130
        )