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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8090>
This commit is contained in:
Alicia Boya García 2024-12-06 18:13:07 +01:00 committed by GStreamer Marge Bot
parent 184ac2d930
commit 482c029c53
3 changed files with 34 additions and 48 deletions

View file

@ -22,6 +22,7 @@ import os
import copy import copy
import sys import sys
import time import time
from types import SimpleNamespace
import urllib.parse import urllib.parse
import shlex import shlex
import socket import socket
@ -33,7 +34,7 @@ import math
from launcher.loggable import Loggable, error from launcher.loggable import Loggable, error
from launcher.baseclasses import GstValidateTest, Test, \ from launcher.baseclasses import GstValidateTest, Test, \
ScenarioManager, NamedDic, GstValidateTestsGenerator, \ ScenarioManager, GstValidateTestsGenerator, \
GstValidateMediaDescriptor, GstValidateEncodingTestInterface, \ GstValidateMediaDescriptor, GstValidateEncodingTestInterface, \
GstValidateBaseTestManager, MediaDescriptor, MediaFormatCombination, VariableFramerateMode 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(): if test_rtsp and protocol == Protocols.FILE and not minfo.media_descriptor.is_image():
rtspminfo = NamedDic({"path": minfo.media_descriptor.get_path(), rtspminfo = SimpleNamespace(path=minfo.media_descriptor.get_path(),
"media_descriptor": GstValidateRTSPMediaDescriptor(minfo.media_descriptor.get_path())}) media_descriptor=GstValidateRTSPMediaDescriptor(minfo.media_descriptor.get_path()))
if not rtspminfo.media_descriptor.is_compatible(scenario): if not rtspminfo.media_descriptor.is_compatible(scenario):
self.debug("Skipping (media descriptor is not compatible for rtsp test): %s", fname) self.debug("Skipping (media descriptor is not compatible for rtsp test): %s", fname)
continue 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( special_scenarios = self.scenarios_manager.find_special_scenarios(
scenario_bname) scenario_bname)
self._uris.append((uri, self._uris.append((uri,
NamedDic({"path": media_info, SimpleNamespace(path=media_info,
"media_descriptor": media_descriptor}), media_descriptor=media_descriptor),
special_scenarios)) special_scenarios))
except configparser.NoOptionError as e: except configparser.NoOptionError as e:
self.debug("Exception: %s for %s", e, media_info) self.debug("Exception: %s for %s", e, media_info)
@ -1276,22 +1277,6 @@ not been tested and explicitly activated if you set use --wanted-tests ALL""")
""" """
Registers default test scenarios 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([ self.add_scenarios([
"play_15s", "play_15s",
"reverse_playback", "reverse_playback",
@ -1387,7 +1372,12 @@ not been tested and explicitly activated if you set use --wanted-tests ALL""")
if self._default_generators_registered: if self._default_generators_registered:
return return
self.add_generators([GstValidatePlaybinTestsGenerator(self), self.add_generators([
# <testsuitename>.*.playback.*
GstValidatePlaybinTestsGenerator(self),
# <testsuitename>.*.media_check.*
GstValidateMediaCheckTestsGenerator(self), GstValidateMediaCheckTestsGenerator(self),
GstValidateTranscodingTestsGenerator(self)]) # <testsuitename>.*.transcode.to_*.*
GstValidateTranscodingTestsGenerator(self)
])
self._default_generators_registered = True self._default_generators_registered = True

View file

@ -2402,14 +2402,6 @@ class _TestsLauncher(Loggable):
return True return True
class NamedDic(object):
def __init__(self, props):
if props:
for name, value in props.items():
setattr(self, name, value)
class Scenario(object): class Scenario(object):
def __init__(self, name, props, path=None): def __init__(self, name, props, path=None):

View file

@ -20,6 +20,7 @@
""" """
The GstValidate default testsuite The GstValidate default testsuite
""" """
from __future__ import annotations
import os import os
import glob import glob
@ -30,8 +31,11 @@ import subprocess
from testsuiteutils import update_assets from testsuiteutils import update_assets
from launcher import utils from launcher import utils
from launcher.baseclasses import MediaFormatCombination 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 validate_known_issues import KNOWN_ISSUES
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from launcher.main import LauncherConfig
TEST_MANAGER = "validate" 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__))) 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")) media_dir = os.path.realpath(os.path.join(testsuite_dir, os.path.pardir, "medias"))