kunit: tool: redo how we construct and mock LinuxSourceTree
authorDaniel Latypov <dlatypov@google.com>
Mon, 16 May 2022 19:47:29 +0000 (12:47 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 7 Jul 2022 23:45:59 +0000 (17:45 -0600)
commit8a04930f2bb0047de4ae18af12e5731084bd555c
tree9446d29f6d21ebdc90f372261b604926be9de344
parent76f0d6f581693fbfd1be82aadc28fb52e33000fd
kunit: tool: redo how we construct and mock LinuxSourceTree

Our main function currently has an optional `linux` argument which is
used to by our unit tests to inject a mock.
We currently have the same code copy-pasted several times to do
  if not linux:
    linux = MakeRealInstance(cli_args.foo, cli_args.bar, ...)

But in python, dependency injection isn't necessary or idiomatic when we
can just use mock.patch() to mock things out.

This change
1. adds a helper to create a LinuxSourceTree from the cli_args
2. drops the `linux` parameter in favor of mocking the __init__ func.

Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/kunit/kunit.py
tools/testing/kunit/kunit_tool_test.py