aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/tools/metaobjectdump
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/tools/metaobjectdump')
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/CMakeLists.txt1
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/baseline_default_birthdayparty.json1
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/baseline_default_person.json1
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_birthdayparty.json1
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_person.json1
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/baseline_property_happybirthdaysong.json1
-rw-r--r--sources/pyside6/tests/tools/metaobjectdump/test_metaobjectdump.py73
7 files changed, 79 insertions, 0 deletions
diff --git a/sources/pyside6/tests/tools/metaobjectdump/CMakeLists.txt b/sources/pyside6/tests/tools/metaobjectdump/CMakeLists.txt
new file mode 100644
index 000000000..f1ad6ab16
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/CMakeLists.txt
@@ -0,0 +1 @@
+PYSIDE_TEST(test_metaobjectdump.py)
diff --git a/sources/pyside6/tests/tools/metaobjectdump/baseline_default_birthdayparty.json b/sources/pyside6/tests/tools/metaobjectdump/baseline_default_birthdayparty.json
new file mode 100644
index 000000000..6a695dd5c
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/baseline_default_birthdayparty.json
@@ -0,0 +1 @@
+[{"classes": [{"className": "BirthdayParty", "qualifiedClassName": "BirthdayParty", "object": true, "superClasses": [{"access": "public", "name": "QObject"}], "classInfos": [{"name": "QML.Element", "value": "auto"}, {"name": "DefaultProperty", "value": "guests"}], "properties": [{"name": "host", "type": "Person", "index": 0, "read": "host", "notify": "host_changed", "write": "host"}, {"name": "guests", "type": "QQmlListProperty<Person>", "index": 1}], "signals": [{"access": "public", "name": "host_changed", "arguments": [], "returnType": "void"}, {"access": "public", "name": "guests_changed", "arguments": [], "returnType": "void"}]}], "outputRevision": 68, "QML_IMPORT_NAME": "People", "QML_IMPORT_MAJOR_VERSION": 1, "QML_IMPORT_MINOR_VERSION": 0, "QT_MODULES": ["QtCore", "QtQml"]}] \ No newline at end of file
diff --git a/sources/pyside6/tests/tools/metaobjectdump/baseline_default_person.json b/sources/pyside6/tests/tools/metaobjectdump/baseline_default_person.json
new file mode 100644
index 000000000..571056c2a
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/baseline_default_person.json
@@ -0,0 +1 @@
+[{"classes": [{"className": "Person", "qualifiedClassName": "Person", "object": true, "superClasses": [{"access": "public", "name": "QObject"}], "classInfos": [{"name": "QML.Element", "value": "anonymous"}], "properties": [{"name": "name", "type": "QString", "index": 0, "read": "name", "notify": "name_changed", "write": "name"}, {"name": "shoe_size", "type": "int", "index": 1, "read": "shoe_size", "notify": "shoe_size_changed", "write": "shoe_size"}], "signals": [{"access": "public", "name": "name_changed", "arguments": [], "returnType": "void"}, {"access": "public", "name": "shoe_size_changed", "arguments": [], "returnType": "void"}]}, {"className": "Boy", "qualifiedClassName": "Boy", "object": true, "superClasses": [{"access": "public", "name": "Person"}], "classInfos": [{"name": "QML.Element", "value": "auto"}]}, {"className": "Girl", "qualifiedClassName": "Girl", "object": true, "superClasses": [{"access": "public", "name": "Person"}], "classInfos": [{"name": "QML.Element", "value": "auto"}]}], "outputRevision": 68, "QML_IMPORT_NAME": "People", "QML_IMPORT_MAJOR_VERSION": 1, "QML_IMPORT_MINOR_VERSION": 0, "QT_MODULES": ["QtCore", "QtQml"]}] \ No newline at end of file
diff --git a/sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_birthdayparty.json b/sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_birthdayparty.json
new file mode 100644
index 000000000..0491e41cc
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_birthdayparty.json
@@ -0,0 +1 @@
+[{"classes": [{"className": "BirthdayParty", "qualifiedClassName": "BirthdayParty", "object": true, "superClasses": [{"access": "public", "name": "QObject"}], "classInfos": [{"name": "QML.Element", "value": "auto"}], "properties": [{"name": "host", "type": "Person", "index": 0, "read": "host", "notify": "host_changed", "write": "host"}, {"name": "guests", "type": "QQmlListProperty<Person>", "index": 1}], "signals": [{"access": "public", "name": "host_changed", "arguments": [], "returnType": "void"}, {"access": "public", "name": "guests_changed", "arguments": [], "returnType": "void"}]}], "outputRevision": 68, "QML_IMPORT_NAME": "People", "QML_IMPORT_MAJOR_VERSION": 1, "QML_IMPORT_MINOR_VERSION": 0, "QT_MODULES": ["QtCore", "QtQml"]}] \ No newline at end of file
diff --git a/sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_person.json b/sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_person.json
new file mode 100644
index 000000000..82021ee0a
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/baseline_inheritance_person.json
@@ -0,0 +1 @@
+[{"classes": [{"className": "Person", "qualifiedClassName": "Person", "object": true, "superClasses": [{"access": "public", "name": "QObject"}], "classInfos": [{"name": "QML.Element", "value": "auto"}, {"name": "QML.Creatable", "value": "false"}, {"name": "QML.UncreatableReason", "value": "Person is an abstract base class."}], "properties": [{"name": "name", "type": "QString", "index": 0, "read": "name", "notify": "name_changed", "write": "name"}, {"name": "shoe_size", "type": "int", "index": 1, "read": "shoe_size", "notify": "shoe_size_changed", "write": "shoe_size"}], "signals": [{"access": "public", "name": "name_changed", "arguments": [], "returnType": "void"}, {"access": "public", "name": "shoe_size_changed", "arguments": [], "returnType": "void"}]}, {"className": "Boy", "qualifiedClassName": "Boy", "object": true, "superClasses": [{"access": "public", "name": "Person"}], "classInfos": [{"name": "QML.Element", "value": "auto"}]}, {"className": "Girl", "qualifiedClassName": "Girl", "object": true, "superClasses": [{"access": "public", "name": "Person"}], "classInfos": [{"name": "QML.Element", "value": "auto"}]}], "outputRevision": 68, "QML_IMPORT_NAME": "People", "QML_IMPORT_MAJOR_VERSION": 1, "QML_IMPORT_MINOR_VERSION": 0, "QT_MODULES": ["QtCore", "QtQml"]}] \ No newline at end of file
diff --git a/sources/pyside6/tests/tools/metaobjectdump/baseline_property_happybirthdaysong.json b/sources/pyside6/tests/tools/metaobjectdump/baseline_property_happybirthdaysong.json
new file mode 100644
index 000000000..c009111b7
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/baseline_property_happybirthdaysong.json
@@ -0,0 +1 @@
+[{"classes": [{"className": "HappyBirthdaySong", "qualifiedClassName": "HappyBirthdaySong", "object": false, "superClasses": [{"access": "public", "name": "QPyQmlPropertyValueSource"}], "classInfos": [{"name": "QML.Element", "value": "auto"}], "properties": [{"name": "name", "type": "QString", "index": 0, "read": "name", "notify": "name_changed", "write": "name"}], "signals": [{"access": "public", "name": "name_changed", "arguments": [], "returnType": "void"}], "slots": [{"access": "public", "name": "advance", "arguments": [], "returnType": "void"}]}], "outputRevision": 68, "QML_IMPORT_NAME": "People", "QML_IMPORT_MAJOR_VERSION": 1, "QML_IMPORT_MINOR_VERSION": 0, "QT_MODULES": ["QtCore", "QtQml"]}] \ No newline at end of file
diff --git a/sources/pyside6/tests/tools/metaobjectdump/test_metaobjectdump.py b/sources/pyside6/tests/tools/metaobjectdump/test_metaobjectdump.py
new file mode 100644
index 000000000..5e7412bf5
--- /dev/null
+++ b/sources/pyside6/tests/tools/metaobjectdump/test_metaobjectdump.py
@@ -0,0 +1,73 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import sys
+import subprocess
+import unittest
+
+from pathlib import Path
+
+"""Test for pyside6-metaobjectdump.
+
+The test prints commands to regenerate the base line."""
+
+
+def msg_regenerate(cmd, baseline):
+ cmd_str = " ".join(cmd)
+ return (f"# Regenerate {baseline}\n"
+ f"{cmd_str} > {baseline}")
+
+
+@unittest.skipIf(sys.version_info < (3, 8), "Needs a recent ast module")
+class TestMetaObjectDump(unittest.TestCase):
+ """Test for the metaobjectdump tool. Compares the output of metaobjectdump.py for some
+ example files in compact format."""
+
+ def setUp(self):
+ super().setUp()
+ self._dir = Path(__file__).parent.resolve()
+ pyside_root = self._dir.parents[4]
+ self._metaobjectdump_tool = pyside_root / "sources" / "pyside-tools" / "metaobjectdump.py"
+ self._examples_dir = (pyside_root / "examples" /
+ "qml" / "tutorials" / "extending-qml-advanced")
+
+ # Compile a list of examples (tuple [file, base line, command])
+ examples = []
+ for d in ["advanced2-Inheritance-and-coercion", "advanced3-Default-properties"]:
+ example_dir = self._examples_dir / d
+ examples.append(example_dir / "birthdayparty.py")
+ examples.append(example_dir / "person.py")
+ # Example with slot
+ examples.append(self._examples_dir / "advanced6-Property-value-source"
+ / "happybirthdaysong.py")
+
+ metaobjectdump_cmd_root = [sys.executable, os.fspath(self._metaobjectdump_tool), "-c", "-s"]
+ self._examples = []
+ for example in examples:
+ name = example.parent.name
+ # Simplify "advanced2-Inheritance-and-coercion" -> "inheritance"
+ short_name = name.split("-")[1].lower()
+ baseline_name = f"baseline_{short_name}_{example.stem}.json"
+ baseline_path = self._dir / baseline_name
+ cmd = metaobjectdump_cmd_root + [os.fspath(example)]
+ self._examples.append((example, baseline_path, cmd))
+ print(msg_regenerate(cmd, baseline_path))
+
+ def testMetaObjectDump(self):
+ self.assertTrue(self._examples_dir.is_dir())
+ self.assertTrue(self._metaobjectdump_tool.is_file())
+
+ for example, baseline, cmd in self._examples:
+ self.assertTrue(example.is_file())
+ self.assertTrue(baseline.is_file())
+ baseline_data = baseline.read_text()
+
+ popen = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ actual = popen.communicate()[0].decode("UTF-8")
+ self.assertEqual(popen.returncode, 0)
+ self.assertEqual(baseline_data, actual)
+
+
+if __name__ == '__main__':
+ unittest.main()