# Path: mutant/utils.py
# def remove_from_app_cache(model_class, quiet=False):
#     opts = model_class._meta
#     apps = opts.apps
#     app_label, model_name = opts.app_label, opts.model_name
#     with apps_lock():
#         try:
#             model_class = apps.app_configs[app_label].models.pop(model_name)
#         except KeyError:
#             if not quiet:
#                 raise ValueError("%r is not cached" % model_class)
#         apps.clear_cache()
#         unreference_model(model_class)
#     return model_class
# 
# Path: tests/utils.py
# class BaseModelDefinitionTestCase(ModelDefinitionDDLTestCase):
#     @classmethod
#     def setUpTestData(cls):
#         model_def = ModelDefinition.objects.create(app_label='mutant', object_name='Model')
#         cls.model_def_pk = model_def.pk
# 
#     def setUp(self):
#         self.model_def = ModelDefinition.objects.get(pk=self.model_def_pk)
# 
#     @classmethod
#     @contextmanager
#     def assertChecksumChange(cls, model_def=None):
#         if not model_def:
#             model_def = ModelDefinition.objects.get(pk=cls.model_def_pk)
#         checksum = model_def.model_class().checksum()
#         yield
#         if model_def.model_class().checksum() == checksum:
#             raise AssertionError("Checksum of model %s should have changed." % model_def)
# 
#     @classmethod
#     @contextmanager
#     def assertChecksumDoesntChange(cls, model_def=None):
#         if not model_def:
#             model_def = ModelDefinition.objects.get(pk=cls.model_def_pk)
#         try:
#             with cls.assertChecksumChange(model_def):
#                 yield
#         except AssertionError:
#             pass
#         else:
#             model_class = model_def.model_class()
#             raise AssertionError("Checksum of model %s shouldn't have changed." % model_class)
# 
#     def assertTableExists(self, db, table):
#         tables = connections[db].introspection.table_names()
#         msg = "Table '%s.%s' doesn't exist, existing tables are %s"
#         self.assertTrue(table in tables, msg % (db, table, tables))
# 
#     def assertTableDoesntExists(self, db, table):
#         tables = connections[db].introspection.table_names()
#         msg = "Table '%s.%s' exists, existing tables are %s"
#         self.assertFalse(table in tables, msg % (db, table, tables))
# 
#     def assertModelTablesExist(self, model):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertTableExists(db, table)
# 
#     def assertModelTablesDontExist(self, model):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertTableDoesntExists(db, table)
# 
#     def assertColumnExists(self, db, table, column):
#         columns = tuple(table_columns_iterator(db, table))
#         data = {
#             'db': db,
#             'table': table,
#             'column': column,
#             'columns': columns
#         }
#         self.assertIn(column, columns,
#                       "Column '%(db)s.%(table)s.%(column)s' doesn't exist, "
#                       "%(db)s.'%(table)s's columns are %(columns)s" % data)
# 
#     def assertColumnDoesntExists(self, db, table, column):
#         self.assertRaises(
#             AssertionError, self.assertColumnExists, db, table, column
#         )
# 
#     def assertModelTablesColumnExists(self, model, column):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertColumnExists(db, table, column)
# 
#     def assertModelTablesColumnDoesntExists(self, model, column):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertColumnDoesntExists(db, table, column)


import json
from tempfile import NamedTemporaryFile
from django.core.management import call_command
from django.core.serializers.base import DeserializationError
from django.core.serializers.json import Serializer as JSONSerializer
from django.utils.encoding import force_bytes
from django.utils.six import StringIO
from mutant.utils import remove_from_app_cache
from .utils import BaseModelDefinitionTestCase
                'model': str(self.model_def).lower(),
                'fields': {}
            }]
        )


class BytesWritter(object):
    def __init__(self, stream):
        self._stream = stream

    def __getattr__(self, name):
        return getattr(self._stream, name)

    def write(self, data):
        self._stream.write(force_bytes(data))


class LoadDataTestCase(DataCommandTestCase):
    def setUp(self):
        super(LoadDataTestCase, self).setUp()
        self.serializer = JSONSerializer()

    def test_load_mutable_models(self):
        """
        Makes sure mutable models instances are correctly loaded when calling
        `loaddata`.
        """
        instance = self.model_cls(pk=1)
        # Make sure to remove the model from the app cache because we're
        # actually testing it's correctly loaded.

