• 
      

    Add unit testing helpers for testing command classes.

    Review Request #12247 — Created April 21, 2022 and submitted — Latest diff uploaded

    Information

    RBTools
    release-3.x

    Reviewers

    This introduces a new mixin for command unit tests,
    rbtools.testing.commands.CommandTestsMixin. This offers two new
    methods:

    • create_command(): Creates an instance of a command that can be
      initialized or inspected.

    • run_command(): Runs a command with provided input and arguments,
      returning the instance, exit code, and output/error content.

    These methods can accept a pre-computed repository_info and tool,
    which will be used instead of repository scanning, making it possible
    to run a test against a real or simulated repository. If not provided,
    scanning will still be disabled unless passing scan=True.

    It also registers URLMapTransport as the transport for the command. A
    setup_transport_func argument can be passed in to create_command()
    to allow the tests to register URLs or set capabilities on the
    transport.

    There's an important fix included for unit tests that set
    needs_temp_home = True. The home directory will be set as the current
    directory, ensuring that the RBTools repository's own .reviewboardrc
    won't interfere with tests. This is a better default behavior than
    what we had, and will meet the expectations of most command unit tests.

    Upcoming changes will make use of this new functionality.

    Made use of this with some in-progress unit test additions, and with
    a change that updates all existing command unit tests.

    Commits

    Files