aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-04-04 16:55:52 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-06-14 12:34:08 +0200
commitd78151f89b2c374af366bee536c8ceeae3b2ab5e (patch)
tree807473b4c90cd1c324f95ffead8516f1bb6f2150 /sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py
parent73adefe22ffbfabe0ef213e9c2fe2c56efdd7488 (diff)
tools: add pyside6-qml
- pyside6-qml is a tool that mimics the capabilities of qml utility and enables quick prototyping for qml files. Most cli options of the qml tool are carried forward to this tool. example-usage: pyside6-qml -a gui examples/declarative/editingmodel/main.qml To see all the cli options available with this tool, do: pyside6-qml --help Task-number: PYSIDE-1878 Pick-to: 6.3 Change-Id: I98bd77ccf6a0a286bb54da264312e81bf2964dc7 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py')
-rw-r--r--sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py b/sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py
new file mode 100644
index 000000000..701f8f215
--- /dev/null
+++ b/sources/pyside6/tests/tools/pyside6-qml/test_pyside6_qml.py
@@ -0,0 +1,75 @@
+# Copyright (C) 2018 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+"""Test for pyside6-qml
+
+The tests does a unittest and some integration tests for pyside6-qml."""
+
+from asyncio.subprocess import PIPE
+import os
+import sys
+import unittest
+import subprocess
+import importlib.util
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[2]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+
+class TestPySide6QmlUnit(unittest.TestCase):
+ def setUp(self) -> None:
+ super().setUp()
+ self._dir = Path(__file__).parent.resolve()
+ self.pyside_root = self._dir.parents[4]
+
+ self.pyqml_path = self.pyside_root / "sources" / "pyside-tools" / "qml.py"
+ self.core_qml_path = (self.pyside_root / "examples" / "declarative" / "referenceexamples"
+ / "adding")
+
+ self.pyqml_run_cmd = [sys.executable, os.fspath(self.pyqml_path)]
+
+ # self.pyqml_path will not abe able to find pyside and other related binaries, if not added
+ # to path explicitly. The following lines does that.
+ self.test_env = os.environ.copy()
+ self.test_env["PYTHONPATH"] = os.pathsep + os.pathsep.join(sys.path)
+
+ def testImportQmlModules(self):
+
+ # because pyside-tools has a hyphen, a normal 'from pyside-tools import qml' cannot be done
+ spec = importlib.util.spec_from_file_location("qml", self.pyqml_path)
+ pyqml = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(pyqml)
+ pyqml.import_qml_modules(self.core_qml_path)
+
+ # path added to sys.path
+ self.assertIn(str(self.core_qml_path), sys.path)
+
+ # module is imported
+ self.assertIn("person", sys.modules.keys())
+
+ # remove the imported modules
+ sys.path.remove(str(self.core_qml_path))
+ del sys.modules["person"]
+
+ # test with module_paths - dir
+ self.person_path = self.core_qml_path / "person.py"
+ pyqml.import_qml_modules(self.core_qml_path, module_paths=[self.core_qml_path])
+ self.assertIn(str(self.core_qml_path), sys.path)
+ self.assertIn("person", sys.modules.keys())
+
+ # test with module_paths - file - in testCoreApplication(self)
+
+ def testCoreApplication(self):
+ self.pyqml_run_cmd.extend(["--apptype", "core"])
+ self.pyqml_run_cmd.append(str(self.core_qml_path / "example.qml"))
+ self.pyqml_run_cmd.extend(["-I", str(self.core_qml_path / "person.py")])
+
+ result = subprocess.run(self.pyqml_run_cmd, stdout=PIPE, env=self.test_env)
+ self.assertEqual(result.returncode, 0)
+ self.assertEqual(result.stdout.rstrip(), b"{'_name': 'Bob Jones', '_shoe_size': 12}")
+
+
+if __name__ == '__main__':
+ unittest.main()