# Path: mako/ext/linguaplugin.py
# class LinguaMakoExtractor(Extractor, MessageExtractor):
#     """Mako templates"""
# 
#     use_bytes = False
#     extensions = [".mako"]
#     default_config = {"encoding": "utf-8", "comment-tags": ""}
# 
#     def __call__(self, filename, options, fileobj=None):
#         self.options = options
#         self.filename = filename
#         self.python_extractor = get_extractor("x.py")
#         if fileobj is None:
#             ctx = open(filename, "r")
#         else:
#             ctx = contextlib.nullcontext(fileobj)
#         with ctx as file_:
#             yield from self.process_file(file_)
# 
#     def process_python(self, code, code_lineno, translator_strings):
#         source = code.getvalue().strip()
#         if source.endswith(":"):
#             if source in ("try:", "else:") or source.startswith("except"):
#                 source = ""  # Ignore try/except and else
#             elif source.startswith("elif"):
#                 source = source[2:]  # Replace "elif" with "if"
#             source += "pass"
#         code = io.StringIO(source)
#         for msg in self.python_extractor(
#             self.filename, self.options, code, code_lineno - 1
#         ):
#             if translator_strings:
#                 msg = Message(
#                     msg.msgctxt,
#                     msg.msgid,
#                     msg.msgid_plural,
#                     msg.flags,
#                     " ".join(translator_strings + [msg.comment]),
#                     msg.tcomment,
#                     msg.location,
#                 )
#             yield msg
# 
# Path: mako/testing/assertions.py
# def eq_(a, b, msg=None):
#     """Assert a == b, with repr messaging on failure."""
#     assert a == b, msg or "%r != %r" % (a, b)
# 
# Path: mako/testing/config.py
# class Config(ReadsCfg):
# 
# Path: mako/testing/exclusions.py
# def _pygments_version():
# def requires_no_pygments_exceptions(fn):
#     def go(*arg, **kw):
# 
# Path: mako/testing/fixtures.py
# class TemplateTest:
#     def _file_template(self, filename, **kw):
#         filepath = self._file_path(filename)
#         return Template(
#             uri=filename,
#             filename=filepath,
#             module_directory=config.module_base,
#             **kw,
#         )
# 
#     def _file_path(self, filename):
#         name, ext = os.path.splitext(filename)
#         py3k_path = os.path.join(config.template_base, name + "_py3k" + ext)
#         if os.path.exists(py3k_path):
#             return py3k_path
# 
#         return os.path.join(config.template_base, filename)
# 
#     def _do_file_test(
#         self,
#         filename,
#         expected,
#         filters=None,
#         unicode_=True,
#         template_args=None,
#         **kw,
#     ):
#         t1 = self._file_template(filename, **kw)
#         self._do_test(
#             t1,
#             expected,
#             filters=filters,
#             unicode_=unicode_,
#             template_args=template_args,
#         )
# 
#     def _do_memory_test(
#         self,
#         source,
#         expected,
#         filters=None,
#         unicode_=True,
#         template_args=None,
#         **kw,
#     ):
#         t1 = Template(text=source, **kw)
#         self._do_test(
#             t1,
#             expected,
#             filters=filters,
#             unicode_=unicode_,
#             template_args=template_args,
#         )
# 
#     def _do_test(
#         self,
#         template,
#         expected,
#         filters=None,
#         template_args=None,
#         unicode_=True,
#     ):
#         if template_args is None:
#             template_args = {}
#         if unicode_:
#             output = template.render_unicode(**template_args)
#         else:
#             output = template.render(**template_args)
# 
#         if filters:
#             output = filters(output)
#         eq_(output, expected)


import os
import pytest
from mako.ext.linguaplugin import LinguaMakoExtractor
from mako.testing.assertions import eq_
from mako.testing.config import config
from mako.testing.exclusions import requires_lingua
from mako.testing.fixtures import TemplateTest
        from lingua.extractors import register_extractors




class MockOptions:
    keywords = []
    domain = None
    comment_tag = True


