mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-24 01:28:29 -04:00
Tools: autotest.py: total flake8 compliance.
This commit is contained in:
parent
7ddb4d681d
commit
39c96f63c8
@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
APM automatic test suite
|
APM automatic test suite.
|
||||||
Andrew Tridgell, October 2011
|
|
||||||
|
Andrew Tridgell, October 2011
|
||||||
|
|
||||||
AP_FLAKE8_CLEAN
|
AP_FLAKE8_CLEAN
|
||||||
"""
|
"""
|
||||||
@ -40,11 +41,12 @@ tester = None
|
|||||||
|
|
||||||
|
|
||||||
def buildlogs_dirpath():
|
def buildlogs_dirpath():
|
||||||
|
"""Return BUILDLOGS directory path."""
|
||||||
return os.getenv("BUILDLOGS", util.reltopdir("../buildlogs"))
|
return os.getenv("BUILDLOGS", util.reltopdir("../buildlogs"))
|
||||||
|
|
||||||
|
|
||||||
def buildlogs_path(path):
|
def buildlogs_path(path):
|
||||||
"""return a string representing path in the buildlogs directory"""
|
"""Return a string representing path in the buildlogs directory."""
|
||||||
bits = [buildlogs_dirpath()]
|
bits = [buildlogs_dirpath()]
|
||||||
if isinstance(path, list):
|
if isinstance(path, list):
|
||||||
bits.extend(path)
|
bits.extend(path)
|
||||||
@ -55,7 +57,6 @@ def buildlogs_path(path):
|
|||||||
|
|
||||||
def get_default_params(atype, binary):
|
def get_default_params(atype, binary):
|
||||||
"""Get default parameters."""
|
"""Get default parameters."""
|
||||||
|
|
||||||
# use rover simulator so SITL is not starved of input
|
# use rover simulator so SITL is not starved of input
|
||||||
HOME = mavutil.location(40.071374969556928,
|
HOME = mavutil.location(40.071374969556928,
|
||||||
-105.22978898137808,
|
-105.22978898137808,
|
||||||
@ -96,6 +97,7 @@ def get_default_params(atype, binary):
|
|||||||
|
|
||||||
|
|
||||||
def build_all_filepath():
|
def build_all_filepath():
|
||||||
|
"""Get build_all.sh path."""
|
||||||
return util.reltopdir('Tools/scripts/build_all.sh')
|
return util.reltopdir('Tools/scripts/build_all.sh')
|
||||||
|
|
||||||
|
|
||||||
@ -154,11 +156,13 @@ def build_unit_tests(**kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def run_unit_test(test):
|
def run_unit_test(test):
|
||||||
|
"""Run unit test file."""
|
||||||
print("Running (%s)" % test)
|
print("Running (%s)" % test)
|
||||||
subprocess.run([test], check=True)
|
subprocess.run([test], check=True)
|
||||||
|
|
||||||
|
|
||||||
def run_unit_tests():
|
def run_unit_tests():
|
||||||
|
"""Run all unit tests files."""
|
||||||
binary_dir = util.reltopdir(os.path.join('build',
|
binary_dir = util.reltopdir(os.path.join('build',
|
||||||
'linux',
|
'linux',
|
||||||
'tests',
|
'tests',
|
||||||
@ -180,6 +184,7 @@ def run_unit_tests():
|
|||||||
|
|
||||||
|
|
||||||
def run_clang_scan_build():
|
def run_clang_scan_build():
|
||||||
|
"""Run Clang Scan-build utility."""
|
||||||
if util.run_cmd("scan-build python waf configure",
|
if util.run_cmd("scan-build python waf configure",
|
||||||
directory=util.reltopdir('.')) != 0:
|
directory=util.reltopdir('.')) != 0:
|
||||||
print("Failed scan-build-configure")
|
print("Failed scan-build-configure")
|
||||||
@ -199,10 +204,12 @@ def run_clang_scan_build():
|
|||||||
|
|
||||||
|
|
||||||
def param_parse_filepath():
|
def param_parse_filepath():
|
||||||
|
"""Get param_parse.py script path."""
|
||||||
return util.reltopdir('Tools/autotest/param_metadata/param_parse.py')
|
return util.reltopdir('Tools/autotest/param_metadata/param_parse.py')
|
||||||
|
|
||||||
|
|
||||||
def all_vehicles():
|
def all_vehicles():
|
||||||
|
"""Get all vehicles name."""
|
||||||
return ('ArduPlane',
|
return ('ArduPlane',
|
||||||
'ArduCopter',
|
'ArduCopter',
|
||||||
'Rover',
|
'Rover',
|
||||||
@ -222,6 +229,7 @@ def build_parameters():
|
|||||||
|
|
||||||
|
|
||||||
def mavtogpx_filepath():
|
def mavtogpx_filepath():
|
||||||
|
"""Get mavtogpx script path."""
|
||||||
return util.reltopdir("modules/mavlink/pymavlink/tools/mavtogpx.py")
|
return util.reltopdir("modules/mavlink/pymavlink/tools/mavtogpx.py")
|
||||||
|
|
||||||
|
|
||||||
@ -311,6 +319,7 @@ __bin_names = {
|
|||||||
|
|
||||||
|
|
||||||
def binary_path(step, debug=False):
|
def binary_path(step, debug=False):
|
||||||
|
"""Get vehicle binary path."""
|
||||||
try:
|
try:
|
||||||
vehicle = step.split(".")[1]
|
vehicle = step.split(".")[1]
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -341,6 +350,7 @@ def binary_path(step, debug=False):
|
|||||||
|
|
||||||
|
|
||||||
def split_specific_test_step(step):
|
def split_specific_test_step(step):
|
||||||
|
"""Extract test from argument."""
|
||||||
print('step=%s' % str(step))
|
print('step=%s' % str(step))
|
||||||
m = re.match("((fly|drive|dive|test)[.][^.]+)[.](.*)", step)
|
m = re.match("((fly|drive|dive|test)[.][^.]+)[.](.*)", step)
|
||||||
if m is None:
|
if m is None:
|
||||||
@ -349,6 +359,7 @@ def split_specific_test_step(step):
|
|||||||
|
|
||||||
|
|
||||||
def find_specific_test_to_run(step):
|
def find_specific_test_to_run(step):
|
||||||
|
"""Find test to run in argument."""
|
||||||
t = split_specific_test_step(step)
|
t = split_specific_test_step(step)
|
||||||
if t is None:
|
if t is None:
|
||||||
return None
|
return None
|
||||||
@ -384,6 +395,7 @@ suplementary_test_binary_map = {
|
|||||||
|
|
||||||
|
|
||||||
def run_specific_test(step, *args, **kwargs):
|
def run_specific_test(step, *args, **kwargs):
|
||||||
|
"""Run a specific test."""
|
||||||
t = split_specific_test_step(step)
|
t = split_specific_test_step(step)
|
||||||
if t is None:
|
if t is None:
|
||||||
return []
|
return []
|
||||||
@ -406,7 +418,6 @@ def run_specific_test(step, *args, **kwargs):
|
|||||||
|
|
||||||
def run_step(step):
|
def run_step(step):
|
||||||
"""Run one step."""
|
"""Run one step."""
|
||||||
|
|
||||||
# remove old logs
|
# remove old logs
|
||||||
util.run_cmd('/bin/rm -f logs/*.BIN logs/LASTLOG.TXT')
|
util.run_cmd('/bin/rm -f logs/*.BIN logs/LASTLOG.TXT')
|
||||||
|
|
||||||
@ -548,7 +559,9 @@ def run_step(step):
|
|||||||
|
|
||||||
class TestResult(object):
|
class TestResult(object):
|
||||||
"""Test result class."""
|
"""Test result class."""
|
||||||
|
|
||||||
def __init__(self, name, result, elapsed):
|
def __init__(self, name, result, elapsed):
|
||||||
|
"""Init test result class."""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.result = result
|
self.result = result
|
||||||
self.elapsed = "%.1f" % elapsed
|
self.elapsed = "%.1f" % elapsed
|
||||||
@ -556,14 +569,18 @@ class TestResult(object):
|
|||||||
|
|
||||||
class TestFile(object):
|
class TestFile(object):
|
||||||
"""Test result file."""
|
"""Test result file."""
|
||||||
|
|
||||||
def __init__(self, name, fname):
|
def __init__(self, name, fname):
|
||||||
|
"""Init test result file."""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.fname = fname
|
self.fname = fname
|
||||||
|
|
||||||
|
|
||||||
class TestResults(object):
|
class TestResults(object):
|
||||||
"""Test results class."""
|
"""Test results class."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""Init test results class."""
|
||||||
self.date = time.asctime()
|
self.date = time.asctime()
|
||||||
self.githash = util.run_cmd('git rev-parse HEAD',
|
self.githash = util.run_cmd('git rev-parse HEAD',
|
||||||
output=True,
|
output=True,
|
||||||
@ -597,10 +614,7 @@ class TestResults(object):
|
|||||||
self.addimage(name, os.path.basename(f))
|
self.addimage(name, os.path.basename(f))
|
||||||
|
|
||||||
def generate_badge(self):
|
def generate_badge(self):
|
||||||
"""
|
"""Get the badge template, populates and saves the result to buildlogs path."""
|
||||||
Gets the badge template, populates and saves the result to buildlogs
|
|
||||||
path.
|
|
||||||
"""
|
|
||||||
passed_tests = len([t for t in self.tests if "PASSED" in t.result])
|
passed_tests = len([t for t in self.tests if "PASSED" in t.result])
|
||||||
total_tests = len(self.tests)
|
total_tests = len(self.tests)
|
||||||
badge_color = "#4c1" if passed_tests == total_tests else "#e05d44"
|
badge_color = "#4c1" if passed_tests == total_tests else "#e05d44"
|
||||||
@ -803,7 +817,10 @@ if __name__ == "__main__":
|
|||||||
os.putenv('TMPDIR', util.reltopdir('tmp'))
|
os.putenv('TMPDIR', util.reltopdir('tmp'))
|
||||||
|
|
||||||
class MyOptionParser(optparse.OptionParser):
|
class MyOptionParser(optparse.OptionParser):
|
||||||
|
"""Custom option parse class."""
|
||||||
|
|
||||||
def format_epilog(self, formatter):
|
def format_epilog(self, formatter):
|
||||||
|
"""Retun customized option parser epilog."""
|
||||||
return self.epilog
|
return self.epilog
|
||||||
|
|
||||||
parser = MyOptionParser(
|
parser = MyOptionParser(
|
||||||
|
Loading…
Reference in New Issue
Block a user