summaryrefslogtreecommitdiff
path: root/tests/python
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@igalia.com>2021-10-14 17:01:01 -0300
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-10-15 20:51:41 +0000
commit1babccfe503de346dfd9722348e2acead742b70a (patch)
treea773950d80c8024711180cad4fdae89f1035e5ed /tests/python
parentba79339d56299094d2aab12873e360d55c119b41 (diff)
downloadgstreamer-1babccfe503de346dfd9722348e2acead742b70a.tar.gz
python: Fix using overrides when not building PyGObject
Since 547570cd790f2b2e390edc1dfb5df4c7a33de45c we do not always build PyGObject and our development environment is broken when trying to use GStreamer python when built against system PyGObject with the following error importing Gst in there: ``` 12345678** (gst-plugin-scanner:710617): CRITICAL **: 11:45:02.343: can't find gi.repository.Gst Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/gi/repository/__init__.py", line 23, in <module> from ..importer import DynamicImporter File "/usr/lib64/python3.9/site-packages/gi/importer.py", line 33, in <module> from .overrides import load_overrides ImportError: cannot import name 'load_overrides' from 'gi.overrides' (/var/home/thiblahute/devel/gstreamer/gstreamer/subprojects/gst-editing-services/bindings/python/gi/overrides/__init__.py) Factory Details: ``` The approach to fixing it is to implement override `gi` in `gst-python/gi/` which we add to `PYTHONPATH`) and in there reset the `gi` module to the right place and we get overrides from paths from `_GI_OVERRIDES_PATH` we set in `gst-env.py` which points to all the overrides that will be installed. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1155>
Diffstat (limited to 'tests/python')
-rw-r--r--tests/python/meson.build19
-rwxr-xr-xtests/python/python-devenv-overrides.py20
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/python/meson.build b/tests/python/meson.build
new file mode 100644
index 0000000000..b391044b7e
--- /dev/null
+++ b/tests/python/meson.build
@@ -0,0 +1,19 @@
+gst_python = subproject('gst-python', required: false)
+gir = find_program('g-ir-scanner', required : get_option('introspection'))
+if not gst_python.found() or not gir.found()
+ message('Not running python devenv tests: gst_python: @0@ gir: @1@'.format(gst_python.found(), gir.found()))
+ subdir_done()
+endif
+
+root_rel = '../..'
+python = import('python').find_installation()
+
+if run_command(python, '-c', 'import gi').returncode() != 0
+ message('PyGObject not found, not running PyGObject tests')
+ subdir_done()
+endif
+
+test('python-overrides-devenv', setenv, args: ['--builddir=@0@'.format(meson.build_root()),
+ '--gstbuilddir=@0@'.format(meson.current_build_dir() / '..' / '..'),
+ '--srcdir=@0@'.format(meson.source_root()),
+ meson.current_source_dir() / 'python-devenv-overrides.py']) \ No newline at end of file
diff --git a/tests/python/python-devenv-overrides.py b/tests/python/python-devenv-overrides.py
new file mode 100755
index 0000000000..0c099118ea
--- /dev/null
+++ b/tests/python/python-devenv-overrides.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python3
+import unittest
+from pathlib import Path
+from unittest import TestCase
+from gi.repository import Gst
+
+
+class TestBin(TestCase):
+ def test_overrides(self):
+ from gi.overrides import Gst
+ self.assertEqual(Path(Gst.__file__), Path(__file__).parents[2] / "subprojects/gst-python/gi/overrides/Gst.py")
+
+ def simple_functional_test(self):
+ Gst.init(None)
+ self.assertEqual(Gst.ElementFactory.make("bin", None).sinkpads, [])
+ self.assertEqual(float(Gst.Fraction(1, 2)), 0.5)
+
+
+if __name__ == "__main__":
+ unittest.main()