Ejemplo n.º 1
0
    def render_html(self, data):
        jinja_paths = []
        if self.jinja_paths:
            for jinja_path in self.jinja_paths.split(','):
                jinja_path = format_path(jinja_path.strip())
                if not os.path.isdir(jinja_path):
                    raise TemplateJinjaException("%r must be a folder" %
                                                 jinja_path)

                jinja_paths.append(jinja_path)

        jinja_env = SandboxedEnvironment(
            loader=jinja2.FileSystemLoader(jinja_paths),
            undefined=jinja2.StrictUndefined,
        )
        parser = self.get_parser()
        if not hasattr(parser, 'serialize_jinja_options'):
            raise TemplateJinjaException(
                ("The parser %r must declare a method "
                 "'serialize_jinja_options' for %r") % (parser, self))

        options = self.get_parser().serialize_jinja_options(self.options)
        return jinja_env.from_string(self.get_template()).render(
            data=data, str=str, **options).encode('utf-8')
Ejemplo n.º 2
0
 def test_format_path_with_invalid_path(self):
     with self.assertRaises(PathException):
         format_path('report#=#wrong/path')
Ejemplo n.º 3
0
 def test_format_path_with_module(self):
     self.assertEqual(format_path('report#=#tests/test_common.py'),
                      self.get_absolute_path())
Ejemplo n.º 4
0
 def test_format_path_without_module(self):
     self.assertEqual(format_path(self.get_absolute_path()),
                      self.get_absolute_path())
Ejemplo n.º 5
0
 def test_format_path_with_module(self):
     format_path_ = format_path('report#=#tests/test_common.py')
     assert format_path_ == self.get_absolute_path()
Ejemplo n.º 6
0
 def test_format_path_without_module(self):
     assert format_path(self.get_absolute_path()) == self.get_absolute_path()