Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mockobject: Allow adding objects derived from DBusMockObject #218

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

swick
Copy link
Contributor

@swick swick commented Sep 13, 2024

This allows to create objects instanciated from a DBusMockObject subclass in mock templates. That way, implementing dynamic objects becomes easier by using dbus decorators:

    class ColordDevice(mockobject.DBusMockObject):
        @dbus.service.method(DEVICE_IFACE, in_signature='', out_signature='i')
	def Test(self):
		return 42

    self.add_object(ColordDevice, device_path, DEVICE_IFACE, {}, [])

@swick
Copy link
Contributor Author

swick commented Sep 13, 2024

I want to use this in the mutter test suite: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4022/diffs

Copy link
Owner

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for the late review, I missed that during my vacation.

This makes sense, but needs documentation (in the docstrings) and unit tests. Please let me know if you need help with either.

dbusmock/mockobject.py Outdated Show resolved Hide resolved
@swick swick force-pushed the wip/derivable-dbus-mock-objects branch from bbcb469 to 13fa944 Compare October 3, 2024 12:36
@swick
Copy link
Contributor Author

swick commented Oct 3, 2024

Tried to add documentation and a unit test. Let me know if it needs adjusting.

@martinpitt
Copy link
Owner

@swick thanks! I'm AFK until next Wednesday, will re-review then. But at a quick glance this looks great!

@martinpitt
Copy link
Owner

There's some pylint/ruff/black failures, see test failure. If you don't feel like fixing these (installing these tools and running the tests), I'm happy to do that, too.

@swick swick force-pushed the wip/derivable-dbus-mock-objects branch from 13fa944 to dc6a386 Compare October 4, 2024 10:40
@swick
Copy link
Contributor Author

swick commented Oct 4, 2024

I think I managed to fix it. If something is still wrong, feel free to take over.

martinpitt and others added 2 commits October 9, 2024 08:49
We are going to add an 8th argument to the DBusMockObject constructor.
This allows to create objects instanciated from a DBusMockObject
subclass in mock templates. That way, implementing dynamic objects
becomes easier by using dbus decorators.

This also allows passing some extra data to the DBusMockObject derived
class constructor so it becomes possible to store some data in the
object created via DBusMockObject.add_object which can be useful if one
e.g. needs some information stored in the parent object.
@martinpitt martinpitt force-pushed the wip/derivable-dbus-mock-objects branch from dc6a386 to 247d50b Compare October 9, 2024 06:49
@martinpitt
Copy link
Owner

Thanks @swick ! I rebased, fixed a trivial black error, and some docstring formatting.

@martinpitt martinpitt merged commit 2f884d1 into martinpitt:main Oct 9, 2024
18 checks passed
@swick
Copy link
Contributor Author

swick commented Oct 9, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants