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

Fix inheritance issues and separate the mocked dbus into an object #184

Merged
merged 10 commits into from
Nov 30, 2023

Commits on Nov 29, 2023

  1. 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.
    whot committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    46b9f91 View commit details
    Browse the repository at this point in the history
  2. 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.
    whot committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    78df3c5 View commit details
    Browse the repository at this point in the history
  3. 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.
    whot committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    6b6d562 View commit details
    Browse the repository at this point in the history

Commits on Nov 30, 2023

  1. 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.
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    d33f1a3 View commit details
    Browse the repository at this point in the history
  2. 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.
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    aec77f3 View commit details
    Browse the repository at this point in the history
  3. 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.
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    4724d63 View commit details
    Browse the repository at this point in the history
  4. 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.
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    7fe90f3 View commit details
    Browse the repository at this point in the history
  5. 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()
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    47adffe View commit details
    Browse the repository at this point in the history
  6. 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.
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    f103698 View commit details
    Browse the repository at this point in the history
  7. 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.
    whot committed Nov 30, 2023
    Configuration menu
    Copy the full SHA
    c39fc5b View commit details
    Browse the repository at this point in the history