# Path: tests/testapp/utils.py
# class CaptureLastQuery:
#     def __init__(self, conn=None):
#         if conn is None:  # pragma: no branch
#             conn = connection
#         self.conn = conn
# 
#     def __enter__(self):
#         self.capturer = CaptureQueriesContext(self.conn)
#         self.capturer.__enter__()
#         return self
# 
#     def __exit__(self, a, b, c):
#         self.capturer.__exit__(a, b, c)
# 
#     @property
#     def query(self):
#         return self.capturer.captured_queries[-1]["sql"]


from django.db import connection
from django.test import TestCase
from django.test.utils import override_settings
from django_mysql.rewrite_query import rewrite_query
from tests.testapp.utils import CaptureLastQuery

    def test_index_hint_multiple_indexes(self):
        assert rewrite_query(
            "SELECT col_a FROM `tabl` WHERE "
            "(/*QueryRewrite':index=`tabl` IGNORE `idx1`,`idx2`*/1)"
        ) == ("SELECT col_a FROM `tabl` IGNORE INDEX (`idx1`,`idx2`) WHERE " + "(1)")

    def test_index_hint_multiple_hints(self):
        assert rewrite_query(
            "SELECT col_a FROM `sometable` "
            + "WHERE (/*QueryRewrite':index=`sometable` IGNORE `idx1`*/1) "
            + "AND (/*QueryRewrite':index=`sometable` IGNORE `idx2`*/1)"
        ) == (
            "SELECT col_a FROM `sometable` IGNORE INDEX (`idx2`) "
            + "IGNORE INDEX (`idx1`) WHERE (1) AND (1)"
        )

    def test_index_hint_for_join(self):
        assert rewrite_query(
            "SELECT `sometable`.col_a, `sometable2`.col_b "
            + "FROM `sometable` NATURAL JOIN `sometable2` "
            + "WHERE (/*QueryRewrite':index=`sometable` IGNORE FOR JOIN "
            + "`idx`*/1)"
        ) == (
            "SELECT `sometable`.col_a, `sometable2`.col_b FROM "
            + "`sometable` IGNORE INDEX FOR JOIN (`idx`) NATURAL JOIN "
            + "`sometable2` WHERE (1)"
        )

    def test_index_hint_for_group_by(self):

# Path: tests/testapp/utils.py
# class CaptureLastQuery:
#     def __init__(self, conn=None):
#         if conn is None:  # pragma: no branch
#             conn = connection
#         self.conn = conn
# 
#     def __enter__(self):
#         self.capturer = CaptureQueriesContext(self.conn)
#         self.capturer.__enter__()
#         return self
# 
#     def __exit__(self, a, b, c):
#         self.capturer.__exit__(a, b, c)
# 
#     @property
#     def query(self):
#         return self.capturer.captured_queries[-1]["sql"]


# Path: tests/testapp/test_rewrite_query.py
from django.db import connection
from django.test import TestCase
from django.test.utils import override_settings
from django_mysql.rewrite_query import rewrite_query
from tests.testapp.utils import CaptureLastQuery


    def test_index_hint_multiple_indexes(self):
        assert rewrite_query(
            "SELECT col_a FROM `tabl` WHERE "
            "(/*QueryRewrite':index=`tabl` IGNORE `idx1`,`idx2`*/1)"
        ) == ("SELECT col_a FROM `tabl` IGNORE INDEX (`idx1`,`idx2`) WHERE " + "(1)")

    def test_index_hint_multiple_hints(self):
        assert rewrite_query(
            "SELECT col_a FROM `sometable` "
            + "WHERE (/*QueryRewrite':index=`sometable` IGNORE `idx1`*/1) "
            + "AND (/*QueryRewrite':index=`sometable` IGNORE `idx2`*/1)"
        ) == (
            "SELECT col_a FROM `sometable` IGNORE INDEX (`idx2`) "
            + "IGNORE INDEX (`idx1`) WHERE (1) AND (1)"
        )

    def test_index_hint_for_join(self):
        assert rewrite_query(
            "SELECT `sometable`.col_a, `sometable2`.col_b "
            + "FROM `sometable` NATURAL JOIN `sometable2` "
            + "WHERE (/*QueryRewrite':index=`sometable` IGNORE FOR JOIN "
            + "`idx`*/1)"
        ) == (
            "SELECT `sometable`.col_a, `sometable2`.col_b FROM "
            + "`sometable` IGNORE INDEX FOR JOIN (`idx`) NATURAL JOIN "
            + "`sometable2` WHERE (1)"
        )

    def test_index_hint_for_group_by(self):

        assert rewrite_query(