def _complete(invocation, collection=None): colstr = "" if collection: colstr = "-c {0}".format(collection) with expect_exit(0): _dispatch("inv --complete {1} -- inv {0}".format(invocation, colstr)) return sys.stdout.getvalue()
def should_not_show_tracebacks(self): # Ensure we fall out of dispatch() on missing parser args, # but are still able to look at stderr to ensure no TB got printed with patch('sys.exit', Mock(side_effect=SystemExit)): try: _dispatch("inv -c fail missing_pos") except SystemExit: pass assert TB_SENTINEL not in sys.stderr.getvalue()
def collection_defaults_dont_block_env_var_run_settings(self): # Environ setting run.warn os.environ['INVOKE_RUN_WARN'] = "1" with run_in_configs() as run: # This collection sets run = {echo: true} # If merging isn't done, it will overwrite the low level # defaults, meaning the env var adapter won't see that # 'run_warn' is a valid setting. _dispatch('invoke -c collection go') ok_(run.call_args[1]['echo'] == True) ok_(run.call_args[1]['warn'] == True)
def run_echo_honors_configuration_overrides(self): # Try a few realistic-for-this-setting levels: with run_in_configs() as run: # Collection _dispatch('invoke -c collection go') eq_(run.call_args_list[-1][1]['echo'], True) # Runtime conf file _dispatch('invoke -c contextualized -f echo.yaml run') eq_(run.call_args_list[-1][1]['echo'], True) # Runtime beats collection _dispatch('invoke -c collection -f no-echo.yaml go') eq_(run.call_args_list[-1][1]['echo'], False) # Flag beats runtime _dispatch('invoke -c contextualized -f no-echo.yaml -e run') eq_(run.call_args_list[-1][1]['echo'], True)
def contextualized_tasks_are_given_parser_context_arg(self): # go() in contextualized.py just returns its initial arg retval = list(_dispatch('invoke -c contextualized go').values())[0] assert isinstance(retval, Context)
def missing_default_task_prints_help(self): with expect_exit(): _dispatch("inv -c foo") ok_("Core options:" in sys.stdout.getvalue())
def _test_flag(self, flag, key): with mocked_run(): # The tasks themselves perform the necessary asserts. _dispatch('invoke {0} -c contextualized check_{1}'.format( flag, key))
def runtime_config_file_honored(self): with cd('configs'): _dispatch("inv -c runtime -f yaml/invoke.yaml mytask")
def command_failure(self): "Command failure doesn't show tracebacks" with patch('sys.exit') as exit: _dispatch('inv -c fail simple') assert TB_SENTINEL not in sys.stderr.getvalue() exit.assert_called_with(1)
def vanilla(self): os.chdir('implicit') _dispatch('inv foo') eq_(sys.stdout.getvalue(), "Hm\n")
def per_project_config_files_load_with_explicit_ns(self): # Re: #234 with cd(os.path.join('configs', 'yaml')): _dispatch("inv -c explicit mytask")
def vanilla_with_explicit_collection(self): # Duplicates _output_eq, but this way that can change w/o breaking # our expectations. _dispatch('inv -c integration print_foo') eq_(sys.stdout.getvalue(), "foo\n")
def _test_flag(self, flag, kwarg, value): with patch('invoke.context.run') as run: _dispatch('invoke {0} -c contextualized run'.format(flag)) ok_(run.call_args[1][kwarg] == value)
def per_project_config_files_are_loaded(self): with cd(os.path.join('configs', 'yaml')): _dispatch("inv mytask")
def debug_flag_activates_logging(self): # Have to patch our logger to get in before Nose logcapture kicks in. with patch('invoke.util.debug') as debug: _dispatch('inv -d -c debugging foo') debug.assert_called_with('my-sentinel')
def version_override(self): with expect_exit(): _dispatch('notinvoke -V', version="nope 1.0") eq_(sys.stdout.getvalue(), "nope 1.0\n")
def _test_flag(self, flag, kwarg, value): with patch('invoke.context.run') as run: _dispatch('invoke {0} -c contextualized run'.format(flag)) run.assert_called_with('x', **{kwarg: value})
def _test_flag(self, flag, key): with mocked_run(): # The tasks themselves perform the necessary asserts. _dispatch('invoke {0} -c contextualized check_{1}'.format( flag, key ))
def env_vars_load_with_prefix(self): os.environ['INVOKE_RUN_ECHO'] = "1" with mocked_run(): # Task performs the assert _dispatch('invoke -c contextualized check_echo')
def env_vars_load_with_prefix(self): os.environ['INVOKE_RUN_ECHO'] = "1" with patch('invoke.context.run') as run: _dispatch('invoke -c contextualized run') ok_(run.call_args[1]['echo'] == True)