# Path: mutant/utils.py
# def remove_from_app_cache(model_class, quiet=False):
#     opts = model_class._meta
#     apps = opts.apps
#     app_label, model_name = opts.app_label, opts.model_name
#     with apps_lock():
#         try:
#             model_class = apps.app_configs[app_label].models.pop(model_name)
#         except KeyError:
#             if not quiet:
#                 raise ValueError("%r is not cached" % model_class)
#         apps.clear_cache()
#         unreference_model(model_class)
#     return model_class
# 
# Path: tests/utils.py
# class BaseModelDefinitionTestCase(ModelDefinitionDDLTestCase):
#     @classmethod
#     def setUpTestData(cls):
#         model_def = ModelDefinition.objects.create(app_label='mutant', object_name='Model')
#         cls.model_def_pk = model_def.pk
# 
#     def setUp(self):
#         self.model_def = ModelDefinition.objects.get(pk=self.model_def_pk)
# 
#     @classmethod
#     @contextmanager
#     def assertChecksumChange(cls, model_def=None):
#         if not model_def:
#             model_def = ModelDefinition.objects.get(pk=cls.model_def_pk)
#         checksum = model_def.model_class().checksum()
#         yield
#         if model_def.model_class().checksum() == checksum:
#             raise AssertionError("Checksum of model %s should have changed." % model_def)
# 
#     @classmethod
#     @contextmanager
#     def assertChecksumDoesntChange(cls, model_def=None):
#         if not model_def:
#             model_def = ModelDefinition.objects.get(pk=cls.model_def_pk)
#         try:
#             with cls.assertChecksumChange(model_def):
#                 yield
#         except AssertionError:
#             pass
#         else:
#             model_class = model_def.model_class()
#             raise AssertionError("Checksum of model %s shouldn't have changed." % model_class)
# 
#     def assertTableExists(self, db, table):
#         tables = connections[db].introspection.table_names()
#         msg = "Table '%s.%s' doesn't exist, existing tables are %s"
#         self.assertTrue(table in tables, msg % (db, table, tables))
# 
#     def assertTableDoesntExists(self, db, table):
#         tables = connections[db].introspection.table_names()
#         msg = "Table '%s.%s' exists, existing tables are %s"
#         self.assertFalse(table in tables, msg % (db, table, tables))
# 
#     def assertModelTablesExist(self, model):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertTableExists(db, table)
# 
#     def assertModelTablesDontExist(self, model):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertTableDoesntExists(db, table)
# 
#     def assertColumnExists(self, db, table, column):
#         columns = tuple(table_columns_iterator(db, table))
#         data = {
#             'db': db,
#             'table': table,
#             'column': column,
#             'columns': columns
#         }
#         self.assertIn(column, columns,
#                       "Column '%(db)s.%(table)s.%(column)s' doesn't exist, "
#                       "%(db)s.'%(table)s's columns are %(columns)s" % data)
# 
#     def assertColumnDoesntExists(self, db, table, column):
#         self.assertRaises(
#             AssertionError, self.assertColumnExists, db, table, column
#         )
# 
#     def assertModelTablesColumnExists(self, model, column):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertColumnExists(db, table, column)
# 
#     def assertModelTablesColumnDoesntExists(self, model, column):
#         table = model._meta.db_table
#         for db in allow_migrate(model):
#             self.assertColumnDoesntExists(db, table, column)


# Path: tests/test_commands.py
import json
from tempfile import NamedTemporaryFile
from django.core.management import call_command
from django.core.serializers.base import DeserializationError
from django.core.serializers.json import Serializer as JSONSerializer
from django.utils.encoding import force_bytes
from django.utils.six import StringIO
from mutant.utils import remove_from_app_cache
from .utils import BaseModelDefinitionTestCase

                'model': str(self.model_def).lower(),
                'fields': {}
            }]
        )


class BytesWritter(object):
    def __init__(self, stream):
        self._stream = stream

    def __getattr__(self, name):
        return getattr(self._stream, name)

    def write(self, data):
        self._stream.write(force_bytes(data))


class LoadDataTestCase(DataCommandTestCase):
    def setUp(self):
        super(LoadDataTestCase, self).setUp()
        self.serializer = JSONSerializer()

    def test_load_mutable_models(self):
        """
        Makes sure mutable models instances are correctly loaded when calling
        `loaddata`.
        """
        instance = self.model_cls(pk=1)
        # Make sure to remove the model from the app cache because we're
        # actually testing it's correctly loaded.

        remove_from_app_cache(self.model_cls)