From 9ca2c9d692ebcb8238c42712d5d3e0ed66bd9255 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 13 Mar 2019 17:12:28 +1100 Subject: [PATCH] Tools: autotest: python3 fixes Tools: autotest: use inbuilt zip on Python3 --- Tools/autotest/arducopter.py | 6 +++--- Tools/autotest/common.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 1619d654a9..fef184ccda 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -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 ) diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index 8e8b51a58e..32ae8d0845 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -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))