<commit_before>from jinja2.exceptions import UndefinedError

from discharge.plugins.jinja2_templates import Jinja2TemplatesPlugin
from discharge.site import Site

from .base import Test


class TestTemplatesPlugin(Test):

    source_dir = 'test_plugin_jinja2_templates'

    def setup(self):
        super(TestTemplatesPlugin, self).setup()
        self.templates_plugin = Jinja2TemplatesPlugin()
        self.site.add_plugin(self.templates_plugin)
        self.site.build()

    def test_non_template(self):
        with open(self.build_path + '/test.txt') as f:
            assert f.read().strip() == '{{"test"}}'

    def test_template(self):
        with open(self.build_path + '/test.html') as f:
            assert f.read().strip() == 'test'

    def test_escaping(self):
        with open(self.build_path + '/test_escaping.html') as f:
            assert f.read().strip() == '&lt;b&gt;HI&lt;/b&gt;'

    def test_var_file(self):
        with open(self.build_path + '/test_var_file.html') as f:
            assert f.read().strip() == '/test_var_file.html'

    def test_var_base_path(self):
        with open(self.build_path + '/test_var_base_path.html') as f:
            assert f.read().strip() == ''

    def test_pygments(self):
        with open(self.build_path + '/test_pygments.html') as f:
            assert f.read().strip() == (
                """<div class="highlight"><pre><span class="kn">import"""
                """</span> <span class="nn">love</span>\n"""
                """</pre></div>"""
            )


class TestTemplatesPluginBasePath(Test):

    source_dir = 'test_plugin_jinja2_templates'

    def setup(self):
        super(TestTemplatesPluginBasePath, self).setup()
        self.site = Site(self.source_path, self.build_path, '/foo')
        templates_plugin = Jinja2TemplatesPlugin()
        self.site.add_plugin(templates_plugin)
        self.site.build()

    def test_var_base_path(self):
        with open(self.build_path + '/test_var_base_path.html') as f:
            assert f.read().strip() == '/foo'


class TestTemplatesPluginUndefined(Test):<commit_msg>add a test for server watching templates<commit_after>from jinja2.exceptions import UndefinedError

from discharge.plugins.jinja2_templates import Jinja2TemplatesPlugin
from discharge.site import Site

from .base import Test


class TestTemplatesPlugin(Test):

    source_dir = 'test_plugin_jinja2_templates'

    def setup(self):
        super(TestTemplatesPlugin, self).setup()
        self.templates_plugin = Jinja2TemplatesPlugin()
        self.site.add_plugin(self.templates_plugin)
        self.build_context = self.site.build()

    def test_non_template(self):
        with open(self.build_path + '/test.txt') as f:
            assert f.read().strip() == '{{"test"}}'

    def test_template(self):
        with open(self.build_path + '/test.html') as f:
            assert f.read().strip() == 'test'

    def test_escaping(self):
        with open(self.build_path + '/test_escaping.html') as f:
            assert f.read().strip() == '&lt;b&gt;HI&lt;/b&gt;'

    def test_var_file(self):
        with open(self.build_path + '/test_var_file.html') as f:
            assert f.read().strip() == '/test_var_file.html'

    def test_var_base_path(self):
        with open(self.build_path + '/test_var_base_path.html') as f:
            assert f.read().strip() == ''

    def test_pygments(self):
        with open(self.build_path + '/test_pygments.html') as f:
            assert f.read().strip() == (
                """<div class="highlight"><pre><span class="kn">import"""
                """</span> <span class="nn">love</span>\n"""
                """</pre></div>"""
            )

    def test_template_logged(self):
        assert "/test.html" in self.build_context


class TestTemplatesPluginBasePath(Test):

    source_dir = 'test_plugin_jinja2_templates'

    def setup(self):
        super(TestTemplatesPluginBasePath, self).setup()
        self.site = Site(self.source_path, self.build_path, '/foo')
        templates_plugin = Jinja2TemplatesPlugin()
        self.site.add_plugin(templates_plugin)
        self.site.build()

    def test_var_base_path(self):
        with open(self.build_path + '/test_var_base_path.html') as f:
            assert f.read().strip() == '/foo'


class TestTemplatesPluginUndefined(Test):
{'fraction_non_alphanumeric': 0.13899792195797736, 'fraction_numerical': 0.0032325098129762178, 'mean_word_length': 2.881720430107527, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3302203', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1336, 'n_words': 254}