Tools: autotest: python3 fixes

Tools: autotest: use inbuilt zip on Python3
This commit is contained in:
Peter Barker 2019-03-13 17:12:28 +11:00 committed by Peter Barker
parent fa082df040
commit 9ca2c9d692
2 changed files with 16 additions and 6 deletions

View File

@ -1408,7 +1408,7 @@ class AutoTestCopter(AutoTest):
self.reboot_sitl()
# without a GPS or some sort of external prompting, AP
# 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,
old_pos.lat,
old_pos.lon,
@ -2485,8 +2485,8 @@ class AutoTestCopter(AutoTest):
self.mav.mav.mount_control_send(
1, # target system
1, # target component
t_lat * 1e7, # lat
t_lon * 1e7, # lon
int(t_lat * 1e7), # lat
int(t_lon * 1e7), # lon
t_alt * 100, # alt
0 # save position
)

View File

@ -29,6 +29,11 @@ if sys.version_info[0] >= 3 and sys.version_info[1] >= 4:
else:
ABC = abc.ABCMeta('ABC', (), {})
try:
from itertools import izip as zip
except ImportError:
# probably python2
pass
class ErrorException(Exception):
"""Base class for other exceptions"""
@ -528,7 +533,7 @@ class AutoTest(ABC):
self.progress("Comparing (%s) and (%s)" % (file1, file2, ))
f1 = open(file1)
f2 = open(file2)
for l1, l2 in itertools.izip(f1, f2):
for l1, l2 in zip(f1, f2):
l1 = l1.rstrip("\r\n")
l2 = l2.rstrip("\r\n")
if l1 == l2:
@ -543,7 +548,7 @@ class AutoTest(ABC):
fields2 = re.split("\s+", l2)
# line = int(fields1[0])
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 t in [mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED,
mavutil.mavlink.MAV_CMD_CONDITION_YAW,
@ -1737,7 +1742,12 @@ class AutoTest(ABC):
test_function()
except Exception as e:
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.progress('FAILED: "%s": %s (see %s)' %
(prettyname, repr(e), test_output_filename))