def core_help_option_prints_core_help(self): # TODO: change dynamically based on parser contents? # e.g. no core args == no [--core-opts], # no tasks == no task stuff? # NOTE: test will trigger default pty size of 80x24, so the below # string is formatted appropriately. # TODO: add more unit-y tests for specific behaviors: # * fill terminal w/ columns + spacing # * line-wrap help text in its own column expected = """ Usage: inv[oke] [--core-opts] task1 [--task1-opts] ... taskN [--taskN-opts] Core options: --no-dedupe Disable task deduplication. -c STRING, --collection=STRING Specify collection name to load. -d, --debug Enable debug output. -e, --echo Echo executed commands before running. -f STRING, --config=STRING Runtime configuration file to use. -h [STRING], --help[=STRING] Show core or per-task help and exit. -H STRING, --hide=STRING Set default value of run()'s 'hide' kwarg. -l, --list List available tasks. -p, --pty Use a pty when executing shell commands. -r STRING, --root=STRING Change root directory used for finding task modules. -V, --version Show version and exit. -w, --warn-only Warn, instead of failing, when shell commands fail. """.lstrip() for flag in ['-h', '--help']: _output_eq(flag, expected)
def core_help_option_prints_core_help(self): # TODO: change dynamically based on parser contents? # e.g. no core args == no [--core-opts], # no tasks == no task stuff? # NOTE: test will trigger default pty size of 80x24, so the below # string is formatted appropriately. # TODO: add more unit-y tests for specific behaviors: # * fill terminal w/ columns + spacing # * line-wrap help text in its own column expected = """ Usage: inv[oke] [--core-opts] task1 [--task1-opts] ... taskN [--taskN-opts] Core options: --complete Print tab-completion candidates for given parse remainder. --no-dedupe Disable task deduplication. -c STRING, --collection=STRING Specify collection name to load. -d, --debug Enable debug output. -e, --echo Echo executed commands before running. -f STRING, --config=STRING Runtime configuration file to use. -h [STRING], --help[=STRING] Show core or per-task help and exit. -H STRING, --hide=STRING Set default value of run()'s 'hide' kwarg. -l, --list List available tasks. -p, --pty Use a pty when executing shell commands. -r STRING, --root=STRING Change root directory used for finding task modules. -V, --version Show version and exit. -w, --warn-only Warn, instead of failing, when shell commands fail. """.lstrip() for flag in ['-h', '--help']: _output_eq(flag, expected)
def tasks_dedupe_honors_configuration(self): # Kinda-sorta duplicates some tests in executor.py, but eh. with cd('configs'): # Runtime conf file _output_eq( '-c integration -f no-dedupe.yaml biz', """ foo foo bar biz post1 post2 post2 """.lstrip()) # Flag beats runtime _output_eq( '-c integration -f dedupe.yaml --no-dedupe biz', """ foo foo bar biz post1 post2 post2 """.lstrip())
def missing_default_collection_doesnt_say_None(self): with cd('/'): _output_eq( '-l', stderr="Can't find any collection named 'tasks'!\n", code=1 )
def chaining_is_depth_first(self): _output_eq('-c depth_first deploy', """ Cleaning HTML Cleaning .tar.gz files Cleaned everything Making directories Building Deploying Preparing for testing Testing """.lstrip())
def per_task_help_works_for_unparameterized_tasks(self): expected = """ Usage: inv[oke] [--core-opts] biz [other tasks here ...] Docstring: none Options: none """.lstrip() _output_eq('-c decorator -h biz', expected)
def per_task_help_displays_docstrings_if_given(self): expected = """ Usage: inv[oke] [--core-opts] foo [other tasks here ...] Docstring: Foo the bar. Options: none """.lstrip() _output_eq('-c decorator -h foo', expected)
def per_task_help_prints_help_for_task_only(self): expected = """ Usage: inv[oke] [--core-opts] punch [--options] [other tasks here ...] Docstring: none Options: -h STRING, --why=STRING Motive -w STRING, --who=STRING Who to punch """.lstrip() for flag in ['-h', '--help']: _output_eq('-c decorator {0} punch'.format(flag), expected)
def simple_output(self): expected = self._listing(( 'bar', 'biz', 'boz', 'foo', 'post1', 'post2', 'print_foo', 'print_name', 'print_underscored_arg', )) for flag in ('-l', '--list'): _output_eq('-c integration {0}'.format(flag), expected)
def per_task_help_dedents_correctly_for_alternate_docstring_style(self): expected = """ Usage: inv[oke] [--core-opts] foo3 [other tasks here ...] Docstring: Foo the other bar: example code Added in 1.1 Options: none """.lstrip() _output_eq('-c decorator -h foo3', expected)
def per_task_help_dedents_correctly(self): expected = """ Usage: inv[oke] [--core-opts] foo2 [other tasks here ...] Docstring: Foo the bar: example code Added in 1.0 Options: none """.lstrip() _output_eq('-c decorator -h foo2', expected)
def per_task_help_dedents_correctly_for_alt_docstring_style(self): expected = """ Usage: inv[oke] [--core-opts] foo3 [other tasks here ...] Docstring: Foo the other bar: example code Added in 1.1 Options: none """.lstrip() _output_eq('-c decorator -h foo3', expected)
def tasks_dedupe_honors_configuration(self): # Kinda-sorta duplicates some tests in executor.py, but eh. with cd('configs'): # Runtime conf file _output_eq('-c integration -f no-dedupe.yaml biz', """foo foo bar biz post1 post2 post2 """) # Flag beats runtime _output_eq('-c integration -f dedupe.yaml --no-dedupe biz', """foo foo bar biz post1 post2 post2 """)
def empty_collections_say_no_tasks(self): _output_eq("-c empty -l", "No tasks found in collection 'empty'!\n")
def missing_default_collection_doesnt_say_None(self): os.chdir('/') _output_eq('-l', stderr="Can't find any collection named 'tasks'!\n")
def version_info(self): _output_eq('-V', "Invoke %s\n" % invoke.__version__)
def _expect(self, args, expected): _output_eq('-c integration {0}'.format(args), expected.lstrip())
def version_info(self): _output_eq('-V', "Invoke {0}\n".format(invoke.__version__))
def prints_return_value_to_stdout_when_on_and_in_collection(self): _output_eq("-c autoprint sub.yup", "It's alive!\n")
def defaults_to_off_and_no_output(self): _output_eq("-c autoprint nope", "")
def does_not_fire_on_post_tasks(self): _output_eq("-c autoprint post_check", "")
def _list_eq(self, collection, listing): cmd = '-c {0} --list'.format(collection) _output_eq(cmd, self._listing(listing))
def no_input_means_just_task_names(self): _output_eq('-c simple_ns_list --complete', "z_toplevel\na.b.subtask\n")
def underscored_args(self): _output_eq( '-c integration print_underscored_arg --my-option whatevs', "whatevs\n", )
def args(self): _output_eq('-c integration print_name --name inigo', "inigo\n")
def prints_return_value_to_stdout_when_on(self): _output_eq("-c autoprint yup", "It's alive!\n")
def empty_collections_say_no_tasks(self): _output_eq( "-c empty -l", "No tasks found in collection 'empty'!\n" )
def missing_collection_yields_useful_error(self): _output_eq('-c huhwhat -l', stderr="Can't find any collection named 'huhwhat'!\n", code=1)
def missing_default_collection_doesnt_say_None(self): with cd('/'): _output_eq('-l', stderr="Can't find any collection named 'tasks'!\n", code=1)
def missing_collection_yields_useful_error(self): _output_eq( '-c huhwhat -l', stderr="Can't find any collection named 'huhwhat'!\n", code=1 )
def no_input_with_no_tasks_yields_empty_response(self): _output_eq('-c empty --complete', "")