-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_e57.py
More file actions
164 lines (130 loc) · 4.44 KB
/
test_e57.py
File metadata and controls
164 lines (130 loc) · 4.44 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import e57
import numpy as np
import pytest
def test_raw_xml():
raw_xml = e57.raw_xml(r"testdata/bunnyFloat.e57")
assert "<?xml version" in raw_xml
def test_read_points():
pointcloud = e57.read_points(r"testdata/bunnyFloat.e57")
points = pointcloud.points
assert isinstance(points, np.ndarray)
assert len(points) == 30_571
def test_read_spherical():
pointcloud = e57.read_points(r"testdata/pipeSpherical.e57")
points = pointcloud.points
assert isinstance(points, np.ndarray)
assert len(points) == 1_220
def test_read_color():
pointcloud = e57.read_points(r"testdata/pipeSpherical.e57")
color = pointcloud.color
assert isinstance(color, np.ndarray)
assert len(color) == 1_220
def test_read_intensity():
pointcloud = e57.read_points(r"testdata/pipeSpherical.e57")
intensity = pointcloud.intensity
assert isinstance(intensity, np.ndarray)
assert len(intensity) == 1_220
assert np.all(intensity >= 0.3935)
assert np.all(intensity <= 0.5555)
def test_no_rgb_intensity():
pointcloud = e57.read_points(r"testdata/bunnyFloat.e57")
intensity = pointcloud.intensity
assert isinstance(intensity, np.ndarray)
assert len(intensity) == 0
def test_box_dimensions():
pointcloud: np.ndarray = e57.read_points(r"testdata/bunnyFloat.e57")
points = pointcloud.points
max_coords = points.max(0, None, False, -np.inf)
min_coords = points.min(0, None, False, np.inf)
X, Y, Z = max_coords - min_coords
assert X == pytest.approx(0.155698)
assert Y == pytest.approx(0.14731)
assert Z == pytest.approx(0.120672)
def test_global_box_center():
pointcloud: np.ndarray = e57.read_points(r"testdata/bunnyFloat.e57")
max_coords = pointcloud.points.max(0, None, False, -np.inf)
min_coords = pointcloud.points.min(0, None, False, np.inf)
X, Y, Z = (max_coords + min_coords) / 2
assert X == pytest.approx(-0.016840)
assert Y == pytest.approx(0.113666)
assert Z == pytest.approx(-0.001537)
def test_file_not_found():
raised = False
try:
e57.read_points(r"testdata/filenotfound.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Unable to open file" in str(e)
assert raised
def test_empty_file():
raised = False
try:
e57.read_points(r"testdata/empty.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Failed to read E57 file header" in str(e)
assert raised
def test_invalid_file():
raised = False
try:
e57.read_points(r"testdata/invalid.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Failed to read E57 file header" in str(e)
assert raised
def test_just_xml():
raised = False
try:
e57.read_points(r"testdata/justxml.e57")
except RuntimeError as e:
raised = True
assert "Invalid E57 content" in str(e)
assert "Found unsupported signature in header" in str(e)
assert raised
def test_raw_xml_file_not_found():
raised = False
try:
e57.raw_xml(r"testdata/filenotfound.e57")
except FileNotFoundError:
raised = True
assert raised
def test_raw_xml_empty():
raised = False
try:
e57.raw_xml(r"testdata/empty.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Cannot read page size bytes" in str(e)
assert raised
def test_raw_xml_invalid():
raised = False
try:
e57.raw_xml(r"testdata/invalid.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Cannot read page size bytes" in str(e)
assert raised
def test_raw_xml_just_xml():
raised = False
try:
e57.raw_xml(r"testdata/justxml.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Failed creating paged CRC reader" in str(e)
assert raised
def test_read_images():
e57_data = e57.read_images(r"testdata/pipeSpherical.e57")
images = e57_data.images
metadata = e57_data.metadata
assert isinstance(images, list)
assert all(isinstance(img, np.ndarray) for img in images)
assert isinstance(metadata, list)
assert all(isinstance(meta, str) for meta in metadata)
assert len(images) == 6
assert len(metadata) == 6