Debian Codegraph @

tests/model_test.py

raw symbols SCIP
1 # Copyright (C) 2021 - 2023 Christian Ledermann
2 #
3 # This library is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation; either version 2.1 of the License, or (at your option)
6 # any later version.
7 #
8 # This library is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this library; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 """Test the kml overlay classes."""
18
19 from pygeoif.geometry import Point
20
21 import fastkml.links
22 import fastkml.model
23 from fastkml.enums import AltitudeMode
24 from fastkml.enums import Verbosity
25 from tests.base import Lxml
26 from tests.base import StdLibrary
27
28
29 class TestModel(StdLibrary):
30 def test_from_string(self) -> None:
31 doc = (
32 '<Model xmlns="http://www.opengis.net/kml/2.2">'
33 "<altitudeMode>absolute</altitudeMode>"
34 "<Location>"
35 "<longitude>-123.115776547816</longitude>"
36 "<latitude>49.279804095564</latitude>"
37 "<altitude>21.614010375743</altitude>"
38 "</Location>"
39 "<Scale><x>1</x><y>1</y><z>1</z></Scale>"
40 "<Link><href>http://barcelona.galdos.local/files/PublicLibrary.dae</href></Link>"
41 '<ResourceMap id="map01">'
42 "<Alias>"
43 "<targetHref>http://barcelona.galdos.local/images/Concrete2.jpg</targetHref>"
44 "<sourceHref>../images/Concrete.jpg</sourceHref>"
45 "</Alias>"
46 "</ResourceMap>"
47 "</Model>"
48 )
49
50 model = fastkml.model.Model.from_string(doc)
51
52 assert model.altitude_mode == AltitudeMode.absolute
53 assert model.geometry == Point(
54 -123.115776547816,
55 49.279804095564,
56 21.614010375743,
57 )
58 assert model == fastkml.model.Model(
59 altitude_mode=AltitudeMode.absolute,
60 location=fastkml.model.Location(
61 altitude=21.614010375743,
62 latitude=49.279804095564,
63 longitude=-123.115776547816,
64 ),
65 orientation=None,
66 scale=fastkml.model.Scale(
67 x=1.0,
68 y=1.0,
69 z=1.0,
70 ),
71 link=fastkml.links.Link(
72 href="http://barcelona.galdos.local/files/PublicLibrary.dae",
73 ),
74 resource_map=fastkml.model.ResourceMap(
75 id="map01",
76 aliases=[
77 fastkml.model.Alias(
78 target_href="http://barcelona.galdos.local/images/Concrete2.jpg",
79 source_href="../images/Concrete.jpg",
80 ),
81 ],
82 ),
83 )
84
85 def test_from_string_no_location(self) -> None:
86 doc = (
87 '<Model xmlns="http://www.opengis.net/kml/2.2">'
88 "<altitudeMode>absolute</altitudeMode>"
89 "<Scale><x>1</x><y>1</y><z>1</z></Scale>"
90 "<Link><href>http://barcelona.galdos.local/files/PublicLibrary.dae</href></Link>"
91 '<ResourceMap id="map01">'
92 "<Alias>"
93 "<targetHref>http://barcelona.galdos.local/images/Concrete2.jpg</targetHref>"
94 "<sourceHref>../images/Concrete.jpg</sourceHref>"
95 "</Alias>"
96 "</ResourceMap>"
97 "</Model>"
98 )
99
100 model = fastkml.model.Model.from_string(doc)
101
102 assert model.altitude_mode == AltitudeMode.absolute
103 assert model.geometry is None
104 assert not model
105
106 def test_from_string_invalid_location(self) -> None:
107 doc = (
108 '<Model xmlns="http://www.opengis.net/kml/2.2">'
109 "<altitudeMode>absolute</altitudeMode>"
110 "<Location>"
111 "<longitude></longitude>"
112 "<latitude>49.279804095564</latitude>"
113 "<altitude>21.614010375743</altitude>"
114 "</Location>"
115 "<Scale><x>1</x><y>1</y><z>1</z></Scale>"
116 "<Link><href>http://barcelona.galdos.local/files/PublicLibrary.dae</href></Link>"
117 '<ResourceMap id="map01">'
118 "<Alias>"
119 "<targetHref>http://barcelona.galdos.local/images/Concrete2.jpg</targetHref>"
120 "<sourceHref>../images/Concrete.jpg</sourceHref>"
121 "</Alias>"
122 "</ResourceMap>"
123 "</Model>"
124 )
125
126 model = fastkml.model.Model.from_string(doc)
127
128 assert model.altitude_mode == AltitudeMode.absolute
129 assert model.geometry is None
130 assert not model
131
132 def test_location_from_string_invalid_location(self) -> None:
133 doc = (
134 '<Location xmlns="http://www.opengis.net/kml/2.2">'
135 "<longitude></longitude>"
136 "<latitude>49.279804095564</latitude>"
137 "<altitude>21.614010375743</altitude>"
138 "</Location>"
139 )
140
141 location = fastkml.model.Location.from_string(doc)
142
143 assert location.altitude == 21.614010375743
144 assert location.latitude == 49.279804095564
145 assert location.geometry is None
146 assert not location
147
148 def test_scale_to_string_terse_default(self) -> None:
149 scale = fastkml.model.Scale(x=1.0, y=1.0, z=1.0)
150 xml = scale.to_string(verbosity=Verbosity.terse)
151
152 assert "x>1.0</" not in xml
153 assert "y>1.0</" not in xml
154 assert "z>1.0</" not in xml
155 assert not fastkml.model.Scale.from_string(xml)
156
157
158 class TestModelLxml(TestModel, Lxml):
159 pass