Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions tests/test_mavlogdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"""
regression tests for mavlogdump.py
"""
import unittest
import os
import pkg_resources
import sys
import unittest
from pathlib import Path

here = Path(__file__).parent

class MAVLogDumpTest(unittest.TestCase):

Expand All @@ -21,9 +22,7 @@ def __init__(self, *args, **kwargs):

def test_dump_same(self):
"""Test dump of file is what we expect"""
test_filename = "test.BIN"
test_filepath = pkg_resources.resource_filename(__name__,
test_filename)
test_filepath = str(here / "test.BIN")
dump_filename = "tmp.dump"
os.system("mavlogdump.py %s >%s" % (test_filepath, dump_filename))
with open(dump_filename) as f:
Expand All @@ -33,8 +32,7 @@ def test_dump_same(self):
"test.BIN.dumped"]
success = False
for expected in possibles:
expected_filepath = pkg_resources.resource_filename(__name__,
expected)
expected_filepath = str(here / expected)
with open(expected_filepath) as e:
expected = e.read()

Expand Down
12 changes: 5 additions & 7 deletions tests/test_mavxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@
"""

import unittest
import pkg_resources
from pathlib import Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from pathlib import Path
import pathlib

and namespace the creation of the object


from pymavlink.generator.mavparse import MAVXML
from pymavlink.generator.mavparse import MAVParseError

here = Path(__file__).parent

class MAVXMLTest(unittest.TestCase):
"""
Class to test MAVXML
"""

def test_fields_number(self):
"""Test that a message can have at most 64 fields"""
test_filename = "64-fields.xml"
test_filepath = pkg_resources.resource_filename(__name__,
test_filename)
test_filepath = str(here / "64-fields.xml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this equivalent to what we did have? ie. this looks like it's trying to take out of an installed package space if that's where you currently are. It's very weird if that's not the case as you wouldn't need to use pkg_resources

xml = MAVXML(test_filepath)
count = len(xml.message[0].fields)
self.assertEqual(count, 64)

test_filename = "65-fields.xml"
test_filepath = pkg_resources.resource_filename(__name__,
test_filename)
test_filepath = str(here / "65-fields.xml")
with self.assertRaises(MAVParseError):
_ = MAVXML(test_filepath)

Expand Down
4 changes: 1 addition & 3 deletions tests/test_trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"""

import unittest
import os
import pkg_resources
import sys

from pymavlink import mavutil

class PayLoadTrimZeros(unittest.TestCase):
Expand Down
35 changes: 13 additions & 22 deletions tests/test_wp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
regression tests for mavwp.py
"""

import unittest
import os
import pkg_resources
import sys
import unittest
from pathlib import Path

os.environ["MAVLINK20"] = "1"

from pymavlink import mavwp
from pymavlink import mavutil

here = Path(__file__).parent

class MAVWPTest(unittest.TestCase):

"""
Expand Down Expand Up @@ -42,14 +43,9 @@ def makewp(self, seq):
seq, # wp.z
)

def make_wps(self):
# create waypoints
count = 4
waypoints = []
for i in range(count):
waypoints.append(self.makewp(i))

return waypoints
def make_wps(self, count: int = 4):
# create count waypoints
return [self.makewp(i) for i in range(count)]

def test_add_remove(self):
"""Test we can add/remove waypoints to/from mavwp"""
Expand All @@ -60,9 +56,9 @@ def test_add_remove(self):
waypoints = self.make_wps()

# make sure basic addition works
for i in range(len(waypoints)):
for i, waypoint in enumerate(waypoints):
self.assertEqual(loader.count(), i)
loader.add(waypoints[i])
loader.add(waypoint)
self.assertEqual(loader.count(), i+1)

self.assertEqual(loader.wp(0).seq, 0)
Expand All @@ -76,7 +72,6 @@ def test_add_remove(self):
self.assertEqual(loader.item(1).z, 1)
self.assertEqual(loader.item(2).z, 2)


# remove a middle one, make sure things get renumbered
loader.remove(waypoints[0])
self.assertEqual(loader.wp(0).seq, 0)
Expand Down Expand Up @@ -194,8 +189,6 @@ def test_wp_is_loiter(self):
self.assertFalse(loader.wp_is_loiter(1))
self.assertFalse(loader.wp_is_loiter(2))

assert True

def test_is_location_command(self):
loader = mavwp.MAVWPLoader()
self.assertFalse(loader.is_location_command(mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH))
Expand All @@ -213,13 +206,13 @@ def test_rally_load(self):
self.assertTrue(loader.is_location_command(mavutil.mavlink.MAV_CMD_NAV_RALLY_POINT))

# test loading a QGC WPL 110 file:
rally_filepath = pkg_resources.resource_filename(__name__, "rally-110.txt")
rally_filepath = str(here / "rally-110.txt")
loader.load(rally_filepath)
self.assertEqual(loader.count(), 2)
self.assertEqual(loader.wp(0).command, mavutil.mavlink.MAV_CMD_NAV_RALLY_POINT)

# test loading tradition "RALLY" style format:
rally_filepath = pkg_resources.resource_filename(__name__, "rally.txt")
rally_filepath = str(here / "rally.txt")
loader.load(rally_filepath)
self.assertEqual(loader.count(), 2)
self.assertEqual(loader.wp(0).command, mavutil.mavlink.MAV_CMD_NAV_RALLY_POINT)
Expand All @@ -233,15 +226,13 @@ def test_fence_load(self):
self.assertTrue(loader.is_location_command(mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION))

# test loading a QGC WPL 110 file:
fence_filepath = pkg_resources.resource_filename(__name__,
"fence-110.txt")
fence_filepath = str(here / "fence-110.txt")
loader.load(fence_filepath)
self.assertEqual(loader.count(), 10)
self.assertEqual(loader.wp(3).command, mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION)

# test loading tradition lat/lng-pair style format:
fence_filepath = pkg_resources.resource_filename(__name__,
"fence.txt")
fence_filepath = str(here / "fence.txt")
loader.load(fence_filepath)
# there are 6 lines in the file - one return point, four fence
# points and a "fence closing point". We don't store the
Expand Down