Browse Source

Tools: autotest: python3 fixes

Tools: autotest: use inbuilt zip on Python3
mission-4.1.18
Peter Barker 6 years ago committed by Peter Barker
parent
commit
9ca2c9d692
  1. 6
      Tools/autotest/arducopter.py
  2. 16
      Tools/autotest/common.py

6
Tools/autotest/arducopter.py

@ -1408,7 +1408,7 @@ class AutoTestCopter(AutoTest):
self.reboot_sitl() self.reboot_sitl()
# without a GPS or some sort of external prompting, AP # without a GPS or some sort of external prompting, AP
# doesn't send system_time messages. So prompt it: # doesn't send system_time messages. So prompt it:
self.mav.mav.system_time_send(time.time() * 1000000, 0) self.mav.mav.system_time_send(int(time.time() * 1000000), 0)
self.mav.mav.set_gps_global_origin_send(1, self.mav.mav.set_gps_global_origin_send(1,
old_pos.lat, old_pos.lat,
old_pos.lon, old_pos.lon,
@ -2485,8 +2485,8 @@ class AutoTestCopter(AutoTest):
self.mav.mav.mount_control_send( self.mav.mav.mount_control_send(
1, # target system 1, # target system
1, # target component 1, # target component
t_lat * 1e7, # lat int(t_lat * 1e7), # lat
t_lon * 1e7, # lon int(t_lon * 1e7), # lon
t_alt * 100, # alt t_alt * 100, # alt
0 # save position 0 # save position
) )

16
Tools/autotest/common.py

@ -29,6 +29,11 @@ if sys.version_info[0] >= 3 and sys.version_info[1] >= 4:
else: else:
ABC = abc.ABCMeta('ABC', (), {}) ABC = abc.ABCMeta('ABC', (), {})
try:
from itertools import izip as zip
except ImportError:
# probably python2
pass
class ErrorException(Exception): class ErrorException(Exception):
"""Base class for other exceptions""" """Base class for other exceptions"""
@ -528,7 +533,7 @@ class AutoTest(ABC):
self.progress("Comparing (%s) and (%s)" % (file1, file2, )) self.progress("Comparing (%s) and (%s)" % (file1, file2, ))
f1 = open(file1) f1 = open(file1)
f2 = open(file2) f2 = open(file2)
for l1, l2 in itertools.izip(f1, f2): for l1, l2 in zip(f1, f2):
l1 = l1.rstrip("\r\n") l1 = l1.rstrip("\r\n")
l2 = l2.rstrip("\r\n") l2 = l2.rstrip("\r\n")
if l1 == l2: if l1 == l2:
@ -543,7 +548,7 @@ class AutoTest(ABC):
fields2 = re.split("\s+", l2) fields2 = re.split("\s+", l2)
# line = int(fields1[0]) # line = int(fields1[0])
t = int(fields1[3]) # mission item type t = int(fields1[3]) # mission item type
for (count, (i1, i2)) in enumerate(itertools.izip(fields1, fields2)): for (count, (i1, i2)) in enumerate(zip(fields1, fields2)):
if count == 2: # frame if count == 2: # frame
if t in [mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED, if t in [mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED,
mavutil.mavlink.MAV_CMD_CONDITION_YAW, mavutil.mavlink.MAV_CMD_CONDITION_YAW,
@ -1737,7 +1742,12 @@ class AutoTest(ABC):
test_function() test_function()
except Exception as e: except Exception as e:
self.test_timings[desc] = time.time() - start_time self.test_timings[desc] = time.time() - start_time
self.progress("Exception caught: %s" % traceback.format_exc(e)) try:
stacktrace = traceback.format_exc(e)
except Exception:
# seems to be broken under Python3:
stacktrace = "stacktrace unavailable"
self.progress("Exception caught: %s" % stacktrace)
self.context_pop() self.context_pop()
self.progress('FAILED: "%s": %s (see %s)' % self.progress('FAILED: "%s": %s (see %s)' %
(prettyname, repr(e), test_output_filename)) (prettyname, repr(e), test_output_filename))

Loading…
Cancel
Save