Example #1
0
    def assert_report(self, test_file, expected_report):
        current_folder, _ = os.path.split(os.path.abspath(test_file))
        filename = os.path.join(current_folder, 'checked_file.py')
        abs_path = os.path.abspath('.')

        report = validate_file(filename, get_deprecated_rules(), project_root=abs_path)

        self.assertDictEqual(report, expected_report)
Example #2
0
    def handle(self, *args, **options):
        """
        This management command applies all deprecated rules defined in rules module.
        Every non-respected rule will have a report displayed with some explanations to fix it:
        - The impacted file,
        - The rule number, with a human description
        - The line number, and the line copy.

        $ ./manage.py check_deprecated_rules

        ./core/models.py
        1601: models.BooleanField has to be initialised with default parameter,
              as implicit default has changed between Django 1.4 (False) and 1.6 (None).
        L6:     boolean_field = models.BooleanField()

        """
        print('-' * 50)
        print('Checking these deprecated rules:')

        deprecated_rules = get_deprecated_rules()

        for rule in deprecated_rules:
            print('{number}: {message}'.format(number=rule['number'],
                                               message=rule['message']))

        report = {}

        def progress_fn(filename, rule, line, number):
            print('-' * 50)
            print(filename)
            print("{number}: {message}".format(number=rule['number'],
                                               message=rule['message']))
            print("L{line_number}: {line}".format(line_number=number,
                                                  line=line))

        for dirName, subdirList, fileList in os.walk('.'):
            if not is_excluded_dir(dirName):
                for fname in [
                        f for f in fileList
                        if not is_excluded_file(f, dirName)
                ]:
                    file_report = validate_file(os.path.join(dirName, fname),
                                                deprecated_rules, progress_fn)
                    report.update(file_report)

        if len(report) > 0:
            print(
                '\nHave a look at http://django-seven.readthedocs.org/en/develop/deprecated-rules for more informations about these errors.\n'
            )
        else:
            print('\nDeprecated rules respected. Good job \o/\n')
    def handle(self, *args, **options):
        """
        This management command applies all deprecated rules defined in rules module.
        Every non-respected rule will have a report displayed with some explanations to fix it:
        - The impacted file,
        - The rule number, with a human description
        - The line number, and the line copy.

        $ ./manage.py check_deprecated_rules

        ./core/models.py
        1601: models.BooleanField has to be initialised with default parameter,
              as implicit default has changed between Django 1.4 (False) and 1.6 (None).
        L6:     boolean_field = models.BooleanField()

        """
        print('-' * 50)
        print('Checking these deprecated rules:')

        deprecated_rules = get_deprecated_rules()

        for rule in deprecated_rules:
            print('{number}: {message}'.format(number=rule['number'], message=rule['message']))

        report = {}

        def progress_fn(filename, rule, line, number):
            print('-' * 50)
            print(filename)
            print("{number}: {message}".format(number=rule['number'], message=rule['message']))
            print("L{line_number}: {line}".format(line_number=number, line=line))

        for dirName, subdirList, fileList in os.walk('.'):
            if not is_excluded_dir(dirName):
                for fname in [f for f in fileList if not is_excluded_file(f, dirName)]:
                    file_report = validate_file(os.path.join(dirName, fname), deprecated_rules, progress_fn)
                    report.update(file_report)

        if len(report) > 0:
            print('\nHave a look at http://django-seven.readthedocs.org/en/develop/deprecated-rules for more informations about these errors.\n')
        else:
            print('\nDeprecated rules respected. Good job \o/\n')