]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commit2eb9d327eed709d4cbbbc65855576119993c4ea4
tree9446d29f6d21ebdc90f372261b604926be9de344
parentdd99c872f6e0899a0934d099d4afadec29806606
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