Ticket #22194: listtags.diff

File listtags.diff, 2.9 KB (added by Tomáš Ehrlich, 11 years ago)

Add --list-tags option to 'check' management command.

  • django/core/checks/registry.py

    diff --git a/django/core/checks/registry.py b/django/core/checks/registry.py
    index 21efbf3..18487cd 100644
    a b class CheckRegistry(object):  
    5454        return errors
    5555
    5656    def tag_exists(self, tag):
    57         tags = chain(*[check.tags for check in self.registered_checks if hasattr(check, 'tags')])
    58         return tag in tags
     57        return tag in self.tags_available()
     58
     59    def tags_available(self):
     60        return chain(*[check.tags for check in self.registered_checks if hasattr(check, 'tags')])
    5961
    6062
    6163registry = CheckRegistry()
  • django/core/management/commands/check.py

    diff --git a/django/core/management/commands/check.py b/django/core/management/commands/check.py
    index b6d2571..b0587f9 100644
    a b from optparse import make_option  
    55
    66from django.apps import apps
    77from django.core import checks
     8from django.core.checks.registry import registry
    89from django.core.management.base import BaseCommand, CommandError
    910
    1011
    class Command(BaseCommand):  
    1617    option_list = BaseCommand.option_list + (
    1718        make_option('--tag', '-t', action='append', dest='tags',
    1819            help='Run only checks labeled with given tag.'),
     20        make_option('--list-tags', action='store_true', dest='list_tags',
     21                    help='List available tags.'),
    1922    )
    2023
    2124    def handle(self, *app_labels, **options):
     25        if options.get('list_tags', False):
     26            self.stdout.write('\n'.join(registry.tags_available()))
     27            return
     28
    2229        if app_labels:
    2330            app_configs = [apps.get_app_config(app_label) for app_label in app_labels]
    2431        else:
  • docs/ref/django-admin.txt

    diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
    index 4571c24..6008338 100644
    a b to perform only security and compatibility checks, you would run::  
    126126
    127127    python manage.py check --tag security --tag compatibility
    128128
     129.. django-admin-option:: --list-tags
     130
     131List all available tags.
     132
    129133compilemessages
    130134---------------
    131135
  • tests/check_framework/tests.py

    diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py
    index c770ee5..af407f5 100644
    a b class CheckCommandTests(TestCase):  
    194194    def test_invalid_tag(self):
    195195        self.assertRaises(CommandError, call_command, 'check', tags=['missingtag'])
    196196
     197    @override_system_checks([simple_system_check])
     198    def test_list_tags_empty(self):
     199        call_command('check', list_tags=True)
     200        self.assertEqual('\n', sys.stdout.getvalue())
     201
     202    @override_system_checks([tagged_system_check])
     203    def test_list_tags(self):
     204        call_command('check', list_tags=True)
     205        self.assertEqual('simpletag\n', sys.stdout.getvalue())
     206
    197207
    198208def custom_error_system_check(app_configs, **kwargs):
    199209    return [
Back to Top