From 0c4a4a163a03bbc26be6991570338de1a73fa33e Mon Sep 17 00:00:00 2001 From: black-desk Date: Wed, 15 Jan 2025 10:26:36 +0800 Subject: [PATCH] tests: update tests Update tests for 1. Skip property names validation 2. Do not validate function argument names --- tests/data/sloppy-introspection.xml | 10 ++++++ ...ospection.xml => strict-introspection.xml} | 6 ++-- tests/test_introspection.py | 31 +++++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 tests/data/sloppy-introspection.xml rename tests/data/{introspection.xml => strict-introspection.xml} (87%) diff --git a/tests/data/sloppy-introspection.xml b/tests/data/sloppy-introspection.xml new file mode 100644 index 00000000..fa7d73a0 --- /dev/null +++ b/tests/data/sloppy-introspection.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/tests/data/introspection.xml b/tests/data/strict-introspection.xml similarity index 87% rename from tests/data/introspection.xml rename to tests/data/strict-introspection.xml index 56fa0f48..869663a0 100644 --- a/tests/data/introspection.xml +++ b/tests/data/strict-introspection.xml @@ -5,7 +5,7 @@ - + @@ -16,11 +16,11 @@ - + - + diff --git a/tests/test_introspection.py b/tests/test_introspection.py index b110cc83..ac689ae6 100644 --- a/tests/test_introspection.py +++ b/tests/test_introspection.py @@ -1,14 +1,33 @@ import os -from dbus_fast import ArgDirection, PropertyAccess, SignatureType +from dbus_fast import ( + ArgDirection, + PropertyAccess, + SignatureType, + InvalidMemberNameError, +) from dbus_fast import introspection as intr -with open(f"{os.path.dirname(__file__)}/data/introspection.xml") as f: - example_data = f.read() +with open(f"{os.path.dirname(__file__)}/data/strict-introspection.xml") as f: + strict_data = f.read() +with open(f"{os.path.dirname(__file__)}/data/sloppy-introspection.xml") as f: + sloppy_data = f.read() -def test_example_introspection_from_xml(): - node = intr.Node.parse(example_data) + +def test_introspection_from_xml_sloppy(): + intr.Node.parse(sloppy_data, validate_property_names=False) + + +def test_introspection_from_xml_strict(): + try: + node = intr.Node.parse(sloppy_data) + except InvalidMemberNameError: + pass + else: + assert False, "Expected an AssertionError" + + node = intr.Node.parse(strict_data) assert len(node.interfaces) == 1 interface = node.interfaces[0] @@ -66,7 +85,7 @@ def test_example_introspection_from_xml(): def test_example_introspection_to_xml(): - node = intr.Node.parse(example_data) + node = intr.Node.parse(strict_data) tree = node.to_xml() assert tree.tag == "node" assert tree.attrib.get("name") == "/com/example/sample_object0"