From 86bac82c8e542ff52477e5d0a61a72b00c076fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Mon, 20 Jan 2025 14:53:36 -0600 Subject: [PATCH] python: Add __eq__ to Mtd classes Also programatically iterate all of the base classes to register them. Part-of: --- .../gst-python/gi/overrides/GstAnalytics.py | 30 +++++++++++++++---- .../gst-python/testsuite/test_analytics.py | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-python/gi/overrides/GstAnalytics.py b/subprojects/gst-python/gi/overrides/GstAnalytics.py index 7369c83278..bffae5ff44 100644 --- a/subprojects/gst-python/gi/overrides/GstAnalytics.py +++ b/subprojects/gst-python/gi/overrides/GstAnalytics.py @@ -35,11 +35,30 @@ _gi_gst_analytics __mtd_types__ = {} -def init(): - __mtd_types__[GstAnalytics.ODMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_od_mtd - __mtd_types__[GstAnalytics.ClsMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_cls_mtd - __mtd_types__[GstAnalytics.TrackingMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_tracking_mtd - __mtd_types__[GstAnalytics.SegmentationMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_segmentation_mtd +class Mtd(GstAnalytics.Mtd): + def __eq__(self, other): + if not hasattr(other, 'meta') or not hasattr(other, 'id'): + return False + return self.meta == other.meta and self.id == other.id + + +__all__.append('Mtd') + + +def _wrap_mtd(module, name, getter): + baseclass = getattr(module, name) + wrapper = type(name, (baseclass, Mtd), {}) + globals()[name] = wrapper + + __mtd_types__[baseclass.get_mtd_type()] = getter + __all__.append(name) + + +for c in dir(GstAnalytics): + if c.endswith('Mtd') and c != 'Mtd': + lower_c = c[:-3].lower() + getter = getattr(GstAnalytics.RelationMeta, 'get_' + lower_c + '_mtd') + _wrap_mtd(GstAnalytics, c, getter) def _get_mtd(mtd_type, rmeta, mtd_id): @@ -55,4 +74,3 @@ class RelationMeta(GstAnalytics.RelationMeta): __all__.append('RelationMeta') -__all__.append('init') diff --git a/subprojects/gst-python/testsuite/test_analytics.py b/subprojects/gst-python/testsuite/test_analytics.py index bf83827722..7a989aa087 100644 --- a/subprojects/gst-python/testsuite/test_analytics.py +++ b/subprojects/gst-python/testsuite/test_analytics.py @@ -37,7 +37,6 @@ from gi.repository import Gst from gi.repository import GstAnalytics from gi.repository import GstVideo Gst.init(None) -GstAnalytics.init() class TestAnalyticsODMtd(TestCase): @@ -280,6 +279,7 @@ class TestAnalyticsRelationMetaIterator(TestCase): self.assertEqual(len(mtds), len(mtds_from_iter)) for e, i in zip(mtds, rmeta): + assert i == e[0] assert e[0].id == i.id assert e[0].meta == i.meta assert e[1] == i.get_mtd_type()