mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-30 19:18:31 +00:00
python: Add __eq__ to Mtd classes
Also programatically iterate all of the base classes to register them. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8237>
This commit is contained in:
parent
ad4fa052e5
commit
86bac82c8e
2 changed files with 25 additions and 7 deletions
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue