selftests/unit/test_remote.py: port from flexmock to mock (unittest.mock)
This is a port to the mock library that is in the standard in Python 3, and it's available in Python 2, and already a requirement for Avocado. The approach used on this port is to avoid excessive mocking, and use the real code, unless when insteracting with dynamic and non-existing components (such as a remote system). A partial list of the changes when compared to the previous version: * Args was made into a real argparse.Namespace instance because there's no need for it to be a mocked object. Actually, it is better to have an exact object instance, rather than a mock when it's possible to. * The "references" attribute being set on the, then mocked, job instance has been dropped, because the natural way of passing that to the job is using the "reference" key in args. Also, while purely cosmetic, the references that look like the example instrumented tests have been renamed (passtest -> passtest.py). * The "unique_id" attribute being set on the, then mocked, job instance had a value (1-sleeptest;0) completely incompatible with job IDs, and was removed from being set manually. * This version does *not* mock "low level" remote execution of commands, such as running "env" or "avocado -v" on the remote host. Instead, it mocks the end result of check_remote_avocado completely. * The extra test on RemoteTestRunner.setup() seems unnecessary, because that is part of the run_suite() workflow. * Checking if `__init__` was called is not be possible with mock. See https://docs.python.org/3/library/unittest.mock.html#mocking-magic-methodsSigned-off-by: NCleber Rosa <crosa@redhat.com>
Showing
想要评论请 注册 或 登录