mirror of
https://github.com/django/django.git
synced 2025-02-04 14:37:19 +00:00
color style
This commit is contained in:
parent
7adde65e56
commit
f810be610b
@ -205,6 +205,7 @@ class ManagementUtility:
|
||||
if self.prog_name == "__main__.py":
|
||||
self.prog_name = "python -m django"
|
||||
self.settings_exception = None
|
||||
self.style = color_style()
|
||||
|
||||
def main_help_text(self, commands_only=False):
|
||||
"""Return the script's main help text, as a string."""
|
||||
@ -225,16 +226,15 @@ class ManagementUtility:
|
||||
else:
|
||||
app = app.rpartition(".")[-1]
|
||||
commands_dict[app].append(name)
|
||||
style = color_style()
|
||||
for app in sorted(commands_dict):
|
||||
usage.append("")
|
||||
usage.append(style.NOTICE("[%s]" % app))
|
||||
usage.append(self.style.NOTICE("[%s]" % app))
|
||||
for name in sorted(commands_dict[app]):
|
||||
usage.append(" %s" % name)
|
||||
# Output an extra note if settings are not properly configured
|
||||
if self.settings_exception is not None:
|
||||
usage.append(
|
||||
style.NOTICE(
|
||||
self.style.NOTICE(
|
||||
"Note that only Django core commands are listed "
|
||||
"as settings are not properly configured (error: %s)."
|
||||
% self.settings_exception
|
||||
@ -258,7 +258,7 @@ class ManagementUtility:
|
||||
sys.stderr.write(self.style.NOTICE(str(self.settings_exception) + "\n"))
|
||||
sys.exit(1)
|
||||
elif not settings.configured:
|
||||
sys.stderr.write("No Django settings specified.\n")
|
||||
sys.stderr.write(self.style.NOTICE("No Django settings specified.\n"))
|
||||
sys.exit(1)
|
||||
possible_matches = get_close_matches(subcommand, commands)
|
||||
sys.stderr.write("Unknown command: %r" % subcommand)
|
||||
|
@ -225,7 +225,7 @@ class DjangoAdminNoSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -235,7 +235,7 @@ class DjangoAdminNoSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_commands_with_invalid_settings(self):
|
||||
"""
|
||||
@ -296,7 +296,7 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -306,7 +306,7 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -395,7 +395,7 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -405,7 +405,7 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -488,7 +488,7 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -498,7 +498,7 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"minimal: django-admin can't execute user commands unless settings are provided"
|
||||
@ -576,7 +576,7 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -586,7 +586,7 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -671,7 +671,7 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||
"""
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -681,7 +681,7 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -780,7 +780,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
||||
"""
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -790,7 +790,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_django_admin(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -854,7 +854,7 @@ class ManageNoSettings(AdminScriptTestCase):
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(
|
||||
err, "Settings module test_project.settings could not be imported\n"
|
||||
err, "Settings module 'test_project.settings' could not be imported.\n"
|
||||
)
|
||||
|
||||
def test_builtin_with_bad_settings(self):
|
||||
@ -865,13 +865,13 @@ class ManageNoSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_runserver_with_bad_settings(self):
|
||||
args = ["runserver", "--settings=bad_settings", "--nostatic"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_startapp_with_bad_settings(self):
|
||||
args = ["startapp", "--settings=bad_settings", "app1"]
|
||||
@ -887,7 +887,7 @@ class ManageNoSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_manage(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
|
||||
class ManageDefaultSettings(AdminScriptTestCase):
|
||||
@ -937,7 +937,7 @@ class ManageDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -947,7 +947,7 @@ class ManageDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_manage(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -1030,7 +1030,7 @@ class ManageFullPathDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -1040,7 +1040,7 @@ class ManageFullPathDefaultSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_manage(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"""
|
||||
@ -1119,7 +1119,7 @@ class ManageMinimalSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -1129,7 +1129,7 @@ class ManageMinimalSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_manage(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"minimal: manage.py can't execute user commands without appropriate settings"
|
||||
@ -1177,7 +1177,7 @@ class ManageAlternateSettings(AdminScriptTestCase):
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(
|
||||
err, "Settings module test_project.settings could not be imported\n"
|
||||
err, "Settings module 'test_project.settings' could not be imported.\n"
|
||||
)
|
||||
|
||||
def test_builtin_with_settings(self):
|
||||
@ -1205,7 +1205,7 @@ class ManageAlternateSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -1215,7 +1215,7 @@ class ManageAlternateSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_manage(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"alternate: manage.py can't execute user commands without settings"
|
||||
@ -1224,7 +1224,7 @@ class ManageAlternateSettings(AdminScriptTestCase):
|
||||
self.assertNoOutput(out)
|
||||
self.assertOutput(
|
||||
err,
|
||||
r"Settings module '?(test_project\.)?settings'? could not be imported",
|
||||
r"Settings module '?(test_project\.)?settings'? could not be imported.",
|
||||
regex=True,
|
||||
)
|
||||
|
||||
@ -1326,7 +1326,7 @@ class ManageMultipleSettings(AdminScriptTestCase):
|
||||
args = ["check", "--settings=bad_settings", "admin_scripts"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_builtin_with_bad_environment(self):
|
||||
"""
|
||||
@ -1336,7 +1336,7 @@ class ManageMultipleSettings(AdminScriptTestCase):
|
||||
args = ["check", "admin_scripts"]
|
||||
out, err = self.run_manage(args, "bad_settings")
|
||||
self.assertNoOutput(out)
|
||||
self.assertEqual(err, "Settings module bad_settings could not be imported\n")
|
||||
self.assertEqual(err, "Settings module 'bad_settings' could not be imported.\n")
|
||||
|
||||
def test_custom_command(self):
|
||||
"multiple: manage.py can't execute user commands using default settings"
|
||||
|
@ -339,7 +339,7 @@ class SettingsTests(SimpleTestCase):
|
||||
settings._setup()
|
||||
|
||||
def test_unable_to_import_settings_module(self):
|
||||
msg = "Settings module fake_settings_module could not be imported"
|
||||
msg = "Settings module 'fake_settings_module' could not be imported"
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
Settings("fake_settings_module")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user