@requires_lingua
class MakoExtractTest(TemplateTest):
    @pytest.fixture(autouse=True)
    def register_lingua_extractors(self):

        register_extractors()

    def test_extract(self):
        plugin = LinguaMakoExtractor({"comment-tags": "TRANSLATOR"})
        messages = list(
            plugin(
                os.path.join(config.template_base, "gettext.mako"),
                MockOptions(),
            )
        )
        msgids = [(m.msgid, m.msgid_plural) for m in messages]
        eq_(
            msgids,

# Path: mako/ext/linguaplugin.py
# class LinguaMakoExtractor(Extractor, MessageExtractor):
#     """Mako templates"""
# 
#     use_bytes = False
#     extensions = [".mako"]
#     default_config = {"encoding": "utf-8", "comment-tags": ""}
# 
#     def __call__(self, filename, options, fileobj=None):
#         self.options = options
#         self.filename = filename
#         self.python_extractor = get_extractor("x.py")
#         if fileobj is None:
#             ctx = open(filename, "r")
#         else:
#             ctx = contextlib.nullcontext(fileobj)
#         with ctx as file_:
#             yield from self.process_file(file_)
# 
#     def process_python(self, code, code_lineno, translator_strings):
#         source = code.getvalue().strip()
#         if source.endswith(":"):
#             if source in ("try:", "else:") or source.startswith("except"):
#                 source = ""  # Ignore try/except and else
#             elif source.startswith("elif"):
#                 source = source[2:]  # Replace "elif" with "if"
#             source += "pass"
#         code = io.StringIO(source)
#         for msg in self.python_extractor(
#             self.filename, self.options, code, code_lineno - 1
#         ):
#             if translator_strings:
#                 msg = Message(
#                     msg.msgctxt,
#                     msg.msgid,
#                     msg.msgid_plural,
#                     msg.flags,
#                     " ".join(translator_strings + [msg.comment]),
#                     msg.tcomment,
#                     msg.location,
#                 )
#             yield msg
# 
# Path: mako/testing/assertions.py
# def eq_(a, b, msg=None):
#     """Assert a == b, with repr messaging on failure."""
#     assert a == b, msg or "%r != %r" % (a, b)
# 
# Path: mako/testing/config.py
# class Config(ReadsCfg):
# 
# Path: mako/testing/exclusions.py
# def _pygments_version():
# def requires_no_pygments_exceptions(fn):
#     def go(*arg, **kw):
# 
# Path: mako/testing/fixtures.py
# class TemplateTest:
#     def _file_template(self, filename, **kw):
#         filepath = self._file_path(filename)
#         return Template(
#             uri=filename,
#             filename=filepath,
#             module_directory=config.module_base,
#             **kw,
#         )
# 
#     def _file_path(self, filename):
#         name, ext = os.path.splitext(filename)
#         py3k_path = os.path.join(config.template_base, name + "_py3k" + ext)
#         if os.path.exists(py3k_path):
#             return py3k_path
# 
#         return os.path.join(config.template_base, filename)
# 
#     def _do_file_test(
#         self,
#         filename,
#         expected,
#         filters=None,
#         unicode_=True,
#         template_args=None,
#         **kw,
#     ):
#         t1 = self._file_template(filename, **kw)
#         self._do_test(
#             t1,
#             expected,
#             filters=filters,
#             unicode_=unicode_,
#             template_args=template_args,
#         )
# 
#     def _do_memory_test(
#         self,
#         source,
#         expected,
#         filters=None,
#         unicode_=True,
#         template_args=None,
#         **kw,
#     ):
#         t1 = Template(text=source, **kw)
#         self._do_test(
#             t1,
#             expected,
#             filters=filters,
#             unicode_=unicode_,
#             template_args=template_args,
#         )
# 
#     def _do_test(
#         self,
#         template,
#         expected,
#         filters=None,
#         template_args=None,
#         unicode_=True,
#     ):
#         if template_args is None:
#             template_args = {}
#         if unicode_:
#             output = template.render_unicode(**template_args)
#         else:
#             output = template.render(**template_args)
# 
#         if filters:
#             output = filters(output)
#         eq_(output, expected)


# Path: test/ext/test_linguaplugin.py
import os
import pytest
from mako.ext.linguaplugin import LinguaMakoExtractor
from mako.testing.assertions import eq_
from mako.testing.config import config
from mako.testing.exclusions import requires_lingua
from mako.testing.fixtures import TemplateTest
        from lingua.extractors import register_extractors





class MockOptions:
    keywords = []
    domain = None
    comment_tag = True


@requires_lingua
class MakoExtractTest(TemplateTest):
    @pytest.fixture(autouse=True)
    def register_lingua_extractors(self):

        register_extractors()

    def test_extract(self):
        plugin = LinguaMakoExtractor({"comment-tags": "TRANSLATOR"})
        messages = list(
            plugin(
                os.path.join(config.template_base, "gettext.mako"),
                MockOptions(),
            )
        )
        msgids = [(m.msgid, m.msgid_plural) for m in messages]
        eq_(
            msgids,

            [