summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2025-07-22 20:41:41 -0700
committernessita <124304+nessita@users.noreply.github.com>2025-07-23 20:17:55 -0300
commit69a93a88edb56ba47f624dac7a21aacc47ea474f (patch)
treef57507a4435d032493cae40e06ecb254790b67b2 /tests/migrations
parent55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff)
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'tests/migrations')
-rw-r--r--tests/migrations/test_autodetector.py79
-rw-r--r--tests/migrations/test_base.py3
-rw-r--r--tests/migrations/test_commands.py26
-rw-r--r--tests/migrations/test_executor.py10
-rw-r--r--tests/migrations/test_loader.py4
-rw-r--r--tests/migrations/test_operations.py9
-rw-r--r--tests/migrations/test_state.py10
7 files changed, 83 insertions, 58 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index dae8a7f3ba..c5d630293e 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -2080,8 +2080,9 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_rename_field_preserve_db_column_preserve_constraint(self):
"""
- Renaming a field that already had a db_column attribute and a constraint
- generates two no-op operations: RenameField and AlterConstraint.
+ Renaming a field that already had a db_column attribute and a
+ constraint generates two no-op operations: RenameField and
+ AlterConstraint.
"""
before = [
ModelState(
@@ -2566,7 +2567,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_circular_fk_dependency(self):
"""
Having a circular ForeignKey dependency automatically
- resolves the situation into 2 migrations on one side and 1 on the other.
+ resolves the situation into 2 migrations on one side and 1 on the
+ other.
"""
changes = self.get_changes(
[], [self.author_with_book, self.book, self.publisher_with_book]
@@ -2665,7 +2667,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_alter_db_table_no_changes(self):
"""
- Alter_db_table doesn't generate a migration if no changes have been made.
+ Alter_db_table doesn't generate a migration if no changes have been
+ made.
"""
changes = self.get_changes(
[self.author_with_db_table_options], [self.author_with_db_table_options]
@@ -2675,8 +2678,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_keep_db_table_with_model_change(self):
"""
- Tests when model changes but db_table stays as-is, autodetector must not
- create more than one operation.
+ Tests when model changes but db_table stays as-is, autodetector must
+ not create more than one operation.
"""
changes = self.get_changes(
[self.author_with_db_table_options],
@@ -4089,16 +4092,16 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstructible_list(self):
"""Nested deconstruction descends into lists."""
- # When lists contain items that deconstruct to identical values, those lists
- # should be considered equal for the purpose of detecting state changes
- # (even if the original items are unequal).
+ # When lists contain items that deconstruct to identical values, those
+ # lists should be considered equal for the purpose of detecting state
+ # changes (even if the original items are unequal).
changes = self.get_changes(
[self.author_name_deconstructible_list_1],
[self.author_name_deconstructible_list_2],
)
self.assertEqual(changes, {})
- # Legitimate differences within the deconstructed lists should be reported
- # as a change
+ # Legitimate differences within the deconstructed lists should be
+ # reported as a change
changes = self.get_changes(
[self.author_name_deconstructible_list_1],
[self.author_name_deconstructible_list_3],
@@ -4107,16 +4110,16 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstructible_tuple(self):
"""Nested deconstruction descends into tuples."""
- # When tuples contain items that deconstruct to identical values, those tuples
- # should be considered equal for the purpose of detecting state changes
- # (even if the original items are unequal).
+ # When tuples contain items that deconstruct to identical values, those
+ # tuples should be considered equal for the purpose of detecting state
+ # changes (even if the original items are unequal).
changes = self.get_changes(
[self.author_name_deconstructible_tuple_1],
[self.author_name_deconstructible_tuple_2],
)
self.assertEqual(changes, {})
- # Legitimate differences within the deconstructed tuples should be reported
- # as a change
+ # Legitimate differences within the deconstructed tuples should be
+ # reported as a change
changes = self.get_changes(
[self.author_name_deconstructible_tuple_1],
[self.author_name_deconstructible_tuple_3],
@@ -4125,16 +4128,16 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstructible_dict(self):
"""Nested deconstruction descends into dict values."""
- # When dicts contain items whose values deconstruct to identical values,
- # those dicts should be considered equal for the purpose of detecting
- # state changes (even if the original values are unequal).
+ # When dicts contain items whose values deconstruct to identical
+ # values, those dicts should be considered equal for the purpose of
+ # detecting state changes (even if the original values are unequal).
changes = self.get_changes(
[self.author_name_deconstructible_dict_1],
[self.author_name_deconstructible_dict_2],
)
self.assertEqual(changes, {})
- # Legitimate differences within the deconstructed dicts should be reported
- # as a change
+ # Legitimate differences within the deconstructed dicts should be
+ # reported as a change
changes = self.get_changes(
[self.author_name_deconstructible_dict_1],
[self.author_name_deconstructible_dict_3],
@@ -4146,16 +4149,17 @@ class AutodetectorTests(BaseAutodetectorTests):
Nested deconstruction is applied recursively to the args/kwargs of
deconstructed objects.
"""
- # If the items within a deconstructed object's args/kwargs have the same
- # deconstructed values - whether or not the items themselves are different
- # instances - then the object as a whole is regarded as unchanged.
+ # If the items within a deconstructed object's args/kwargs have the
+ # same deconstructed values - whether or not the items themselves are
+ # different instances - then the object as a whole is regarded as
+ # unchanged.
changes = self.get_changes(
[self.author_name_nested_deconstructible_1],
[self.author_name_nested_deconstructible_2],
)
self.assertEqual(changes, {})
- # Differences that exist solely within the args list of a deconstructed object
- # should be reported as changes
+ # Differences that exist solely within the args list of a deconstructed
+ # object should be reported as changes
changes = self.get_changes(
[self.author_name_nested_deconstructible_1],
[self.author_name_nested_deconstructible_changed_arg],
@@ -4167,8 +4171,8 @@ class AutodetectorTests(BaseAutodetectorTests):
[self.author_name_nested_deconstructible_extra_arg],
)
self.assertEqual(len(changes), 1)
- # Differences that exist solely within the kwargs dict of a deconstructed object
- # should be reported as changes
+ # Differences that exist solely within the kwargs dict of a
+ # deconstructed object should be reported as changes
changes = self.get_changes(
[self.author_name_nested_deconstructible_1],
[self.author_name_nested_deconstructible_changed_kwarg],
@@ -4183,8 +4187,8 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_deconstruct_type(self):
"""
- #22951 -- Uninstantiated classes with deconstruct are correctly returned
- by deep_deconstruct during serialization.
+ #22951 -- Uninstantiated classes with deconstruct are correctly
+ returned by deep_deconstruct during serialization.
"""
author = ModelState(
"testapp",
@@ -4243,7 +4247,9 @@ class AutodetectorTests(BaseAutodetectorTests):
side_effect=AssertionError("Should not have prompted for not null addition"),
)
def test_add_many_to_many(self, mocked_ask_method):
- """#22435 - Adding a ManyToManyField should not prompt for a default."""
+ """
+ #22435 - Adding a ManyToManyField should not prompt for a default.
+ """
changes = self.get_changes(
[self.author_empty, self.publisher], [self.author_with_m2m, self.publisher]
)
@@ -4362,9 +4368,9 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_many_to_many_removed_before_through_model_2(self):
"""
- Removing a model that contains a ManyToManyField and the "through" model
- in the same change must remove the field before the model to maintain
- consistency.
+ Removing a model that contains a ManyToManyField and the "through"
+ model in the same change must remove the field before the model to
+ maintain consistency.
"""
changes = self.get_changes(
[
@@ -4459,8 +4465,9 @@ class AutodetectorTests(BaseAutodetectorTests):
def test_non_circular_foreignkey_dependency_removal(self):
"""
- If two models with a ForeignKey from one to the other are removed at the
- same time, the autodetector should remove them in the correct order.
+ If two models with a ForeignKey from one to the other are removed at
+ the same time, the autodetector should remove them in the correct
+ order.
"""
changes = self.get_changes(
[self.author_with_publisher, self.publisher_with_author], []
diff --git a/tests/migrations/test_base.py b/tests/migrations/test_base.py
index 41041f51e8..b636d18ec4 100644
--- a/tests/migrations/test_base.py
+++ b/tests/migrations/test_base.py
@@ -21,7 +21,8 @@ from django.utils.module_loading import module_dir
class MigrationTestBase(TransactionTestCase):
"""
- Contains an extended set of asserts for testing migrations and schema operations.
+ Contains an extended set of asserts for testing migrations and schema
+ operations.
"""
available_apps = ["migrations"]
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index cd49a5a8fc..b5817081d2 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -463,7 +463,8 @@ class MigrateTests(MigrationTestBase):
call_command("migrate", "migrations", "0001", verbosity=0)
out = io.StringIO()
- # Giving the explicit app_label tests for selective `show_list` in the command
+ # Giving the explicit app_label tests for selective `show_list` in the
+ # command
call_command(
"showmigrations",
"migrations",
@@ -1696,7 +1697,8 @@ class MakeMigrationsTests(MigrationTestBase):
self.assertEqual(has_table.call_count, 4)
def test_failing_migration(self):
- # If a migration fails to serialize, it shouldn't generate an empty file. #21280
+ # If a migration fails to serialize, it shouldn't generate an empty
+ # file. #21280
apps.register_model("migrations", UnserializableModel)
with self.temporary_migration_module() as migration_dir:
@@ -1754,7 +1756,8 @@ class MakeMigrationsTests(MigrationTestBase):
with open(initial_file, encoding="utf-8") as fp:
content = fp.read()
- # Remove all whitespace to check for empty dependencies and operations
+ # Remove all whitespace to check for empty dependencies and
+ # operations
content = content.replace(" ", "")
self.assertIn(
"dependencies=[]" if HAS_BLACK else "dependencies=[\n]", content
@@ -1778,7 +1781,8 @@ class MakeMigrationsTests(MigrationTestBase):
def test_makemigrations_no_changes_no_apps(self):
"""
- makemigrations exits when there are no changes and no apps are specified.
+ makemigrations exits when there are no changes and no apps are
+ specified.
"""
out = io.StringIO()
call_command("makemigrations", stdout=out)
@@ -2165,7 +2169,8 @@ class MakeMigrationsTests(MigrationTestBase):
def test_makemigrations_handle_merge(self):
"""
- makemigrations properly merges the conflicting migrations with --noinput.
+ makemigrations properly merges the conflicting migrations with
+ --noinput.
"""
out = io.StringIO()
with self.temporary_migration_module(
@@ -2965,8 +2970,9 @@ class SquashMigrationsTests(MigrationTestBase):
with self.temporary_migration_module(
module="migrations.test_migrations_squashed_loop"
):
- # Hits a squash replacement cycle check error, but the actual failure is
- # dependent on the order in which the files are read on disk.
+ # Hits a squash replacement cycle check error, but the actual
+ # failure is dependent on the order in which the files are read on
+ # disk.
with self.assertRaisesRegex(
CommandError,
r"Cyclical squash replacement found, starting at"
@@ -3039,7 +3045,8 @@ class SquashMigrationsTests(MigrationTestBase):
interactive=False,
)
- # Update the 4th migration to depend on the squash(replacement) migration.
+ # Update the 4th migration to depend on the squash(replacement)
+ # migration.
loader = MigrationLoader(connection)
migration = loader.disk_migrations[
("migrations", "0004_remove_mymodel1_field_1_mymodel1_field_3_and_more")
@@ -3219,7 +3226,8 @@ class SquashMigrationsTests(MigrationTestBase):
def test_squashmigrations_invalid_start(self):
"""
- squashmigrations doesn't accept a starting migration after the ending migration.
+ squashmigrations doesn't accept a starting migration after the ending
+ migration.
"""
with self.temporary_migration_module(
module="migrations.test_migrations_no_changes"
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
index 571cb3e1a2..dd6793b533 100644
--- a/tests/migrations/test_executor.py
+++ b/tests/migrations/test_executor.py
@@ -78,7 +78,8 @@ class ExecutorTests(MigrationTestBase):
)
def test_run_with_squashed(self):
"""
- Tests running a squashed migration from zero (should ignore what it replaces)
+ Tests running a squashed migration from zero (should ignore what it
+ replaces)
"""
executor = MigrationExecutor(connection)
# Check our leaf node is the squashed one
@@ -351,7 +352,8 @@ class ExecutorTests(MigrationTestBase):
self.assertTableExists("migrations_tribble")
# Make sure that was faked
self.assertIs(state["faked"], True)
- # Finally, migrate forwards; this should fake-apply our initial migration
+ # Finally, migrate forwards; this should fake-apply our initial
+ # migration
executor.loader.build_graph()
self.assertEqual(
executor.migration_plan([("migrations", "0001_initial")]),
@@ -383,8 +385,8 @@ class ExecutorTests(MigrationTestBase):
)
def test_custom_user(self):
"""
- Regression test for #22325 - references to a custom user model defined in the
- same app are not resolved correctly.
+ Regression test for #22325 - references to a custom user model defined
+ in the same app are not resolved correctly.
"""
with isolate_lru_cache(global_apps.get_swappable_settings_name):
executor = MigrationExecutor(connection)
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
index 3b30aed100..7cf11f7faa 100644
--- a/tests/migrations/test_loader.py
+++ b/tests/migrations/test_loader.py
@@ -515,7 +515,9 @@ class LoaderTests(TestCase):
}
)
def test_loading_squashed_ref_squashed(self):
- "Tests loading a squashed migration with a new migration referencing it"
+ """
+ Tests loading a squashed migration with a new migration referencing it
+ """
r"""
The sample migrations are structured like this:
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index f86fe16fe0..a893442ce6 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -955,7 +955,8 @@ class OperationTests(OperationTestBase):
operation.state_forwards("test_rmwsc", new_state)
self.assertNotIn(("test_rmwsc", "shetlandpony"), new_state.models)
self.assertIn(("test_rmwsc", "littlehorse"), new_state.models)
- # RenameModel shouldn't repoint the superclass's relations, only local ones
+ # RenameModel shouldn't repoint the superclass's relations, only local
+ # ones
self.assertEqual(
project_state.models["test_rmwsc", "rider"]
.fields["pony"]
@@ -2616,7 +2617,8 @@ class OperationTests(OperationTestBase):
@skipUnlessDBFeature("supports_foreign_keys")
def test_alter_field_pk_fk(self):
"""
- Tests the AlterField operation on primary keys changes any FKs pointing to it.
+ Tests the AlterField operation on primary keys changes any FKs pointing
+ to it.
"""
project_state = self.set_up_test_model("test_alflpkfk", related_model=True)
project_state = self.apply_operations(
@@ -5782,7 +5784,8 @@ class OperationTests(OperationTestBase):
non_atomic_migration.operations = [
migrations.RunPython(inner_method, reverse_code=inner_method, atomic=False)
]
- # If we're a fully-transactional database, both versions should rollback
+ # If we're a fully-transactional database, both versions should
+ # rollback
if connection.features.can_rollback_ddl:
self.assertEqual(
project_state.apps.get_model(
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py
index d6ecaa1c5d..c31f8b80dd 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -183,11 +183,12 @@ class StateTests(SimpleTestCase):
self.assertTrue(all(isinstance(name, str) for name, mgr in food_state.managers))
self.assertEqual(food_state.managers[0][1].args, ("a", "b", 1, 2))
- # No explicit managers defined. Migrations will fall back to the default
+ # No explicit managers defined. Migrations will fall back to the
+ # default
self.assertEqual(food_no_managers_state.managers, [])
- # food_mgr is used in migration but isn't the default mgr, hence add the
- # default
+ # food_mgr is used in migration but isn't the default mgr, hence add
+ # the default
self.assertEqual(
[name for name, mgr in food_no_default_manager_state.managers],
["food_no_mgr", "food_mgr"],
@@ -1302,7 +1303,8 @@ class StateRelationsTests(SimpleTestCase):
with self.subTest(method=method):
project_state = self.get_base_project_state()
getattr(project_state, method)(*args)
- # ProjectState's `_relations` are populated on `relations` access.
+ # ProjectState's `_relations` are populated on `relations`
+ # access.
self.assertIsNone(project_state._relations)
self.assertEqual(project_state.relations, project_state._relations)
self.assertIsNotNone(project_state._relations)