Merge lp:~frankban/lpsetup/commands-unittests into lp:lpsetup
Status: | Merged |
---|---|
Approved by: | Francesco Banconi |
Approved revision: | 43 |
Merged at revision: | 34 |
Proposed branch: | lp:~frankban/lpsetup/commands-unittests |
Merge into: | lp:lpsetup |
Diff against target: |
627 lines (+376/-51) 11 files modified
lpsetup/argparser.py (+39/-24) lpsetup/subcommands/get.py (+0/-1) lpsetup/subcommands/install.py (+4/-2) lpsetup/subcommands/lxcinstall.py (+7/-10) lpsetup/tests/subcommands/test_get.py (+66/-0) lpsetup/tests/subcommands/test_inithost.py (+50/-0) lpsetup/tests/subcommands/test_install.py (+55/-0) lpsetup/tests/subcommands/test_lxcinstall.py (+75/-0) lpsetup/tests/subcommands/test_version.py (+0/-1) lpsetup/tests/test_argparser.py (+14/-8) lpsetup/tests/utils.py (+66/-5) |
To merge this branch: | bzr merge lp:~frankban/lpsetup/commands-unittests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Benji York (community) | code | Approve | |
Review via email: mp+112094@code.launchpad.net |
Commit message
Added sub commands unit tests.
Description of the change
== Changes ==
sub command tests: added unit tests for the get, inithost, install and lxcinstall sub commands. Each TestCase is a subclass of `tests.
Note that update and branch sub commands are not tested: they are obsolete and will either go away or be heavily modified before the end of the process.
argparser.
argparser.
get: removed *needs_root* to avoid confusion: *needs_root* is unnecessary since the command overrides *get_needs_root()*.
lxcinstall: now the command subclasses install and reuses inithost, install and get steps. A consequence of this change is that now the command correctly handles `directory` and `dependencies_dir` arguments.
tests.utils.
tests.utils: added a helper function returning a random string.
tests.test_
This branch is really good. These tests will help us quite a bit while we
implement the LEP. Here are my thoughts from reading through the diff:
The combination of the negative test for step_name ("not in steps_to_skip") and
the ternary operator in _include_step is really hard for me to understand.
Maybe this instead:
def _include_step(self, step_name, namespace):
"""Return True if the given *step_name* must be run, False otherwise.
A step is included in the command execution if the step included in skip_steps or []
`--steps` (or steps is None) and is not included in `--skip-steps`.
"""
steps_to_skip = namespace.
steps_to_run = namespace.steps
# If explicitly told to skip a step, then skip it.
if step_name in steps_to_skip:
return False
# If no list of steps was provided then any non-skipped are to be run.
if steps_to_run is None:
return True
# A list of steps to run was provided, so the step has to be included in
# order to be run.
return step_name in steps_to_run
I am not entirely sure the above is right, which bolsters my feeling that the
original was hard to understand.
Since the subcommand tests always have a get_arguments function which is called
and assigned to expected_arguments, it might be slightly better to just have a
required get_arguments method instead.
I don't feel strongly about it, but for the sake of diversity: here is a
version of get_random_string that is a bit shorter and more direct:
def get_random_ string( size=10) : random. sample( string. ascii_letters, size))
"""Return a random string to be used in tests."""
return ''.join(
I really like the explanation in the StepsBasedSubCo mmandTestMixin docstring of
how to use the class. I wonder if it would be good to leave the "must define"
attributes undefined so AttributeErrors are generated if a subclass leaves them
out.