def test_unexpected_template_type(): with pytest.raises( gluetool.GlueError, match= "Cannot render template: Unhandled template type <(type|class) 'int'>" ): render_template(17)
def test_missing_variable(): assert render_template(TEMPLATE) == 'This is a dummy template:'
def test_unexpected_template_type(): with pytest.raises(gluetool.GlueError, message="Unhandled template type <type 'int'>"): render_template(17)
def test_render(template): assert render_template(template, bar='baz') == 'This is a dummy template: baz'
def check_options(self): # type: () -> None Glue = self.Glue assert Glue is not None self.pipeline_desc = self._deduce_pipeline_desc( Glue.option('pipeline'), Glue.module_list()) log_dict(Glue.debug, 'pipeline description', self.pipeline_desc) # list modules groups = Glue.option('list-modules') if groups == [True]: sys.stdout.write('%s\n' % Glue.module_list_usage([])) sys.exit(0) elif groups: sys.stdout.write('%s\n' % Glue.module_list_usage(groups)) sys.exit(0) if Glue.option('list-shared'): functions = [] # type: List[List[str]] for mod_name in Glue.module_list(): # pylint: disable=line-too-long functions += [[func_name, mod_name] for func_name in Glue.modules[mod_name] ['class'].shared_functions] # Ignore PEP8Bear if functions: functions = sorted(functions, key=lambda row: row[0]) else: functions = [['-- no shared functions available --', '']] sys.stdout.write("""Available shared functions {} """.format( tabulate.tabulate(functions, ['Shared function', 'Module name'], tablefmt='simple'))) sys.exit(0) if Glue.option('list-eval-context'): variables = [] def _add_variables(source): # type: (gluetool.glue.Configurable) -> None info = extract_eval_context_info(source) for name, description in info.iteritems(): variables.append([ name, source.name, docstring_to_help(description, line_prefix='') ]) for mod_name in Glue.module_list(): _add_variables(Glue.init_module(mod_name)) _add_variables(Glue) if variables: variables = sorted(variables, key=lambda row: row[0]) else: variables = [['-- no variables available --', '', '']] table = tabulate.tabulate( variables, ['Variable', 'Module name', 'Description'], tablefmt='simple') print render_template(""" {{ '** Variables available in eval context **' | style(fg='yellow') }} {{ TABLE }} """, TABLE=table) sys.exit(0)