Ejemplo n.º 1
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)

        class JenkinsReport(pep8.BaseReport):
            def error(instance, line_number, offset, text, check):
                code = super(JenkinsReport,
                             instance).error(line_number, offset, text, check)

                if not code:
                    return
                sourceline = instance.line_offset + line_number
                self.output.write(
                    '%s:%s:%s: %s\n' %
                    (instance.filename, sourceline, offset + 1, text))

        pep8style = get_style_guide(parse_argv=False,
                                    config_file=self.pep8_rcfile,
                                    reporter=JenkinsReport,
                                    max_complexity=self.max_complexity,
                                    **self.pep8_options)

        for location in locations:
            pep8style.input_dir(relpath(location))

        self.output.close()
Ejemplo n.º 2
0
    def static_files_iterator(self):
        locations = get_apps_locations(self.test_labels, self.test_all)

        def in_tested_locations(path):
            for location in locations:
                if path.startswith(location):
                    return True
            return False

        if hasattr(settings, 'JSLINT_CHECKED_FILES'):
            for path in settings.JSLINT_CHECKED_FILES:
                yield path

        if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
            # use django.contrib.staticfiles
            from django.contrib.staticfiles import finders

            for finder in finders.get_finders():
                for path, _ in finder.list(self.exclude):
                    if path.endswith('.js') and in_tested_locations(path):
                        yield path
        else:
            # scan apps directories for static folders
            for location in locations:
                for dirpath, dirnames, filenames in os.walk(
                        os.path.join(location, 'static')):
                    for filename in filenames:
                        if filename.endswith('.js') and in_tested_locations(
                                os.path.join(dirpath, filename)):
                            yield os.path.join(dirpath, filename)
Ejemplo n.º 3
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)

        # run pyflakes tool with captured output
        old_stdout, pyflakes_output = sys.stdout, StringIO()
        sys.stdout = pyflakes_output
        try:
            for location in locations:
                if os.path.isdir(location):
                    for dirpath, dirnames, filenames in os.walk(relpath(location)):
                        for filename in filenames:
                            if filename.endswith('.py'):
                                pyflakes.checkPath(os.path.join(dirpath, filename))
                else:
                    pyflakes.checkPath(relpath(location))
        finally:
            sys.stdout = old_stdout

        # save report
        pyflakes_output.reset()
        while True:
            line = pyflakes_output.readline()
            if not line:
                break
            message = re.sub(r': ', r': [E] PYFLAKES:', line)
            self.output.write(message)

        self.output.close()
Ejemplo n.º 4
0
    def static_files_iterator(self):
        locations = get_apps_locations(self.test_labels, self.test_all)

        def in_tested_locations(path):
            for location in locations:
                if path.startswith(location):
                    return True
            return False
        
        if hasattr(settings, 'JSLINT_CHECKED_FILES'):
            for path in settings.JSLINT_CHECKED_FILES:
                yield path
                    
        if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
            # use django.contrib.staticfiles
            from django.contrib.staticfiles import finders

            for finder in finders.get_finders():
                for path, storage in finder.list(self.exclude):
                    path = os.path.join(storage.location, path)                
                    if path.endswith('.js') and in_tested_locations(path):
                        yield path
        else:
            # scan apps directories for static folders
            for location in locations:
                for dirpath, dirnames, filenames in os.walk(os.path.join(location, 'static')):
                    for filename in filenames:
                        if filename.endswith('.js') and in_tested_locations(os.path.join(dirpath, filename)):
                            yield os.path.join(dirpath, filename)
Ejemplo n.º 5
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)

        class JenkinsReport(pep8.BaseReport):
            def error(instance, line_number, offset, text, check):
                code = super(JenkinsReport, instance).error(
                    line_number, offset, text, check
                )

                if not code:
                    return
                sourceline = instance.line_offset + line_number
                self.output.write('%s:%s:%s: %s\n' % (
                    instance.filename, sourceline, offset + 1, text)
                )

        pep8style = pep8.StyleGuide(
            parse_argv=False, config_file='.pep8',
            reporter=JenkinsReport
        )

        for location in locations:
            pep8style.input_dir(relpath(location))

        self.output.close()
