def test_unicode_contents(self): """ Testing for the issue described in https://github.com/oTree-org/otree-core/issues/408 """ source = u'{% formfield player.contribution with label = "好" %}' # Should not raise UnicodeEncodeError format_source_snippet(source, arrow_position=0)
def template_has_valid_syntax(self, template_name): from otree.checks.templates import has_valid_encoding from otree.checks.templates import format_source_snippet # Only test files that are valid templates. if not has_valid_encoding(template_name): return try: with open(template_name, 'r') as f: Template(f.read()) except (IOError, OSError): pass except TemplateSyntaxError as error: # The django_template_source attribute will only be available on # DEBUG = True. if hasattr(error, 'django_template_source'): template_source, position = error.django_template_source snippet = format_source_snippet(template_source.source, arrow_position=position[0]) message = ('Template syntax error in {template}\n' '\n' '{snippet}\n' '\n' 'Error: {error}'.format(template=template_name, error=error, snippet=snippet)) else: message = ('Template syntax error in {template}\n' 'Error: {error}\n' 'Set "DEBUG = True" to see more details.'.format( template=template_name, error=error)) return self.error(message)
def template_has_valid_syntax(self, template_name): from otree.checks.templates import has_valid_encoding from otree.checks.templates import format_source_snippet # Only test files that are valid templates. if not has_valid_encoding(template_name): return try: with open(template_name, 'r') as f: Template(f.read()) except (IOError, OSError): pass except TemplateSyntaxError as error: template_source, position = error.django_template_source snippet = format_source_snippet( template_source.source, arrow_position=position[0]) return self.error( 'Template syntax error in {template}\n' '\n' '{snippet}\n' '\n' 'Error: {error}'.format( template=template_name, error=error, snippet=snippet))
def template_has_valid_syntax(self, template_name): from otree.checks.templates import has_valid_encoding from otree.checks.templates import format_source_snippet # Only test files that are valid templates. if not has_valid_encoding(template_name): return try: with open(template_name, 'r') as f: Template(f.read()) except (IOError, OSError): pass except TemplateSyntaxError as error: # The django_template_source attribute will only be available on # DEBUG = True. if hasattr(error, 'django_template_source'): template_source, position = error.django_template_source snippet = format_source_snippet( template_source.source, arrow_position=position[0]) message = ( 'Template syntax error in {template}\n' '\n' '{snippet}\n' '\n' 'Error: {error}'.format( template=template_name, error=error, snippet=snippet)) else: message = ( 'Template syntax error in {template}\n' 'Error: {error}\n' 'Set "DEBUG = True" to see more details.'.format( template=template_name, error=error)) return self.error(message)
def template_has_valid_syntax(self, template_name): from otree.checks.templates import has_valid_encoding from otree.checks.templates import format_source_snippet # Only test files that are valid templates. if not has_valid_encoding(template_name): return try: with open(template_name, 'r') as f: Template(f.read()) except (IOError, OSError): pass except TemplateSyntaxError as error: template_source, position = error.django_template_source snippet = format_source_snippet(template_source.source, arrow_position=position[0]) return self.error('Template syntax error in {template}\n' '\n' '{snippet}\n' '\n' 'Error: {error}'.format(template=template_name, error=error, snippet=snippet))