Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def uses_overridden_value_when_given(self):
stdout, _ = run(
"myapp --help", invoke=False, program=Program(binary="nope")
)
assert "nope [--core-opts]" in stdout
def splits_a_string(self):
p = Program()
p.print_version = Mock()
p.run("inv --version", exit=False)
p.print_version.assert_called()
def does_not_seek_tasks_module_if_namespace_was_given(self):
expect(
"foo",
err="No idea what 'foo' is!\n",
program=Program(namespace=Collection("blank")),
)
def returns_core_args_list(self):
# Mostly so we encode explicity doc'd public API member in tests.
# Spot checks good enough, --help tests include the full deal.
core_args = Program().core_args()
core_arg_names = [x.names[0] for x in core_args]
for name in ("complete", "help", "pty", "version"):
assert name in core_arg_names
# Also make sure it's a list for easier tweaking/appending
assert isinstance(core_args, list)
def contains_truly_core_arguments_regardless_of_namespace_value(self):
# Spot check. See integration-style --help tests for full argument
# checkup.
for program in (Program(), Program(namespace=Collection())):
for arg in ("--complete", "--debug", "--warn-only", "--list"):
stdout, _ = run("--help", program=program)
assert arg in stdout
def _complete(invocation, collection=None):
colstr = ""
if collection:
colstr = "-c {}".format(collection)
command = "inv --complete {0} -- inv {0} {1}".format(colstr, invocation)
Program().run(command, exit=False)
return sys.stdout.getvalue()
def uses_executor_class_given(self):
klass = Mock()
Program(executor_class=klass).run("myapp foo", exit=False)
klass.assert_called_with(ANY, ANY, ANY)
klass.return_value.execute.assert_called_with(ANY)
def debug_honored_as_env_var_too(self, reset_environ):
os.environ["INVOKE_DEBUG"] = "1"
with patch("invoke.util.debug") as debug:
# NOTE: no use of -d/--debug
Program().run("invoke -c debugging foo")
debug.assert_called_with("my-sentinel")
def may_specify_loader_class(self):
klass = object()
assert Program(loader_class=klass).loader_class == klass
test=None):
"""
Run ``invocation`` via ``program`` and expect resulting output to match.
May give one or both of ``out``/``err`` (but not neither).
``program`` defaults to ``Program()``.
To skip automatically assuming the argv under test starts with ``"invoke
"``, say ``invoke=False``.
To customize the operator used for testing (default: equality), use
``test`` (which should be an assertion wrapper of some kind).
"""
if program is None:
program = Program()
if invoke:
invocation = "invoke {0}".format(invocation)
program.run(invocation, exit=False)
# Perform tests
if out is not None:
(test or eq_)(sys.stdout.getvalue(), out)
if err is not None:
(test or eq_)(sys.stderr.getvalue(), err)