Ejemplo n.º 6
0
 def __init__(self, test_labels, options):
     super(Task, self).__init__(test_labels, options)
     self.locations = get_apps_locations(self.test_labels, options['test_all'])   
     if options.get('sloccount_file_output', True):
         output_dir = options['output_dir']
         if not os.path.exists(output_dir):
             os.makedirs(output_dir)
         self.output = open(os.path.join(output_dir, 'sloccount.report'), 'w')
     else:
         self.output = sys.stdout 
     self.root_dir = os.path.normpath(os.path.dirname(__file__))
Ejemplo n.º 7
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)  

        report_output = check_output(
            ['sloccount', "--duplicates", "--wide", "--details"] + locations)

        if self.with_migrations:
            self.output.write(report_output)
        else:
            for line in report_output.splitlines():
                if '/migrations/' in line:
                    continue
                self.output.write(line)
                self.output.write('\n')
Ejemplo n.º 8
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)

        report_output = check_output(
            ['sloccount', "--duplicates", "--wide", "--details"] + locations)

        if self.with_migrations:
            self.output.write(report_output)
        else:
            for line in report_output.splitlines():
                if '/migrations/' in line:
                    continue
                self.output.write(line)
                self.output.write('\n')
Ejemplo n.º 9
0
    def __init__(self, test_labels, options):
        super(Task, self).__init__(test_labels, options)

        self.locations = get_apps_locations(self.test_labels,
                                            options['test_all'])
        self.with_migrations = options['sloccount_with_migrations']

        if options.get('sloccount_file_output', True):
            output_dir = options['output_dir']
            if not os.path.exists(output_dir):
                os.makedirs(output_dir)
            self.output = open(os.path.join(output_dir, 'sloccount.report'),
                               'w')
        else:
            self.output = sys.stdout
Ejemplo n.º 10
0
    def static_files_iterator(self):
        locations = get_apps_locations(self.test_labels, self.test_all)

        def in_tested_locations(path):
            if not self.jshint_with_minjs and path.endswith('.min.js'):
                return False

            for location in list(locations):
                if path.startswith(location):
                    return True
            if self.with_static_dirs:
                for location in list(settings.STATICFILES_DIRS):
                    if path.startswith(location):
                        return True
            return False

        def is_excluded(path):
            for pattern in self.exclude:
                if fnmatch.fnmatchcase(path, pattern):
                    return True
            return False

        if hasattr(settings, 'JSHINT_CHECKED_FILES'):
            for path in settings.JSHINT_CHECKED_FILES:
                yield path

        if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
            # use django.contrib.staticfiles
            from django.contrib.staticfiles import finders

            for finder in finders.get_finders():
                for path, storage in finder.list(None):
                    path = os.path.join(storage.location, path)
                    if path.endswith('.js') and \
                            in_tested_locations(path) and not \
                                is_excluded(path):
                        yield path
        else:
            # scan apps directories for static folders
            for location in locations:
                for dirpath, dirnames, filenames in \
                        os.walk(os.path.join(location, self.static_dirname)):
                    for filename in filenames:
                        path = os.path.join(dirpath, filename)
                        if filename.endswith('.js') and \
                                in_tested_locations(path) and not \
                                    is_excluded(path):
                            yield path
Ejemplo n.º 11
0
    def static_files_iterator(self):
        locations = get_apps_locations(self.test_labels, self.test_all)

        def in_tested_locations(path):
            if not self.jshint_with_minjs and path.endswith('.min.js'):
                return False

            for location in list(locations):
                if path.startswith(location):
                    return True
            if self.with_static_dirs:
                for location in list(settings.STATICFILES_DIRS):
                    if path.startswith(location):
                        return True
            return False

        def is_excluded(path):
            for pattern in self.exclude:
                if fnmatch.fnmatchcase(path, pattern):
                    return True
            return False

        if hasattr(settings, 'JSHINT_CHECKED_FILES'):
            for path in settings.JSHINT_CHECKED_FILES:
                yield path

        if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
            # use django.contrib.staticfiles
            from django.contrib.staticfiles import finders

            for finder in finders.get_finders():
                for path, storage in finder.list(None):
                    path = os.path.join(storage.location, path)
                    if path.endswith('.js') and \
                            in_tested_locations(path) and not \
                                is_excluded(path):
                        yield path
        else:
            # scan apps directories for static folders
            for location in locations:
                for dirpath, dirnames, filenames in \
                        os.walk(os.path.join(location, self.static_dirname)):
                    for filename in filenames:
                        path = os.path.join(dirpath, filename)
                        if filename.endswith('.js') and \
                                in_tested_locations(path) and not \
                                    is_excluded(path):
                            yield path
