# Path: tests/testapp/models.py
# class AgedCustomer(Customer):
#     age = IntegerField(default=21)
# 
# class Alphabet(Model):
#     a = IntegerField(default=1)
#     b = IntegerField(default=2)
#     c = IntegerField(default=3)
#     d = CharField(max_length=32)
#     e = CharField(max_length=32, null=True)
#     f = IntegerField(null=True)
#     g = DecimalField(default=0, decimal_places=2, max_digits=10)
# 
# class Customer(Model):
#     name = CharField(max_length=32)
# 
# class ProxyAlphabet(Alphabet):
#     class Meta:
#         proxy = True
# 
#     @property
#     def a_times_b(self):
#         return self.a * self.b
# 
# class TitledAgedCustomer(AgedCustomer):
#     class Meta:
#         db_table = "titled aged customer"  # Test name quoting
# 
#     title = CharField(max_length=16)


import queue
import pytest
from threading import Thread
from typing import TYPE_CHECKING
from django.db import OperationalError, connection, connections
from django.db.transaction import TransactionManagementError, atomic
from django.test import TestCase, TransactionTestCase
from django_mysql.exceptions import TimeoutError
from django_mysql.locks import Lock, TableLock
from django_mysql.models import Model
from django_mysql.utils import connection_is_mariadb
from tests.testapp.models import (
    AgedCustomer,
    Alphabet,
    Customer,
    ProxyAlphabet,
    TitledAgedCustomer,
)
        if cls.supports_lock_info and not cls.lock_info_preinstalled:
            with connection.cursor() as cursor:
                cursor.execute("UNINSTALL SONAME 'metadata_lock_info'")
        super().tearDownClass()

    def test_simple(self):
        mylock = Lock("mylock")
        assert not mylock.is_held()

        with mylock:
            assert mylock.is_held()
            assert Lock("mylock").is_held()

            cursor = connection.cursor()
            cursor.execute("SELECT CONNECTION_ID();")
            own_connection_id = cursor.fetchone()[0]
            assert mylock.holding_connection_id() == own_connection_id

        assert not mylock.is_held()
        assert not Lock("mylock").is_held()

    def test_error_on_unneeded_exit(self):
        mylock = Lock("mylock")
        assert not mylock.is_held()
        with pytest.raises(ValueError) as excinfo:
            mylock.__exit__(None, None, None)
        assert "unheld lock" in str(excinfo.value)

    import_time_lock = Lock("defined_at_import_time")


# Path: tests/testapp/models.py
# class AgedCustomer(Customer):
#     age = IntegerField(default=21)
# 
# class Alphabet(Model):
#     a = IntegerField(default=1)
#     b = IntegerField(default=2)
#     c = IntegerField(default=3)
#     d = CharField(max_length=32)
#     e = CharField(max_length=32, null=True)
#     f = IntegerField(null=True)
#     g = DecimalField(default=0, decimal_places=2, max_digits=10)
# 
# class Customer(Model):
#     name = CharField(max_length=32)
# 
# class ProxyAlphabet(Alphabet):
#     class Meta:
#         proxy = True
# 
#     @property
#     def a_times_b(self):
#         return self.a * self.b
# 
# class TitledAgedCustomer(AgedCustomer):
#     class Meta:
#         db_table = "titled aged customer"  # Test name quoting
# 
#     title = CharField(max_length=16)


# Path: tests/testapp/test_locks.py
import queue
import pytest
from threading import Thread
from typing import TYPE_CHECKING
from django.db import OperationalError, connection, connections
from django.db.transaction import TransactionManagementError, atomic
from django.test import TestCase, TransactionTestCase
from django_mysql.exceptions import TimeoutError
from django_mysql.locks import Lock, TableLock
from django_mysql.models import Model
from django_mysql.utils import connection_is_mariadb
from tests.testapp.models import (
    AgedCustomer,
    Alphabet,
    Customer,
    ProxyAlphabet,
    TitledAgedCustomer,
)

        if cls.supports_lock_info and not cls.lock_info_preinstalled:
            with connection.cursor() as cursor:
                cursor.execute("UNINSTALL SONAME 'metadata_lock_info'")
        super().tearDownClass()

    def test_simple(self):
        mylock = Lock("mylock")
        assert not mylock.is_held()

        with mylock:
            assert mylock.is_held()
            assert Lock("mylock").is_held()

            cursor = connection.cursor()
            cursor.execute("SELECT CONNECTION_ID();")
            own_connection_id = cursor.fetchone()[0]
            assert mylock.holding_connection_id() == own_connection_id

        assert not mylock.is_held()
        assert not Lock("mylock").is_held()

    def test_error_on_unneeded_exit(self):
        mylock = Lock("mylock")
        assert not mylock.is_held()
        with pytest.raises(ValueError) as excinfo:
            mylock.__exit__(None, None, None)
        assert "unheld lock" in str(excinfo.value)

    import_time_lock = Lock("defined_at_import_time")


    def test_defined_at_import_time(self):