def test_check_template(self): assert attrib.check_template('template_string') == None assert attrib.check_template('{{template_string') == (1, "unexpected end of template, expected 'end of print statement'.",) with open(get_test_loc('attrib_gen/test.template')) as tmpl: template = tmpl.read() assert attrib.check_template(template) == None
def test_check_template(self): assert attrib.check_template('template_string') == None assert attrib.check_template('{{template_string') == ( 1, "unexpected end of template, expected 'end of print statement'.", ) with open(get_test_loc('attrib_gen/test.template')) as tmpl: template = tmpl.read() assert attrib.check_template(template) == None
def test_check_template_all_builtin_templates_are_valid(self): builtin_templates_dir = os.path.dirname(attrib.DEFAULT_TEMPLATE_FILE) for template in os.listdir(builtin_templates_dir): template_loc = os.path.join(builtin_templates_dir, template) with io.open(template_loc, 'r', encoding='utf-8') as tmpl: template = tmpl.read() try: assert None == attrib.check_template(template) except: raise Exception(template_loc)
def test_check_template_complex_invalid_returns_error(self): template = ''' {% for about in abouts -%} {{ about.name.value }}: {{ about.version.value }} {% for res in about.about_ressdsdsdsdsdsdource.value -%} resource: {{] res }} {% endfor -%} {% endfor -%}''' expected = (5, "unexpected ']'") assert expected == attrib.check_template(template)
def test_check_template_complex_valid_returns_None(self): template = ''' {% for about in abouts -%} {{ about.name.value }}: {{ about.version.value }} {% for res in about.about_resource.value -%} resource: {{ res }} {% endfor -%} {% endfor -%}''' expected = None assert expected == attrib.check_template(template)
def validate_template(ctx, param, value): if not value: return DEFAULT_TEMPLATE_FILE with io.open(value, encoding='utf-8') as templatef: template_error = check_template(templatef.read()) if template_error: lineno, message = template_error raise click.UsageError('Template syntax error at line: ' '{lineno}: "{message}"'.format(**locals())) return value
def test_check_template_default_is_valid(self): with open(attrib.default_template) as tmpl: template = tmpl.read() assert attrib.check_template(template) == None
def test_check_template_invalid_return_error_lineno_and_message(self): expected = 1, "unexpected end of template, expected 'end of print statement'." assert expected == attrib.check_template('{{template_string')
def test_check_template_simple_valid_returns_None(self): expected = None assert expected == attrib.check_template('template_string')