Skip to content

Commit

Permalink
tests: update tests
Browse files Browse the repository at this point in the history
Update tests for

1. Skip property names validation
2. Do not validate function argument names
  • Loading branch information
black-desk committed Jan 15, 2025
1 parent c8cf670 commit 0c4a4a1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
10 changes: 10 additions & 0 deletions tests/data/sloppy-introspection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/com/example/sample_object0">
<interface name="com.example.SampleInterface0">
<method name="Frobate">
<arg name="0-foo-bar" type="i" direction="in"/>
</method>
<property name="0-baz-qux" type="y" access="write"/>
</interface>
</node>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<method name="Frobate">
<arg name="foo" type="i" direction="in"/>
<arg name="bar" type="s" direction="out"/>
<arg name="baz" type="a{us}" direction="out"/>
<arg name="0-baz" type="a{us}" direction="out"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
<method name="Bazify">
Expand All @@ -16,11 +16,11 @@
<arg name="bar" type="(iiav)" direction="in"/>
</method>
<signal name="Changed">
<arg name="new_value" type="b"/>
<arg name="0-new_value" type="b"/>
</signal>
<signal name="ChangedMulti">
<arg name="new_value1" type="b"/>
<arg name="new_value2" type="y"/>
<arg name="0-new_value2" type="y"/>
</signal>
<property name="Bar" type="y" access="write"/>
</interface>
Expand Down
31 changes: 25 additions & 6 deletions tests/test_introspection.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0c4a4a1

Please sign in to comment.