-
Notifications
You must be signed in to change notification settings - Fork 92
/
model_test.py
148 lines (130 loc) · 5.29 KB
/
model_test.py
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
# Copyright (C) 2021 - 2023 Christian Ledermann
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Test the kml overlay classes."""
from pygeoif.geometry import Point
import fastkml.links
import fastkml.model
from fastkml.enums import AltitudeMode
from tests.base import Lxml
from tests.base import StdLibrary
class TestModel(StdLibrary):
def test_from_string(self) -> None:
doc = (
'<Model xmlns="http://www.opengis.net/kml/2.2">'
"<altitudeMode>absolute</altitudeMode>"
"<Location>"
"<longitude>-123.115776547816</longitude>"
"<latitude>49.279804095564</latitude>"
"<altitude>21.614010375743</altitude>"
"</Location>"
"<Scale><x>1</x><y>1</y><z>1</z></Scale>"
"<Link><href>http://barcelona.galdos.local/files/PublicLibrary.dae</href></Link>"
'<ResourceMap id="map01">'
"<Alias>"
"<targetHref>http://barcelona.galdos.local/images/Concrete2.jpg</targetHref>"
"<sourceHref>../images/Concrete.jpg</sourceHref>"
"</Alias>"
"</ResourceMap>"
"</Model>"
)
model = fastkml.model.Model.from_string(doc)
assert model.altitude_mode == AltitudeMode.absolute
assert model.geometry == Point(
-123.115776547816,
49.279804095564,
21.614010375743,
)
assert model == fastkml.model.Model(
altitude_mode=AltitudeMode.absolute,
location=fastkml.model.Location(
altitude=21.614010375743,
latitude=49.279804095564,
longitude=-123.115776547816,
),
orientation=None,
scale=fastkml.model.Scale(
x=1.0,
y=1.0,
z=1.0,
),
link=fastkml.links.Link(
href="http://barcelona.galdos.local/files/PublicLibrary.dae",
),
resource_map=fastkml.model.ResourceMap(
aliases=[
fastkml.model.Alias(
target_href="http://barcelona.galdos.local/images/Concrete2.jpg",
source_href="../images/Concrete.jpg",
),
],
),
)
def test_from_string_no_location(self) -> None:
doc = (
'<Model xmlns="http://www.opengis.net/kml/2.2">'
"<altitudeMode>absolute</altitudeMode>"
"<Scale><x>1</x><y>1</y><z>1</z></Scale>"
"<Link><href>http://barcelona.galdos.local/files/PublicLibrary.dae</href></Link>"
'<ResourceMap id="map01">'
"<Alias>"
"<targetHref>http://barcelona.galdos.local/images/Concrete2.jpg</targetHref>"
"<sourceHref>../images/Concrete.jpg</sourceHref>"
"</Alias>"
"</ResourceMap>"
"</Model>"
)
model = fastkml.model.Model.from_string(doc)
assert model.altitude_mode == AltitudeMode.absolute
assert model.geometry is None
assert not model
def test_from_string_invalid_location(self) -> None:
doc = (
'<Model xmlns="http://www.opengis.net/kml/2.2">'
"<altitudeMode>absolute</altitudeMode>"
"<Location>"
"<longitude></longitude>"
"<latitude>49.279804095564</latitude>"
"<altitude>21.614010375743</altitude>"
"</Location>"
"<Scale><x>1</x><y>1</y><z>1</z></Scale>"
"<Link><href>http://barcelona.galdos.local/files/PublicLibrary.dae</href></Link>"
'<ResourceMap id="map01">'
"<Alias>"
"<targetHref>http://barcelona.galdos.local/images/Concrete2.jpg</targetHref>"
"<sourceHref>../images/Concrete.jpg</sourceHref>"
"</Alias>"
"</ResourceMap>"
"</Model>"
)
model = fastkml.model.Model.from_string(doc)
assert model.altitude_mode == AltitudeMode.absolute
assert model.geometry is None
assert not model
def test_location_from_string_invalid_location(self) -> None:
doc = (
'<Location xmlns="http://www.opengis.net/kml/2.2">'
"<longitude></longitude>"
"<latitude>49.279804095564</latitude>"
"<altitude>21.614010375743</altitude>"
"</Location>"
)
location = fastkml.model.Location.from_string(doc)
assert location.altitude == 21.614010375743
assert location.latitude == 49.279804095564
assert location.geometry is None
assert not location
class TestModelLxml(TestModel, Lxml):
pass