From 482c029c533ce902085218270c37c22686befbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alicia=20Boya=20Garc=C3=ADa?= Date: Fri, 6 Dec 2024 18:13:07 +0100 Subject: [PATCH] validate: miscellaneous Python cleanups I spent too much time trying to navigate validate Python code to figure out where a test was coming from. Hoping that it's slightly easier for the next person, this patch: * Adds type annotations to setup_tests(), for the sake of code navigation. * Adds comments matching each test generator with the patterns of test names it produces. * Removes an if statement in `register_default_scenarios()` where both branches have the same exact code with the same exact very long list. * Removes NamedDic [sic] and replaces it with SimpleNamespace from the standard library (3.3+) which has the same purpose and API. Part-of: --- .../validate/launcher/apps/gstvalidate.py | 66 ++++++++----------- .../validate/launcher/baseclasses.py | 8 --- .../testsuites/validate.py | 8 ++- 3 files changed, 34 insertions(+), 48 deletions(-) diff --git a/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py b/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py index 4ee06bc022..09aacc86b5 100644 --- a/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py +++ b/subprojects/gst-devtools/validate/launcher/apps/gstvalidate.py @@ -22,6 +22,7 @@ import os import copy import sys import time +from types import SimpleNamespace import urllib.parse import shlex import socket @@ -33,7 +34,7 @@ import math from launcher.loggable import Loggable, error from launcher.baseclasses import GstValidateTest, Test, \ - ScenarioManager, NamedDic, GstValidateTestsGenerator, \ + ScenarioManager, GstValidateTestsGenerator, \ GstValidateMediaDescriptor, GstValidateEncodingTestInterface, \ GstValidateBaseTestManager, MediaDescriptor, MediaFormatCombination, VariableFramerateMode @@ -488,8 +489,8 @@ class GstValidatePlaybinTestsGenerator(GstValidatePipelineTestsGenerator): ) if test_rtsp and protocol == Protocols.FILE and not minfo.media_descriptor.is_image(): - rtspminfo = NamedDic({"path": minfo.media_descriptor.get_path(), - "media_descriptor": GstValidateRTSPMediaDescriptor(minfo.media_descriptor.get_path())}) + rtspminfo = SimpleNamespace(path=minfo.media_descriptor.get_path(), + media_descriptor=GstValidateRTSPMediaDescriptor(minfo.media_descriptor.get_path())) if not rtspminfo.media_descriptor.is_compatible(scenario): self.debug("Skipping (media descriptor is not compatible for rtsp test): %s", fname) continue @@ -1133,8 +1134,8 @@ not been tested and explicitly activated if you set use --wanted-tests ALL""") special_scenarios = self.scenarios_manager.find_special_scenarios( scenario_bname) self._uris.append((uri, - NamedDic({"path": media_info, - "media_descriptor": media_descriptor}), + SimpleNamespace(path=media_info, + media_descriptor=media_descriptor), special_scenarios)) except configparser.NoOptionError as e: self.debug("Exception: %s for %s", e, media_info) @@ -1276,36 +1277,20 @@ not been tested and explicitly activated if you set use --wanted-tests ALL""") """ Registers default test scenarios """ - if self.options.long_limit != 0: - self.add_scenarios([ - "play_15s", - "reverse_playback", - "fast_forward", - "seek_forward", - "seek_backward", - "seek_with_stop", - "switch_audio_track", - "switch_audio_track_while_paused", - "switch_subtitle_track", - "switch_subtitle_track_while_paused", - "disable_subtitle_track_while_paused", - "change_state_intensive", - "scrub_forward_seeking"]) - else: - self.add_scenarios([ - "play_15s", - "reverse_playback", - "fast_forward", - "seek_forward", - "seek_backward", - "seek_with_stop", - "switch_audio_track", - "switch_audio_track_while_paused", - "switch_subtitle_track", - "switch_subtitle_track_while_paused", - "disable_subtitle_track_while_paused", - "change_state_intensive", - "scrub_forward_seeking"]) + self.add_scenarios([ + "play_15s", + "reverse_playback", + "fast_forward", + "seek_forward", + "seek_backward", + "seek_with_stop", + "switch_audio_track", + "switch_audio_track_while_paused", + "switch_subtitle_track", + "switch_subtitle_track_while_paused", + "disable_subtitle_track_while_paused", + "change_state_intensive", + "scrub_forward_seeking"]) def register_default_encoding_formats(self): """ @@ -1387,7 +1372,12 @@ not been tested and explicitly activated if you set use --wanted-tests ALL""") if self._default_generators_registered: return - self.add_generators([GstValidatePlaybinTestsGenerator(self), - GstValidateMediaCheckTestsGenerator(self), - GstValidateTranscodingTestsGenerator(self)]) + self.add_generators([ + # .*.playback.* + GstValidatePlaybinTestsGenerator(self), + # .*.media_check.* + GstValidateMediaCheckTestsGenerator(self), + # .*.transcode.to_*.* + GstValidateTranscodingTestsGenerator(self) + ]) self._default_generators_registered = True diff --git a/subprojects/gst-devtools/validate/launcher/baseclasses.py b/subprojects/gst-devtools/validate/launcher/baseclasses.py index 714ec73553..9686fcb83e 100644 --- a/subprojects/gst-devtools/validate/launcher/baseclasses.py +++ b/subprojects/gst-devtools/validate/launcher/baseclasses.py @@ -2402,14 +2402,6 @@ class _TestsLauncher(Loggable): return True -class NamedDic(object): - - def __init__(self, props): - if props: - for name, value in props.items(): - setattr(self, name, value) - - class Scenario(object): def __init__(self, name, props, path=None): diff --git a/subprojects/gst-integration-testsuites/testsuites/validate.py b/subprojects/gst-integration-testsuites/testsuites/validate.py index 92c0946d96..4496282b86 100644 --- a/subprojects/gst-integration-testsuites/testsuites/validate.py +++ b/subprojects/gst-integration-testsuites/testsuites/validate.py @@ -20,6 +20,7 @@ """ The GstValidate default testsuite """ +from __future__ import annotations import os import glob @@ -30,8 +31,11 @@ import subprocess from testsuiteutils import update_assets from launcher import utils from launcher.baseclasses import MediaFormatCombination -from launcher.apps.gstvalidate import GstValidateSimpleTestsGenerator +from launcher.apps.gstvalidate import GstValidateSimpleTestsGenerator, GstValidateTestManager from validate_known_issues import KNOWN_ISSUES +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from launcher.main import LauncherConfig TEST_MANAGER = "validate" @@ -96,7 +100,7 @@ def add_accurate_seek_tests(test_manager, media_dir, extra_data): ) -def setup_tests(test_manager, options): +def setup_tests(test_manager: GstValidateTestManager, options: LauncherConfig): testsuite_dir = os.path.realpath(os.path.join(os.path.dirname(__file__))) media_dir = os.path.realpath(os.path.join(testsuite_dir, os.path.pardir, "medias"))