# Path: kibitzr/transformer/jinja_transform.py
# class JinjaTransform(object):
# 
#     def __init__(self, code, conf):
#         from jinja2 import Environment
#         environment = Environment()
#         environment.filters['text'] = text_filter
#         environment.filters['int'] = int_filter
#         environment.filters['float'] = float_filter
#         environment.filters['dollars'] = dollars_filter
#         self.template = environment.from_string(code)
#         self.conf = conf
# 
#     def render(self, content, context=None):
#         from jinja2 import TemplateError
#         try:
#             return True, self.template.render(context or self.context(content))
#         except TemplateError:
#             logger.warning("Jinja render failed", exc_info=True)
#             return False, None
#     __call__ = render
# 
#     def context(self, content):
#         html = LazyHTML(content)
#         xml = LazyXML(content)
#         return {
#             'conf': self.conf,
#             'stash': LazyStash(),
#             'content': content,
#             'lines': content.splitlines(),
#             'json': LazyJSON(content),
#             'css': html.css,
#             'xpath': xml.xpath,
#             'env': os.environ,
#         }
# 
# Path: tests/helpers.py
# @contextlib.contextmanager
# def stash_mock():
#     with tempfile.NamedTemporaryFile() as fp:
#         fp.close()
#         with mock.patch.object(Stash, 'FILENAME', fp.name):
#             yield Stash()


from kibitzr.transformer.jinja_transform import JinjaTransform
from ...helpers import stash_mock
    ok, content = jinja_transform('{{ lines[1] }}', 'a\nb')
    assert ok is True
    assert content == "b"


def test_json_is_passed():
    ok, content = jinja_transform('{{ json["a"][1] }}', '{"a": [1, 2, 3]}')
    assert ok is True
    assert content == "2"


def test_css_selector_is_passed():
    ok, content = jinja_transform(
        '{{ css("div p") | text }}',
        '<div><a>A</a><p>P</p></div>',
    )
    assert ok is True
    assert content == "P"


def test_xpath_selector_is_passed():
    ok, content = jinja_transform(
        '{{ xpath("//div/p") | text }}',
        '<div><a>A</a><p>P</p></div>',
    )
    assert ok is True
    assert content == "P"


def test_stash_is_passed():

# Path: kibitzr/transformer/jinja_transform.py
# class JinjaTransform(object):
# 
#     def __init__(self, code, conf):
#         from jinja2 import Environment
#         environment = Environment()
#         environment.filters['text'] = text_filter
#         environment.filters['int'] = int_filter
#         environment.filters['float'] = float_filter
#         environment.filters['dollars'] = dollars_filter
#         self.template = environment.from_string(code)
#         self.conf = conf
# 
#     def render(self, content, context=None):
#         from jinja2 import TemplateError
#         try:
#             return True, self.template.render(context or self.context(content))
#         except TemplateError:
#             logger.warning("Jinja render failed", exc_info=True)
#             return False, None
#     __call__ = render
# 
#     def context(self, content):
#         html = LazyHTML(content)
#         xml = LazyXML(content)
#         return {
#             'conf': self.conf,
#             'stash': LazyStash(),
#             'content': content,
#             'lines': content.splitlines(),
#             'json': LazyJSON(content),
#             'css': html.css,
#             'xpath': xml.xpath,
#             'env': os.environ,
#         }
# 
# Path: tests/helpers.py
# @contextlib.contextmanager
# def stash_mock():
#     with tempfile.NamedTemporaryFile() as fp:
#         fp.close()
#         with mock.patch.object(Stash, 'FILENAME', fp.name):
#             yield Stash()


# Path: tests/unit/transforms/test_jinja.py
from kibitzr.transformer.jinja_transform import JinjaTransform
from ...helpers import stash_mock

    ok, content = jinja_transform('{{ lines[1] }}', 'a\nb')
    assert ok is True
    assert content == "b"


def test_json_is_passed():
    ok, content = jinja_transform('{{ json["a"][1] }}', '{"a": [1, 2, 3]}')
    assert ok is True
    assert content == "2"


def test_css_selector_is_passed():
    ok, content = jinja_transform(
        '{{ css("div p") | text }}',
        '<div><a>A</a><p>P</p></div>',
    )
    assert ok is True
    assert content == "P"


def test_xpath_selector_is_passed():
    ok, content = jinja_transform(
        '{{ xpath("//div/p") | text }}',
        '<div><a>A</a><p>P</p></div>',
    )
    assert ok is True
    assert content == "P"


def test_stash_is_passed():

    with stash_mock() as stash: