From 0346563939396fb89dec8df31f82eaefaaeb8616 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 25 Jun 2013 09:37:54 +0800 Subject: Fixed #20653 -- Renamed checksetup management command. This is to allow future compatibility with work that is ongoing in the 2013 GSoC. --- django/core/checks/__init__.py | 0 django/core/checks/compatibility/__init__.py | 0 django/core/checks/compatibility/base.py | 39 +++++++++ django/core/checks/compatibility/django_1_6_0.py | 37 ++++++++ django/core/compat_checks/__init__.py | 0 django/core/compat_checks/base.py | 39 --------- django/core/compat_checks/django_1_6_0.py | 37 -------- django/core/management/commands/check.py | 14 +++ django/core/management/commands/checksetup.py | 14 --- docs/releases/1.6.txt | 6 +- tests/check/__init__.py | 0 tests/check/models.py | 1 + tests/check/tests.py | 107 +++++++++++++++++++++++ tests/compat_checks/__init__.py | 0 tests/compat_checks/models.py | 1 - tests/compat_checks/tests.py | 107 ----------------------- 16 files changed, 201 insertions(+), 201 deletions(-) create mode 100644 django/core/checks/__init__.py create mode 100644 django/core/checks/compatibility/__init__.py create mode 100644 django/core/checks/compatibility/base.py create mode 100644 django/core/checks/compatibility/django_1_6_0.py delete mode 100644 django/core/compat_checks/__init__.py delete mode 100644 django/core/compat_checks/base.py delete mode 100644 django/core/compat_checks/django_1_6_0.py create mode 100644 django/core/management/commands/check.py delete mode 100644 django/core/management/commands/checksetup.py create mode 100644 tests/check/__init__.py create mode 100644 tests/check/models.py create mode 100644 tests/check/tests.py delete mode 100644 tests/compat_checks/__init__.py delete mode 100644 tests/compat_checks/models.py delete mode 100644 tests/compat_checks/tests.py diff --git a/django/core/checks/__init__.py b/django/core/checks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/core/checks/compatibility/__init__.py b/django/core/checks/compatibility/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/core/checks/compatibility/base.py b/django/core/checks/compatibility/base.py new file mode 100644 index 0000000000..7fe52d2af9 --- /dev/null +++ b/django/core/checks/compatibility/base.py @@ -0,0 +1,39 @@ +from __future__ import unicode_literals +import warnings + +from django.core.checks.compatibility import django_1_6_0 + + +COMPAT_CHECKS = [ + # Add new modules at the top, so we keep things in descending order. + # After two-three minor releases, old versions should get dropped. + django_1_6_0, +] + + +def check_compatibility(): + """ + Runs through compatibility checks to warn the user with an existing install + about changes in an up-to-date Django. + + Modules should be located in ``django.core.compat_checks`` (typically one + per release of Django) & must have a ``run_checks`` function that runs + all the checks. + + Returns a list of informational messages about incompatibilities. + """ + messages = [] + + for check_module in COMPAT_CHECKS: + check = getattr(check_module, 'run_checks', None) + + if check is None: + warnings.warn( + "The '%s' module lacks a " % check_module.__name__ + + "'run_checks' method, which is needed to verify compatibility." + ) + continue + + messages.extend(check()) + + return messages diff --git a/django/core/checks/compatibility/django_1_6_0.py b/django/core/checks/compatibility/django_1_6_0.py new file mode 100644 index 0000000000..1998c5ba77 --- /dev/null +++ b/django/core/checks/compatibility/django_1_6_0.py @@ -0,0 +1,37 @@ +from __future__ import unicode_literals + + +def check_test_runner(): + """ + Checks if the user has *not* overridden the ``TEST_RUNNER`` setting & + warns them about the default behavior changes. + + If the user has overridden that setting, we presume they know what they're + doing & avoid generating a message. + """ + from django.conf import settings + new_default = 'django.test.runner.DiscoverRunner' + test_runner_setting = getattr(settings, 'TEST_RUNNER', new_default) + + if test_runner_setting == new_default: + message = [ + "You have not explicitly set 'TEST_RUNNER'. In Django 1.6,", + "there is a new test runner ('%s')" % new_default, + "by default. You should ensure your tests are still all", + "running & behaving as expected. See", + "https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module", + "for more information.", + ] + return ' '.join(message) + + +def run_checks(): + """ + Required by the ``check`` management command, this returns a list of + messages from all the relevant check functions for this version of Django. + """ + checks = [ + check_test_runner() + ] + # Filter out the ``None`` or empty strings. + return [output for output in checks if output] diff --git a/django/core/compat_checks/__init__.py b/django/core/compat_checks/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/django/core/compat_checks/base.py b/django/core/compat_checks/base.py deleted file mode 100644 index e54b50f287..0000000000 --- a/django/core/compat_checks/base.py +++ /dev/null @@ -1,39 +0,0 @@ -from __future__ import unicode_literals -import warnings - -from django.core.compat_checks import django_1_6_0 - - -COMPAT_CHECKS = [ - # Add new modules at the top, so we keep things in descending order. - # After two-three minor releases, old versions should get dropped. - django_1_6_0, -] - - -def check_compatibility(): - """ - Runs through compatibility checks to warn the user with an existing install - about changes in an up-to-date Django. - - Modules should be located in ``django.core.compat_checks`` (typically one - per release of Django) & must have a ``run_checks`` function that runs - all the checks. - - Returns a list of informational messages about incompatibilities. - """ - messages = [] - - for check_module in COMPAT_CHECKS: - check = getattr(check_module, 'run_checks', None) - - if check is None: - warnings.warn( - "The '%s' module lacks a " % check_module.__name__ + - "'run_checks' method, which is needed to verify compatibility." - ) - continue - - messages.extend(check()) - - return messages diff --git a/django/core/compat_checks/django_1_6_0.py b/django/core/compat_checks/django_1_6_0.py deleted file mode 100644 index bb0dabedac..0000000000 --- a/django/core/compat_checks/django_1_6_0.py +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import unicode_literals - - -def check_test_runner(): - """ - Checks if the user has *not* overridden the ``TEST_RUNNER`` setting & - warns them about the default behavior changes. - - If the user has overridden that setting, we presume they know what they're - doing & avoid generating a message. - """ - from django.conf import settings - new_default = 'django.test.runner.DiscoverRunner' - test_runner_setting = getattr(settings, 'TEST_RUNNER', new_default) - - if test_runner_setting == new_default: - message = [ - "You have not explicitly set 'TEST_RUNNER'. In Django 1.6,", - "there is a new test runner ('%s')" % new_default, - "by default. You should ensure your tests are still all", - "running & behaving as expected. See", - "https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module", - "for more information.", - ] - return ' '.join(message) - - -def run_checks(): - """ - Required by the ``checksetup`` management command, this returns a list of - messages from all the relevant check functions for this version of Django. - """ - checks = [ - check_test_runner() - ] - # Filter out the ``None`` or empty strings. - return [output for output in checks if output] diff --git a/django/core/management/commands/check.py b/django/core/management/commands/check.py new file mode 100644 index 0000000000..05f48c82bc --- /dev/null +++ b/django/core/management/commands/check.py @@ -0,0 +1,14 @@ +from __future__ import unicode_literals +import warnings + +from django.core.checks.compatibility.base import check_compatibility +from django.core.management.base import NoArgsCommand + + +class Command(NoArgsCommand): + help = "Checks your configuration's compatibility with this version " + \ + "of Django." + + def handle_noargs(self, **options): + for message in check_compatibility(): + warnings.warn(message) diff --git a/django/core/management/commands/checksetup.py b/django/core/management/commands/checksetup.py deleted file mode 100644 index d37e826757..0000000000 --- a/django/core/management/commands/checksetup.py +++ /dev/null @@ -1,14 +0,0 @@ -from __future__ import unicode_literals -import warnings - -from django.core.compat_checks.base import check_compatibility -from django.core.management.base import NoArgsCommand - - -class Command(NoArgsCommand): - help = "Checks your configuration's compatibility with this version " + \ - "of Django." - - def handle_noargs(self, **options): - for message in check_compatibility(): - warnings.warn(message) diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt index 95bfedc74e..086c10c389 100644 --- a/docs/releases/1.6.txt +++ b/docs/releases/1.6.txt @@ -121,10 +121,10 @@ GeoDjango now provides :ref:`form fields and widgets ` for its geo-specialized fields. They are OpenLayers-based by default, but they can be customized to use any other JS framework. -``checksetup`` management command added for verifying compatibility -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``check`` management command added for verifying compatibility +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -A ``checksetup`` management command was added, enabling you to verify if your +A ``check`` management command was added, enabling you to verify if your current configuration (currently oriented at settings) is compatible with the current version of Django. diff --git a/tests/check/__init__.py b/tests/check/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/check/models.py b/tests/check/models.py new file mode 100644 index 0000000000..78a10abba6 --- /dev/null +++ b/tests/check/models.py @@ -0,0 +1 @@ +# Stubby. diff --git a/tests/check/tests.py b/tests/check/tests.py new file mode 100644 index 0000000000..98495e38ae --- /dev/null +++ b/tests/check/tests.py @@ -0,0 +1,107 @@ +from django.core.checks.compatibility import base +from django.core.checks.compatibility import django_1_6_0 +from django.core.management.commands import check +from django.core.management import call_command +from django.test import TestCase + + +class StubCheckModule(object): + # Has no ``run_checks`` attribute & will trigger a warning. + __name__ = 'StubCheckModule' + + +class FakeWarnings(object): + def __init__(self): + self._warnings = [] + + def warn(self, message): + self._warnings.append(message) + + +class CompatChecksTestCase(TestCase): + def setUp(self): + super(CompatChecksTestCase, self).setUp() + + # We're going to override the list of checks to perform for test + # consistency in the future. + self.old_compat_checks = base.COMPAT_CHECKS + base.COMPAT_CHECKS = [ + django_1_6_0, + ] + + def tearDown(self): + # Restore what's supposed to be in ``COMPAT_CHECKS``. + base.COMPAT_CHECKS = self.old_compat_checks + super(CompatChecksTestCase, self).tearDown() + + def test_check_test_runner_new_default(self): + with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): + result = django_1_6_0.check_test_runner() + self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in result) + + def test_check_test_runner_overridden(self): + with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): + self.assertEqual(django_1_6_0.check_test_runner(), None) + + def test_run_checks_new_default(self): + with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): + result = django_1_6_0.run_checks() + self.assertEqual(len(result), 1) + self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in result[0]) + + def test_run_checks_overridden(self): + with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): + self.assertEqual(len(django_1_6_0.run_checks()), 0) + + def test_check_compatibility(self): + with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): + result = base.check_compatibility() + self.assertEqual(len(result), 1) + self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in result[0]) + + with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): + self.assertEqual(len(base.check_compatibility()), 0) + + def test_check_compatibility_warning(self): + # First, we're patching over the ``COMPAT_CHECKS`` with a stub which + # will trigger the warning. + base.COMPAT_CHECKS = [ + StubCheckModule(), + ] + + # Next, we unfortunately have to patch out ``warnings``. + old_warnings = base.warnings + base.warnings = FakeWarnings() + + self.assertEqual(len(base.warnings._warnings), 0) + + with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): + self.assertEqual(len(base.check_compatibility()), 0) + + self.assertEqual(len(base.warnings._warnings), 1) + self.assertTrue("The 'StubCheckModule' module lacks a 'run_checks'" in base.warnings._warnings[0]) + + # Restore the ``warnings``. + base.warnings = old_warnings + + def test_management_command(self): + # Again, we unfortunately have to patch out ``warnings``. Different + old_warnings = check.warnings + check.warnings = FakeWarnings() + + self.assertEqual(len(check.warnings._warnings), 0) + + # Should not produce any warnings. + with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): + call_command('check') + + self.assertEqual(len(check.warnings._warnings), 0) + + with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): + call_command('check') + + self.assertEqual(len(check.warnings._warnings), 1) + self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in check.warnings._warnings[0]) + + # Restore the ``warnings``. + base.warnings = old_warnings diff --git a/tests/compat_checks/__init__.py b/tests/compat_checks/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/compat_checks/models.py b/tests/compat_checks/models.py deleted file mode 100644 index 78a10abba6..0000000000 --- a/tests/compat_checks/models.py +++ /dev/null @@ -1 +0,0 @@ -# Stubby. diff --git a/tests/compat_checks/tests.py b/tests/compat_checks/tests.py deleted file mode 100644 index 879988c905..0000000000 --- a/tests/compat_checks/tests.py +++ /dev/null @@ -1,107 +0,0 @@ -from django.core.compat_checks import base -from django.core.compat_checks import django_1_6_0 -from django.core.management.commands import checksetup -from django.core.management import call_command -from django.test import TestCase - - -class StubCheckModule(object): - # Has no ``run_checks`` attribute & will trigger a warning. - __name__ = 'StubCheckModule' - - -class FakeWarnings(object): - def __init__(self): - self._warnings = [] - - def warn(self, message): - self._warnings.append(message) - - -class CompatChecksTestCase(TestCase): - def setUp(self): - super(CompatChecksTestCase, self).setUp() - - # We're going to override the list of checks to perform for test - # consistency in the future. - self.old_compat_checks = base.COMPAT_CHECKS - base.COMPAT_CHECKS = [ - django_1_6_0, - ] - - def tearDown(self): - # Restore what's supposed to be in ``COMPAT_CHECKS``. - base.COMPAT_CHECKS = self.old_compat_checks - super(CompatChecksTestCase, self).tearDown() - - def test_check_test_runner_new_default(self): - with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): - result = django_1_6_0.check_test_runner() - self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in result) - - def test_check_test_runner_overridden(self): - with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): - self.assertEqual(django_1_6_0.check_test_runner(), None) - - def test_run_checks_new_default(self): - with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): - result = django_1_6_0.run_checks() - self.assertEqual(len(result), 1) - self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in result[0]) - - def test_run_checks_overridden(self): - with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): - self.assertEqual(len(django_1_6_0.run_checks()), 0) - - def test_check_compatibility(self): - with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): - result = base.check_compatibility() - self.assertEqual(len(result), 1) - self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in result[0]) - - with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): - self.assertEqual(len(base.check_compatibility()), 0) - - def test_check_compatibility_warning(self): - # First, we're patching over the ``COMPAT_CHECKS`` with a stub which - # will trigger the warning. - base.COMPAT_CHECKS = [ - StubCheckModule(), - ] - - # Next, we unfortunately have to patch out ``warnings``. - old_warnings = base.warnings - base.warnings = FakeWarnings() - - self.assertEqual(len(base.warnings._warnings), 0) - - with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): - self.assertEqual(len(base.check_compatibility()), 0) - - self.assertEqual(len(base.warnings._warnings), 1) - self.assertTrue("The 'StubCheckModule' module lacks a 'run_checks'" in base.warnings._warnings[0]) - - # Restore the ``warnings``. - base.warnings = old_warnings - - def test_management_command(self): - # Again, we unfortunately have to patch out ``warnings``. Different - old_warnings = checksetup.warnings - checksetup.warnings = FakeWarnings() - - self.assertEqual(len(checksetup.warnings._warnings), 0) - - # Should not produce any warnings. - with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): - call_command('checksetup') - - self.assertEqual(len(checksetup.warnings._warnings), 0) - - with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): - call_command('checksetup') - - self.assertEqual(len(checksetup.warnings._warnings), 1) - self.assertTrue("You have not explicitly set 'TEST_RUNNER'" in checksetup.warnings._warnings[0]) - - # Restore the ``warnings``. - base.warnings = old_warnings -- cgit v1.3