Ejemplo n.º 12
0
    def test_files_iterator(self):
        locations = get_apps_locations(self.test_labels, self.test_all)

        def in_tested_locations(path):
            for location in list(locations):
                if path.startswith(location):
                    return True
            return False

         # scan apps directories for static folders
        for location in locations:
            for dirpath, dirnames, filenames in os.walk(os.path.join(location, 'testem')):
                for filename in filenames:
                    path = os.path.join(dirpath, filename)
                    if filename.endswith('.yml') and in_tested_locations(path):
                        yield path
Ejemplo n.º 13
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)
        pep8.process_options(self.pep8_options + locations)

        # run pep8 tool with captured output
        def report_error(instance, line_number, offset, text, check):
            code = text[:4]
            if pep8.ignore_code(code):
                return
            sourceline = instance.line_offset + line_number
            self.output.write('%s:%s:%s: %s\n' % (instance.filename, sourceline, offset+1, text))
        pep8.Checker.report_error = report_error

        for location in locations:
            pep8.input_dir(relpath(location), runner=pep8.input_file)

        self.output.close()
Ejemplo n.º 14
0
    def teardown_test_environment(self, **kwargs):
        locations = get_apps_locations(self.test_labels, self.test_all)
        pep8.process_options(self.pep8_options + locations)

        # run pep8 tool with captured output
        def report_error(instance, line_number, offset, text, check):
            code = text[:4]
            if pep8.ignore_code(code):
                return
            sourceline = instance.line_offset + line_number
            self.output.write('%s:%s:%s: %s\n' % (instance.filename, sourceline, offset+1, text))
        pep8.Checker.report_error = report_error

        for location in locations:
            pep8.input_dir(relpath(location), runner=pep8.input_file)

        self.output.close()
Ejemplo n.º 15
0
    def teardown_test_environment(self, **kwargs):
        # Local imports to avoid intallation errors.
        import flake8.run

        # Use pep8 from flake8 to avoid weird errors resulting from
        # version mismatch.
        from flake8 import pep8

        locations = get_apps_locations(
            self.test_labels,
            self.test_all
        )

        paths = flake8.run._get_python_files(locations)
        flake8.run.pep8style = pep8.StyleGuide(
            parse_argv=False,
            config_file=False
        )
        old_stdout, flake8_output = sys.stdout, StringIO()
        sys.stdout = flake8_output
        warnings = 0
        for path in paths:
            # We could pass ignore paths and max complexity there,
            # but I need to figure out first how to do it
            warnings += flake8.run.check_file(path)

        sys.stdout = old_stdout

        flake8_output.seek(0)

        while True:
            line = flake8_output.readline()
            if not line:
                break

            # Make sure the path is relative in the report
            bits = line.split(':')
            bits[0] = relpath(bits[0])
            self.output.write(':'.join(bits))

        self.output.close()
Ejemplo n.º 16
0
    def teardown_test_environment(self, **kwargs):
        # Local import to avoid intallation errors.
        import flake8.run

        locations = get_apps_locations(
            self.test_labels,
            self.test_all
        )

        paths = flake8.run._get_python_files(locations)
        flake8.run.pep8style = pep8.StyleGuide(
            parse_argv=False,
            config_file=False
        )
        old_stdout, flake8_output = sys.stdout, BytesIO()
        sys.stdout = flake8_output
        warnings = 0
        for path in paths:
            # We could pass ignore paths
            # but I need to figure out first how to do it
            warnings += flake8.run.check_file(
                path,
                complexity=self.max_complexity
            )

        sys.stdout = old_stdout

        flake8_output.seek(0)

        while True:
            line = flake8_output.readline()
            if not line:
                break

            # Make sure the path is relative in the report
            bits = line.split(':')
            bits[0] = relpath(bits[0])
            self.output.write(':'.join(bits))

        self.output.close()