summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/admin_scripts/custom_templates/project_template/manage.py-tpl6
-rw-r--r--tests/admin_scripts/tests.py21
-rw-r--r--tests/migrations/test_commands.py36
-rw-r--r--tests/requirements/py3.txt1
4 files changed, 49 insertions, 15 deletions
diff --git a/tests/admin_scripts/custom_templates/project_template/manage.py-tpl b/tests/admin_scripts/custom_templates/project_template/manage.py-tpl
index d9843c433f..42a1fa6684 100755
--- a/tests/admin_scripts/custom_templates/project_template/manage.py-tpl
+++ b/tests/admin_scripts/custom_templates/project_template/manage.py-tpl
@@ -1,6 +1,6 @@
# The manage.py of the {{ project_name }} test project
# template context:
-project_name = '{{ project_name }}'
-project_directory = '{{ project_directory }}'
-secret_key = '{{ secret_key }}'
+project_name = "{{ project_name }}"
+project_directory = "{{ project_directory }}"
+secret_key = "{{ secret_key }}"
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 3d5902f768..9d2ca839d5 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -41,6 +41,8 @@ custom_templates_dir = os.path.join(os.path.dirname(__file__), "custom_templates
SYSTEM_CHECK_MSG = "System check identified no issues"
+HAS_BLACK = shutil.which("black")
+
class AdminScriptTestCase(SimpleTestCase):
def setUp(self):
@@ -732,7 +734,10 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
with open(os.path.join(app_path, "apps.py")) as f:
content = f.read()
self.assertIn("class SettingsTestConfig(AppConfig)", content)
- self.assertIn("name = 'settings_test'", content)
+ self.assertIn(
+ 'name = "settings_test"' if HAS_BLACK else "name = 'settings_test'",
+ content,
+ )
def test_setup_environ_custom_template(self):
"directory: startapp creates the correct directory with a custom template"
@@ -754,7 +759,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
with open(os.path.join(app_path, "apps.py"), encoding="utf8") as f:
content = f.read()
self.assertIn("class こんにちはConfig(AppConfig)", content)
- self.assertIn("name = 'こんにちは'", content)
+ self.assertIn('name = "こんにちは"' if HAS_BLACK else "name = 'こんにちは'", content)
def test_builtin_command(self):
"""
@@ -2614,8 +2619,8 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
test_manage_py = os.path.join(testproject_dir, "manage.py")
with open(test_manage_py) as fp:
content = fp.read()
- self.assertIn("project_name = 'another_project'", content)
- self.assertIn("project_directory = '%s'" % testproject_dir, content)
+ self.assertIn('project_name = "another_project"', content)
+ self.assertIn('project_directory = "%s"' % testproject_dir, content)
def test_no_escaping_of_project_variables(self):
"Make sure template context variables are not html escaped"
@@ -2880,11 +2885,15 @@ class StartApp(AdminScriptTestCase):
with open(os.path.join(app_path, "apps.py")) as f:
content = f.read()
self.assertIn("class NewAppConfig(AppConfig)", content)
+ if HAS_BLACK:
+ test_str = 'default_auto_field = "django.db.models.BigAutoField"'
+ else:
+ test_str = "default_auto_field = 'django.db.models.BigAutoField'"
+ self.assertIn(test_str, content)
self.assertIn(
- "default_auto_field = 'django.db.models.BigAutoField'",
+ 'name = "new_app"' if HAS_BLACK else "name = 'new_app'",
content,
)
- self.assertIn("name = 'new_app'", content)
class DiffSettings(AdminScriptTestCase):
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index b3d9972b0c..4d7918238e 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -2,6 +2,7 @@ import datetime
import importlib
import io
import os
+import shutil
import sys
from unittest import mock
@@ -28,6 +29,8 @@ from .models import UnicodeModel, UnserializableModel
from .routers import TestRouter
from .test_base import MigrationTestBase
+HAS_BLACK = shutil.which("black")
+
class MigrateTests(MigrationTestBase):
"""
@@ -1524,8 +1527,12 @@ class MakeMigrationsTests(MigrationTestBase):
# Remove all whitespace to check for empty dependencies and operations
content = content.replace(" ", "")
- self.assertIn("dependencies=[\n]", content)
- self.assertIn("operations=[\n]", content)
+ self.assertIn(
+ "dependencies=[]" if HAS_BLACK else "dependencies=[\n]", content
+ )
+ self.assertIn(
+ "operations=[]" if HAS_BLACK else "operations=[\n]", content
+ )
@override_settings(MIGRATION_MODULES={"migrations": None})
def test_makemigrations_disabled_migrations_for_app(self):
@@ -1661,6 +1668,13 @@ class MakeMigrationsTests(MigrationTestBase):
"0003_merge_0002_conflicting_second_0002_second.py",
)
self.assertIs(os.path.exists(merge_file), True)
+ with open(merge_file, encoding="utf-8") as fp:
+ content = fp.read()
+ if HAS_BLACK:
+ target_str = '("migrations", "0002_conflicting_second")'
+ else:
+ target_str = "('migrations', '0002_conflicting_second')"
+ self.assertIn(target_str, content)
self.assertIn("Created new merge migration %s" % merge_file, out.getvalue())
@mock.patch("django.db.migrations.utils.datetime")
@@ -2252,7 +2266,9 @@ class MakeMigrationsTests(MigrationTestBase):
# generate an initial migration
migration_name_0001 = "my_initial_migration"
content = cmd("0001", migration_name_0001)
- self.assertIn("dependencies=[\n]", content)
+ self.assertIn(
+ "dependencies=[]" if HAS_BLACK else "dependencies=[\n]", content
+ )
# importlib caches os.listdir() on some platforms like macOS
# (#23850).
@@ -2262,11 +2278,15 @@ class MakeMigrationsTests(MigrationTestBase):
# generate an empty migration
migration_name_0002 = "my_custom_migration"
content = cmd("0002", migration_name_0002, "--empty")
+ if HAS_BLACK:
+ template_str = 'dependencies=[\n("migrations","0001_%s"),\n]'
+ else:
+ template_str = "dependencies=[\n('migrations','0001_%s'),\n]"
self.assertIn(
- "dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001,
+ template_str % migration_name_0001,
content,
)
- self.assertIn("operations=[\n]", content)
+ self.assertIn("operations=[]" if HAS_BLACK else "operations=[\n]", content)
def test_makemigrations_with_invalid_custom_name(self):
msg = "The migration name must be a valid Python identifier."
@@ -2606,7 +2626,11 @@ class SquashMigrationsTests(MigrationTestBase):
)
with open(squashed_migration_file, encoding="utf-8") as fp:
content = fp.read()
- self.assertIn(" ('migrations', '0001_initial')", content)
+ if HAS_BLACK:
+ test_str = ' ("migrations", "0001_initial")'
+ else:
+ test_str = " ('migrations', '0001_initial')"
+ self.assertIn(test_str, content)
self.assertNotIn("initial = True", content)
out = out.getvalue()
self.assertNotIn(" - 0001_initial", out)
diff --git a/tests/requirements/py3.txt b/tests/requirements/py3.txt
index 7ce1ca9b2e..9092d4b7de 100644
--- a/tests/requirements/py3.txt
+++ b/tests/requirements/py3.txt
@@ -3,6 +3,7 @@ asgiref >= 3.4.1
argon2-cffi >= 16.1.0
backports.zoneinfo; python_version < '3.9'
bcrypt
+black
docutils
geoip2
jinja2 >= 2.9.2