validate:launcher: Refactor the "main" function

- Move the parser code into a `LauncherConfig.create_parser()` method
- Remove the need to pass libsdir to the _TestsLauncher object
- Extract out a `setup_launcher_from_args` function
This commit is contained in:
Thibault Saunier 2019-01-25 22:13:28 -03:00 committed by Thibault Saunier
parent 1b3867b82d
commit 6665652cff
2 changed files with 220 additions and 208 deletions

View file

@ -1399,11 +1399,10 @@ class GstValidateTestsGenerator(TestsGenerator):
class _TestsLauncher(Loggable):
def __init__(self, libsdir):
def __init__(self):
Loggable.__init__(self)
self.libsdir = libsdir
self.options = None
self.testers = []
self.tests = []
@ -1419,15 +1418,12 @@ class _TestsLauncher(Loggable):
self.httpsrv = None
self.vfb_server = None
def _list_app_dirs(self):
app_dirs = []
app_dirs.append(os.path.join(self.libsdir, "apps"))
env_dirs = os.environ.get("GST_VALIDATE_APPS_DIR")
env_dirs = os.environ["GST_VALIDATE_APPS_DIR"]
if env_dirs is not None:
for dir_ in env_dirs.split(":"):
app_dirs.append(dir_)
sys.path.append(dir_)
return app_dirs
@ -1600,12 +1596,12 @@ class _TestsLauncher(Loggable):
if options.no_display:
self.vfb_server = get_virual_frame_buffer_server(options)
res = vfb_server.start()
res = self.vfb_server.start()
if res[0] is False:
printc("Could not start virtual frame server: %s" % res[1],
Colors.FAIL)
return False
os.environ["DISPLAY"] = vfb_server.display_id
os.environ["DISPLAY"] = self.vfb_server.display_id
return True
@ -1837,7 +1833,7 @@ class _TestsLauncher(Loggable):
if self.httpsrv:
self.httpsrv.stop()
if self.vfb_server:
vfb_server.stop()
self.vfb_server.stop()
self.clean_tests()
def final_report(self):

View file

@ -135,6 +135,9 @@ http://wiki.pitivi.org/wiki/Bug_reporting#Debug_logs).
dir(Protocols) if isinstance(getattr(Protocols, att), str) and not
att.startswith("_")]))
if "--help" not in sys.argv:
HELP = "Use --help for the full help"
QA_ASSETS = "gst-integration-testsuites"
MEDIAS_FOLDER = "medias"
DEFAULT_GST_QA_ASSETS_REPO = "https://gitlab.freedesktop.org/gstreamer/gst-integration-testsuites.git"
@ -342,18 +345,11 @@ class LauncherConfig(Loggable):
if path not in self.paths:
self.paths.append(path)
def main(libsdir):
if "--help" in sys.argv:
_help_message = HELP
else:
_help_message = "Use --help for the full help"
DEFAULT_TESTSUITES_DIRS.append(os.path.join(libsdir, "testsuites"))
@staticmethod
def create_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
prog='gst-validate-launcher', description=_help_message)
prog='gst-validate-launcher', description=HELP)
parser.add_argument('testsuites', metavar='N', nargs='*',
help="""Lets you specify a test to run, a testsuite name or a file where the testsuite to execute is defined.
@ -541,36 +537,56 @@ Note that all testsuite should be inside python modules, so the directory should
" including big media files")
assets_group.add_argument("--usage", action=PrintUsage,
help="Print usage documentation")
return parser
def setup_launcher_from_args(args):
loggable.init("GST_VALIDATE_LAUNCHER_DEBUG", True, False)
tests_launcher = _TestsLauncher(libsdir)
parser = LauncherConfig.create_parser()
tests_launcher = _TestsLauncher()
tests_launcher.add_options(parser)
if _help_message == HELP and which(LESS):
if "--help" in sys.argv and which(LESS):
tmpf = tempfile.NamedTemporaryFile(mode='r+')
parser.print_help(file=tmpf)
exit(os.system("%s %s" % (LESS, tmpf.name)))
os.system("%s %s" % (LESS, tmpf.name))
return False, None, None
options = LauncherConfig()
parser.parse_args(namespace=options)
parser.parse_args(args=args, namespace=options)
if not options.cleanup():
exit(1)
return False, None, None
if options.remote_assets_url and options.sync and not os.path.exists(options.clone_dir):
if not download_assets(options):
exit(1)
return False, None, None
# Ensure that the scenario manager singleton is ready to be used
ScenarioManager().config = options
if not tests_launcher.set_settings(options, []):
exit(1)
return False, None, None
return True, options, tests_launcher
def main(libsdir):
global LIBSDIR
LIBSDIR = libsdir
DEFAULT_TESTSUITES_DIRS.append(os.path.join(LIBSDIR, "testsuites"))
os.environ["GST_VALIDATE_APPS_DIR"] = os.path.join(
LIBSDIR, "apps") + os.pathsep + os.environ.get("GST_VALIDATE_APPS_DIR", "")
res, options, tests_launcher = setup_launcher_from_args(sys.argv[1:])
if res is False:
return 1
if options.list_tests:
if tests_launcher.list_tests() == -1:
printc("\nFailling as tests have been removed/added "
" (--fail-on-testlist-change)", Colors.FAIL)
exit(1)
return 1
tests = tests_launcher.tests
for test in tests: