<commit_before>import unittest
from mock import patch, mock_open
from unittest.mock import MagicMock
from e2j2.helpers import templates

class TestTemplates(unittest.TestCase):
    def setUp(self):
        pass

    def test_find(self):
        # recurse = True
        with patch('e2j2.helpers.templates.os.walk') as recurse_mock:
            templates.find(searchlist='/etc', j2file_ext='.j2', recurse=True)
            recurse_mock.assert_called_with('/etc')

        # recurse = False
        with patch('e2j2.helpers.templates.os.listdir') as dirlist_mock:
            templates.find(searchlist='/etc', j2file_ext='.j2', recurse=False)
            dirlist_mock.assert_called_with('/etc')

    def test_get_vars(self):
        with patch('e2j2.helpers.templates.os') as os_mock:
            os_mock.environ = {'FOO_ENV': 'json:{"key": "value"}'}
            self.assertEqual(templates.get_vars(), {})<commit_msg>add more tests<commit_after>import unittest
from mock import patch
from e2j2.helpers import templates


class TestTemplates(unittest.TestCase):
    def setUp(self):
        pass

    def test_find(self):
        # recurse = True
        with patch('e2j2.helpers.templates.os.walk') as recurse_mock:
            templates.find(searchlist='/etc', j2file_ext='.j2', recurse=True)
            recurse_mock.assert_called_with('/etc')

        # recurse = False
        with patch('e2j2.helpers.templates.os.listdir') as dirlist_mock:
            templates.find(searchlist='/etc', j2file_ext='.j2', recurse=False)
            dirlist_mock.assert_called_with('/etc')

    def test_get_vars(self):
        with patch('e2j2.helpers.templates.os') as os_mock:
            os_mock.environ = {'FOO_ENV': 'json:{"key": "value"}'}
            self.assertEqual(templates.get_vars(), {'FOO_ENV': {'key': 'value'}})

        with patch('e2j2.helpers.templates.os') as os_mock:
            os_mock.environ = {'FOO_ENV': 'json:{"key": "value"}'}

            with patch('e2j2.helpers.templates.parsers.parse_tag', return_value='** ERROR: Key not found **'):
                self.assertEqual(templates.get_vars(), {'FOO_ENV': '** ERROR: Key not found **'})

    def test_render(self):
        # one pass
        with patch('e2j2.helpers.templates.jinja2.Environment') as jinja2_mock:
            jinja2_mock.return_value.get_template.return_value.render.return_value='rendered template'

            response = templates.render(
                        j2file='/foo/file1.j2',
                        twopass=False,
                        block_start='{%',
                        block_end='%}',
                        variable_start='{{',
                        variable_end='}}',
                        comment_start='{#',
                        comment_end='#}',
                        j2vars={"FOO": "BAR"})

            jinja2_mock.return_value.get_template.assert_called_with('file1.j2')
            jinja2_mock.return_value.get_template.return_value.render.assert_called_with({"FOO": "BAR"})
            self.assertEqual(response, 'rendered template')

        # two pass

if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.13258785942492013, 'fraction_numerical': 0.013099041533546326, 'mean_word_length': 2.467331118493909, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 3, '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': '3480189', 'n_tokens_mistral': 983, 'n_tokens_neox': 967, 'n_words': 161}