forked from Open-MSS/MSS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a04e7ee
commit 6a41a4d
Showing
9 changed files
with
239 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
mslib.utils.verify_waypoint_data | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
basic checks for xml waypoint data. | ||
This file is part of MSS. | ||
:copyright: Copyright 2024 Reimar Bauer | ||
:license: APACHE-2.0, see LICENSE for details. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
|
||
import xml.dom.minidom | ||
import xml.parsers.expat | ||
|
||
|
||
def verify_waypoint_data(xml_content): | ||
try: | ||
doc = xml.dom.minidom.parseString(xml_content) | ||
except xml.parsers.expat.ExpatError: | ||
return False | ||
|
||
ft_el = doc.getElementsByTagName("FlightTrack")[0] | ||
waypoints = ft_el.getElementsByTagName("Waypoint") | ||
if (len(waypoints)) < 2: | ||
return False | ||
|
||
for wp_el in ft_el.getElementsByTagName("Waypoint"): | ||
try: | ||
wp_el.getAttribute("location") | ||
float(wp_el.getAttribute("lat")) | ||
float(wp_el.getAttribute("lon")) | ||
float(wp_el.getAttribute("flightlevel")) | ||
wp_el.getElementsByTagName("Comments")[0] | ||
except ValueError: | ||
return False | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
tests._test_utils.test_verify_xml_waypoint | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This tests for valid xml data of waypoint data. | ||
This file is part of MSS. | ||
:copyright: Copyright 2024 Reimar Bauer | ||
:license: APACHE-2.0, see LICENSE for details. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from mslib.utils.verify_waypoint_data import verify_waypoint_data | ||
|
||
|
||
def test_verify_xml_waypoint(): | ||
xml_content = ( | ||
("""<?xml version="1.0" encoding="utf-8"?> | ||
<FlightTrack version="9.0.0"> | ||
<ListOfWaypoints> | ||
<Waypoint flightlevel="233.0" lat="41.601070573320186" location="" lon="41.355120439498535"> | ||
<Comments></Comments> | ||
</Waypoint> | ||
<Waypoint flightlevel="374.0" lat="48.19354838709677" location="" lon="33.74841526975632"> | ||
<Comments></Comments> | ||
</Waypoint> | ||
<Waypoint flightlevel="372.0" lat="51.23623045499366" location="" lon="-34.20481757994082"> | ||
<Comments></Comments> | ||
</Waypoint> | ||
<Waypoint flightlevel="20.0" lat="37.037047471474835" location="" lon="-40.797295393717434"> | ||
<Comments></Comments> | ||
</Waypoint> | ||
</ListOfWaypoints> | ||
</FlightTrack>""", True), | ||
("""<?xml version="1.0" encoding="utf-8"?> | ||
<FlightTrack version="9.0.0"> | ||
<ListOfWaypoints> | ||
</ListOfWaypoints> | ||
</FlightTrack>""", False), | ||
) | ||
|
||
|
||
for xml, check in xml_content: | ||
assert verify_waypoint_data(xml) is check |
Oops, something went wrong.