Skip to content

Commit

Permalink
Make empty_migration a constant not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Jan 3, 2023
1 parent f114737 commit f1459a9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
12 changes: 6 additions & 6 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_skipped_unspecified_app(self):

def test_dlm_E001(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)

result = check_max_migration_files()

Expand All @@ -66,7 +66,7 @@ def test_dlm_E001(self):

def test_dlm_E002(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text("line1\nline2\n")

result = check_max_migration_files()
Expand All @@ -77,7 +77,7 @@ def test_dlm_E002(self):

def test_dlm_E003(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text("0001_start\n")

result = check_max_migration_files()
Expand All @@ -91,7 +91,7 @@ def test_dlm_E003(self):

def test_dlm_E004(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_updates.py").write_text(
dedent(
"""
Expand All @@ -114,7 +114,7 @@ class Migration(migrations.Migration):

def test_dlm_E005(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "custom_name.py").write_text(
dedent(
"""
Expand Down Expand Up @@ -146,7 +146,7 @@ class Migration(migrations.Migration):

def test_okay(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_updates.py").write_text(
dedent(
"""
Expand Down
16 changes: 8 additions & 8 deletions tests/test_create_max_migration_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_success_only_init(self):
@override_settings(FIRST_PARTY_APPS=[])
def test_success_setting_not_first_party(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)

out, err, returncode = self.call_command()

Expand All @@ -90,7 +90,7 @@ def test_success_setting_not_first_party(self):

def test_success_dry_run(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)

out, err, returncode = self.call_command("--dry-run")

Expand All @@ -102,7 +102,7 @@ def test_success_dry_run(self):

def test_success(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)

out, err, returncode = self.call_command()

Expand All @@ -114,7 +114,7 @@ def test_success(self):

def test_success_already_exists(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text("0001_initial\n")

out, err, returncode = self.call_command()
Expand All @@ -125,7 +125,7 @@ def test_success_already_exists(self):

def test_success_recreate(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text("0001_initial\n")

out, err, returncode = self.call_command("--recreate")
Expand All @@ -136,7 +136,7 @@ def test_success_recreate(self):

def test_success_recreate_dry_run(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text("0001_initial\n")

out, err, returncode = self.call_command("--recreate", "--dry-run")
Expand All @@ -147,7 +147,7 @@ def test_success_recreate_dry_run(self):

def test_success_specific_app_label(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)

out, err, returncode = self.call_command("testapp")

Expand Down Expand Up @@ -175,7 +175,7 @@ def test_success_ignored_app_label(self):

def test_success_custom_migration_name(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "custom_name.py").write_text(
dedent(
"""
Expand Down
42 changes: 21 additions & 21 deletions tests/test_rebase_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_error_for_non_first_party_app(self):

def test_error_for_no_max_migration_txt(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)

with pytest.raises(CommandError) as excinfo:
self.call_command("testapp")
Expand All @@ -54,7 +54,7 @@ def test_error_for_no_max_migration_txt(self):

def test_error_for_no_migration_conflict(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text("0001_initial\n")

with pytest.raises(CommandError) as excinfo:
Expand All @@ -67,7 +67,7 @@ def test_error_for_no_migration_conflict(self):

def test_error_for_non_existent_merged_migration(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text(
dedent(
"""\
Expand All @@ -91,8 +91,8 @@ def test_error_for_non_existent_merged_migration(self):

def test_error_for_non_existent_rebased_migration(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text(
dedent(
"""\
Expand All @@ -116,9 +116,9 @@ def test_error_for_non_existent_rebased_migration(self):

def test_error_for_non_existent_rebased_migration_file(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0002_longer_titles.pyc").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.pyc").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text(
dedent(
"""\
Expand All @@ -141,9 +141,9 @@ def test_error_for_non_existent_rebased_migration_file(self):

def test_error_for_applied_migration(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0002_longer_titles.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(empty_migration)
(self.migrations_dir / "max_migration.txt").write_text(
dedent(
"""\
Expand All @@ -170,8 +170,8 @@ def test_error_for_applied_migration(self):

def test_error_for_missing_dependencies(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(
dedent(
"""\
Expand Down Expand Up @@ -203,8 +203,8 @@ class Migration(migrations.Migration):

def test_error_for_unparseable_dependencies(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(
dedent(
"""\
Expand Down Expand Up @@ -237,8 +237,8 @@ class Migration(migrations.Migration):

def test_error_for_no_dependencies(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(
dedent(
"""\
Expand Down Expand Up @@ -274,8 +274,8 @@ class Migration(migrations.Migration):

def test_error_for_double_dependencies(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_author_nicknames.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(
dedent(
"""\
Expand Down Expand Up @@ -312,7 +312,7 @@ class Migration(migrations.Migration):

def test_success(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(
dedent(
"""\
Expand Down Expand Up @@ -368,7 +368,7 @@ class Migration(migrations.Migration):

def test_success_swappable_dependency(self):
(self.migrations_dir / "__init__.py").touch()
(self.migrations_dir / "0001_initial.py").write_text(empty_migration())
(self.migrations_dir / "0001_initial.py").write_text(empty_migration)
(self.migrations_dir / "0002_longer_titles.py").write_text(
dedent(
"""\
Expand Down
15 changes: 7 additions & 8 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ def run_command(*args, **kwargs):
return out.getvalue(), err.getvalue(), returncode


def empty_migration() -> str:
return dedent(
"""
from django.db import migrations
class Migration(migrations.Migration):
pass
"""
)
empty_migration = dedent(
"""\
from django.db import migrations
class Migration(migrations.Migration):
pass
"""
)

0 comments on commit f1459a9

Please sign in to comment.