From 690af580c9639b772a2a013b4bc4322f885123c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Nov 2020 08:58:40 +1100 Subject: [PATCH] autotest: abstract out load_local_module() this will be useful for other tests --- Tools/autotest/arducopter.py | 19 +++++++------------ Tools/autotest/pysim/util.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 4f527f4e9e..201dffc48a 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -5339,22 +5339,17 @@ class AutoTestCopter(AutoTest): self.progress("Running replay") - shutil.rmtree("logs/replay", ignore_errors=True) - util.run_cmd(['build/linux/tools/Replay', '--log-directory=logs/replay', '--', current_log_filepath], + util.run_cmd(['build/sitl/tools/Replay', current_log_filepath], directory=util.topdir(), checkfail=True, show=True) self.context_pop() - check_replay_py = os.path.join(util.topdir(), "Tools/Replay/check_replay.py") - if sys.version_info.major >= 3: - import importlib.util - spec = importlib.util.spec_from_file_location("check_replay", check_replay_py) - check_replay = importlib.util.module_from_spec(spec) - spec.loader.exec_module(check_replay) - else: - import imp - check_replay = imp.load_source("check_replay", os.path.join(util.topdir(), "Tools/Replay/check_replay.py")) - ok = check_replay.check_log("logs/replay/00000001.BIN", self.progress) + replay_log_filepath = self.current_onboard_log_filepath() + self.progress("Replay log path: %s" % str(replay_log_filepath)) + + check_replay = util.load_local_module("Tools/Replay/check_replay.py") + + ok = check_replay.check_log(replay_log_filepath, self.progress) if not ok: raise NotAchievedException("check_replay failed") diff --git a/Tools/autotest/pysim/util.py b/Tools/autotest/pysim/util.py index 5b96537f5b..684fcb4478 100644 --- a/Tools/autotest/pysim/util.py +++ b/Tools/autotest/pysim/util.py @@ -758,6 +758,19 @@ def constrain(value, minv, maxv): value = maxv return value +def load_local_module(filename): + '''load a python module from within the ardupilot tree''' + filename = os.path.join(topdir(), filename) + if sys.version_info.major >= 3: + import importlib.util + spec = importlib.util.spec_from_file_location("local_module", filename) + ret = importlib.util.module_from_spec(spec) + spec.loader.exec_module(ret) + else: + import imp + ret = imp.load_source("local_module", filename) + return ret + if __name__ == "__main__": import doctest