-
Notifications
You must be signed in to change notification settings - Fork 51
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
Fix inheritance issues and separate the mocked dbus into an object #184
Commits on Nov 29, 2023
-
testcase: actually delete the datadir
We probably shouldn't set it to None before checking whether it's None, that seems less efficient than it could be.
Configuration menu - View commit details
-
Copy full SHA for 46b9f91 - Browse repository at this point
Copy the full SHA 46b9f91View commit details -
testcase: reset the datadir on the DBusTestCaseClass
On the run of a derived test class, cls._DBusTestCase__datadir calls up into the parent class for the datadir and removes it. The subsequent statement cls._DBusTestCase__datadir = None sets it on the derived class, not on DBusTestCase which remains at the original value. Doesn't matter too much since the next derived test class will repeat that process but we leave the parent datadir set despite having removed it which seems like a bad idea. See the comment in get_services_dir(), the datadir is always on the DBusTestCase class, so let's mirror that behavior here.
Configuration menu - View commit details
-
Copy full SHA for 78df3c5 - Browse repository at this point
Copy the full SHA 78df3c5View commit details -
testcase: start the bus on our class, not on the parent
A slightly weird side-effect here: start_dbus was called on the DBusTestCase class - thus the session/system bus pid was set on that class. But tearDownClass() was called with the derived class from the test, so while the getters for variables resolved correctly, setattr(cls, f"{bus_type}_bus_pid", None) would set TestFoo.session_bus_pid = None and leave DBusTestCase.session_bus_pid at whatever value it had before. Fix this and add an assert to ensure we never start a session/system bus twice in the same test class.
Configuration menu - View commit details
-
Copy full SHA for 6b6d562 - Browse repository at this point
Copy the full SHA 6b6d562View commit details
Commits on Nov 30, 2023
-
pytest: make the fixture a subclass of DBusTestCase
No real functional changes, this prepares the way for some extra asserts in the future and the behavior matches that of unittest-style classes which are always subclasses of DBusTestCase.
Configuration menu - View commit details
-
Copy full SHA for d33f1a3 - Browse repository at this point
Copy the full SHA d33f1a3View commit details -
testcase: assert our parent class never gets bus PIDs
This is a potential break but it's unlikely to affect any old-style unittest classes since they would be subclasses by default. It may affect new-style pytest classes, if any exist, but OTOH it can catch confusing errors like setting a variable on the DBusTestCase class but then unsetting it on the derived class during a test.
Configuration menu - View commit details
-
Copy full SHA for aec77f3 - Browse repository at this point
Copy the full SHA aec77f3View commit details -
testcase: move some classmethods to staticmethods
This is what they are anyway, so let's do this and avoid the possibly accidental wrong class handling fixed a few commits ago.
Configuration menu - View commit details
-
Copy full SHA for 4724d63 - Browse repository at this point
Copy the full SHA 4724d63View commit details -
testcase: replace the classmethods with a proper object
This patch introduces the BusType class which handles the system/session buss differences including whatever is independent of who started the actual daemon such as getting a connection. It moves spawn_server and spawn_server_template to standalone functions since those do not have any dependency on anything else in DBusTestCase. It adds the PrivateDBus class which wraps a single instance of a DBus daemon, with a context manager so we can do things like: with PrivateDBus(BusType.SESSION) as bus: .... and have it self clean up automatically. Unlike the previous approach, we don't just fork in the background and kill via PID, we keep a reference to the process and kill it via Python's API. Finally, it changes the DBusTestCase class to use a single instance of those objects as its DBus server when created with start_session_bus() or start_system_bus(). Most of that class is now a wrapper around the PrivateDBus object (or the BusType object where appropriate). PrivateDBus also wraps some functions to make it look more like a DBusTestCase object to keep compatibility with the current pytest behavior. With all that, we can now return a PrivateDBus object from the pytest fixtures and have better insulation than before where the DBusTestCase class was responsible for singleton handling.
Configuration menu - View commit details
-
Copy full SHA for 7fe90f3 - Browse repository at this point
Copy the full SHA 7fe90f3View commit details -
testcase: factor the server spawning into a new SpawnedMock object
Let's move spawn_server and spawn_server_template into an object with a context manager, greatly simplifying them where fixtures are being used. Note that both are renamed into: SpawnedMock.spawn_for_name() SpawedMock.spawn_with_template()
Configuration menu - View commit details
-
Copy full SHA for 47adffe - Browse repository at this point
Copy the full SHA 47adffeView commit details -
testcase: remove unnecessary compat methods
Some of these could've only been exposed by the recently added pytest fixtures - those have never been in a release so let's drop them.
Configuration menu - View commit details
-
Copy full SHA for f103698 - Browse repository at this point
Copy the full SHA f103698View commit details -
testcase: switch to seconds from deciseconds
deciseconds is a rather unusual unit. Let's switch the real API we now have to use seconds: float like time.sleep() and wrap our old API around that.
Configuration menu - View commit details
-
Copy full SHA for c39fc5b - Browse repository at this point
Copy the full SHA c39fc5bView commit details