diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2018-12-19 00:28:33 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2019-01-03 18:12:23 -0800 |
commit | 7e92ff823e2bf97ee33c1b7ff87bb8acecb5ae77 (patch) | |
tree | dfbd249b644a7c95a7872862bab2db3aa1f1fc79 /test/units/playbook | |
parent | afdbb0d9d5bebb91f632f0d4a1364de5393ba17a (diff) | |
download | ansible-7e92ff823e2bf97ee33c1b7ff87bb8acecb5ae77.tar.gz |
Split up the base_parser function
The goal of breaking apart the base_parser() function is to get rid of
a bunch of conditionals and parameters in the code and, instead, make
code look like simple composition.
When splitting, a choice had to be made as to whether this would operate
by side effect (modifying a passed in parser) or side effect-free
(returning a new parser everytime).
Making a version that's side-effect-free appears to be fighting with the
optparse API (it wants to work by creating a parser object, configuring
the object, and then parsing the arguments with it) so instead, make it
clear that our helper functions are modifying the passed in parser by
(1) not returning the parser and (2) changing the function names to be
more clear that it is operating by side-effect.
Also move all of the generic optparse code, along with the argument
context classes, into a new subdirectory.
Diffstat (limited to 'test/units/playbook')
-rw-r--r-- | test/units/playbook/test_play_context.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/test/units/playbook/test_play_context.py b/test/units/playbook/test_play_context.py index 2c8be52d6a..c7e51cd8a4 100644 --- a/test/units/playbook/test_play_context.py +++ b/test/units/playbook/test_play_context.py @@ -11,10 +11,10 @@ import os import pytest -from ansible import arguments from ansible import constants as C from ansible import context -from ansible import cli +from ansible.arguments import context_objects as co +from ansible.arguments import optparse_helpers as opt_help from units.compat import unittest from ansible.errors import AnsibleError, AnsibleParserError from ansible.module_utils.six.moves import shlex_quote @@ -25,19 +25,26 @@ from units.mock.loader import DictDataLoader @pytest.fixture def parser(): - parser = cli.base_parser(runas_opts=True, meta_opts=True, - runtask_opts=True, vault_opts=True, - async_opts=True, connect_opts=True, - subset_opts=True, check_opts=True, - inventory_opts=True,) + parser = opt_help.create_base_parser() + + opt_help.add_runas_options(parser) + opt_help.add_meta_options(parser) + opt_help.add_runtask_options(parser) + opt_help.add_vault_options(parser) + opt_help.add_async_options(parser) + opt_help.add_connect_options(parser) + opt_help.add_subset_options(parser) + opt_help.add_check_options(parser) + opt_help.add_inventory_options(parser) + return parser @pytest.fixture def reset_cli_args(): - arguments.GlobalCLIArgs._Singleton__instance = None + co.GlobalCLIArgs._Singleton__instance = None yield - arguments.GlobalCLIArgs._Singleton__instance = None + co.GlobalCLIArgs._Singleton__instance = None def test_play_context(mocker, parser, reset_cli_args): |