Esempio n. 1
0
 def test_pep8(self):
     filepath = settings.INSTALL_DIR
     arglist = ['--exclude=', filepath]
     pep8.process_options(arglist)
     pep8.input_dir(filepath)
     output = pep8.get_statistics()
     self.assertEqual(len(output), 0)
Esempio n. 2
0
def main():
    """
    Parse options and run checks on Python source.
    """
    pep8.options = options()
    repo = dirname(dirname(abspath(__file__)))
    pep8.input_dir(repo)
Esempio n. 3
0
    def test_pep8(self):
        """ Verify that source code complies with PEP 8 formatting. """
        import pep8

        ignored_codes = [
            "E221",
            "E241",
        ]

        # Setup pep8 processing options.
        pep8_args = [
            "--show-source",
            "--repeat",
            "--ignore=" + ",".join(ignored_codes),
            "ignored",  # Ignored argument, but needed
            #  by pep8.process_options()
        ]
        pep8.process_options(pep8_args)

        # Call pep8 to process local files.
        directory = os.path.split(os.path.abspath(__file__))[0]
        directory = os.path.split(directory)[0]
        pep8.input_dir(directory)
        statistics = pep8.get_statistics()

        filtered_statistics = []
        for line in statistics:
            code = line[8:12]
            if code not in ignored_codes:
                filtered_statistics.append(line)

        self.assertFalse(filtered_statistics)
Esempio n. 4
0
    def pep8_report(self):
        """
        Outputs PEP8 report to screen and pep8.txt.
        """
        verbose = '--quiet' not in sys.argv
        if verbose:
            # Hook into stdout.
            old_stdout = sys.stdout
            sys.stdout = mystdout = StringIO()

            # Run Pep8 checks.
            pep8.options, pep8.args = pep8.process_options()
            pep8.args = self.packages
            pep8.options.repeat = True
            for package in self.packages:
                pep8.input_dir(package)

            # Restore stdout.
            sys.stdout = old_stdout

            # Save result to pep8.txt.
            result = mystdout.getvalue()
            output = open('pep8.txt', 'w')
            output.write(result)
            output.close()

            # Return Pep8 result
            if result:
                log.info("\nPEP8 Report:")
                log.info(result)
Esempio n. 5
0
    def test_fullhouse_test(self):
        filepath = os.path.join(settings.PROJECT_ROOT,
                                'fullhouse/test')

        arglist = [filepath]
        pep8.process_options(arglist)
        pep8.input_dir(filepath)
Esempio n. 6
0
def test_pep8():
    arglist = [
        "--statistics",
        "--filename=*.py",
        "--show-source",
        "--repeat",
        "--exclude=SVGdraw.py",
        "--ignore=E302,E701",
        #"--show-pep8",
        #"-qq",
        #"-v",
        BASE_DIR,
    ]

    options, args = pep8.process_options(arglist)
    runner = pep8.input_file

    for path in args:
        if isdir(path):
            pep8.input_dir(path, runner=runner)
        elif not pep8.excluded(path):
            options.counters["files"] += 1
            runner(path)

    pep8.print_statistics()
    errors = pep8.get_count("E")
    warnings = pep8.get_count("W")
    message = "pep8: %d errors / %d warnings" % (errors, warnings)
    print(message)
    assert errors + warnings == 0, message
Esempio n. 7
0
    def test_pep8():
        arglist = [
            '--statistics',
            '--filename=*.py',
            '--show-source',
            '--benchmark',
            '--repeat',
            '--show-pep8',
            #'--qq',
            #'-v',
            BASE_DIR,
        ]

        options, args = pep8.process_options(arglist)
        runner = pep8.input_file

        for path in args:
            if os.path.isdir(path):
                pep8.input_dir(path, runner=runner)
            elif not pep8.excluded(path):
                options.counters['files'] += 1
                runner(path)

        pep8.print_statistics()
        errors = pep8.get_count('E')
        warnings = pep8.get_count('W')
        message = 'pep8: %d errors / %d warnings' % (errors, warnings)
        print(message)
        assert errors + warnings == 0, message
Esempio n. 8
0
 def do_test(self):
     arglist = ['--exclude=', filepath]
     pep8.process_options(arglist)
     pep8.input_dir(filepath)
     output = pep8.get_statistics()
     print "PEP8 OUTPUT: " + str(output)
     self.assertEqual(len(output), 0)
Esempio n. 9
0
def test_pep8():
    arglist = [
        '--statistics',
        '--filename=*.py',
        '--show-source',
        '--repeat',
        #'--show-pep8',
        #'-qq',
        #'-v',
        BASE_DIR,
    ]

    options, args = pep8.process_options(arglist)
    runner = pep8.input_file

    for path in args:
        if os.path.isdir(path):
            pep8.input_dir(path, runner=runner)
        elif not pep8.excluded(path):
            options.counters['files'] += 1
            runner(path)

    pep8.print_statistics()
    errors = pep8.get_count('E')
    warnings = pep8.get_count('W')
    message = 'pep8: %d errors / %d warnings' % (errors, warnings)
    print message
    assert errors + warnings == 0, message
Esempio n. 10
0
 def handle(self, *test_labels, **opts):
     reportMessages = {}
     appMessages = []
     
     def writer(name):
         reportMessages[name] = []
         rex = re.compile(r"^/(?P<filename>.*):(?P<row>\d{1,}):(?P<col>\d{1,}): (?P<code>[A-Z]\d\d\d) (?P<msg>.*)$")
         def storeMessage( msg ):
             appMessages.append(msg)
             m = rex.match( msg )
             if m:
                 reportMessages[name].append( m.groups() )
         return storeMessage
     
     pep8_options =  ['','--filename','*.py']
     #[ pep8_options.extend(['--ignore', x]) for x in opts.get('ignore','').split(',') ]
     if opts.get('ignore', False):
         pep8_options.extend(['--ignore', opts['ignore']])
     pep8_options.extend( [ k for k in ['--show-source', '--show-pep8','--verbose' ] if k in sys.argv[1:] ])
     #pep8_options.extend( [ k for k in ['--show-source', '--show-pep8','--verbose' ] if k in opts ])
     pep8.process_options(pep8_options)
     
     for name, dir, app in self.get_apps( *test_labels ): 
         if 'django' == name:
             continue
         pep8.message = writer(name)
         pep8.input_dir( dir )
     
     if opts.get("output")=='json':
         self.generateJsonOutput(reportMessages)
     elif opts.get("output")=='xml':
         self.generateXmlOutput(reportMessages)
     else:
         self.generateConsoleOutput(appMessages)
Esempio n. 11
0
def main():
    """
    Parse options and run checks on Python source.
    """
    pep8.options = options()
    repo = dirname(dirname(abspath(__file__)))
    pep8.input_dir(repo)
Esempio n. 12
0
def test_pep8():
    arglist = [
        "--statistics",
        "--filename=*.py",
        "--show-source",
        "--repeat",
        "--exclude=SVGdraw.py",
        "--ignore=E302,E701",
        #"--show-pep8",
        #"-qq",
        #"-v",
        BASE_DIR,
    ]

    options, args = pep8.process_options(arglist)
    runner = pep8.input_file

    for path in args:
        if isdir(path):
            pep8.input_dir(path, runner=runner)
        elif not pep8.excluded(path):
            options.counters["files"] += 1
            runner(path)

    pep8.print_statistics()
    errors = pep8.get_count("E")
    warnings = pep8.get_count("W")
    message = "pep8: %d errors / %d warnings" % (errors, warnings)
    print message
    assert errors + warnings == 0, message
Esempio n. 13
0
    def test_pep8(self):
        """ Verify that source code complies with PEP 8 formatting. """
        import pep8

        ignored_codes = [
                         "E221",
                         "E241",
                        ]

        # Setup pep8 processing options.
        pep8_args = [
                     "--show-source",
                     "--repeat",
                     "--ignore=" + ",".join(ignored_codes),
                     "ignored",  # Ignored argument, but needed
                                 #  by pep8.process_options()
                    ]
        pep8.process_options(pep8_args)

        # Call pep8 to process local files.
        directory = os.path.split(os.path.abspath(__file__))[0]
        directory = os.path.split(directory)[0]
        pep8.input_dir(directory)
        statistics = pep8.get_statistics()

        filtered_statistics = []
        for line in statistics:
            code = line[8:12]
            if code not in ignored_codes:
                filtered_statistics.append(line)

        self.assertFalse(filtered_statistics)
Esempio n. 14
0
def test_pep8():
    arglist = [
        "--statistics",
        "--filename=*.py",
        "--show-source",
        "--benchmark",
        "--repeat",
        "--show-pep8",
        #'--qq',
        #'-v',
        BASE_DIR,
    ]

    options, args = pep8.process_options(arglist)
    runner = pep8.input_file

    for path in args:
        if os.path.isdir(path):
            pep8.input_dir(path, runner=runner)
        elif not pep8.excluded(path):
            options.counters["files"] += 1
            runner(path)

    pep8.print_statistics()
    errors = pep8.get_count("E")
    warnings = pep8.get_count("W")
    message = "pep8: %d errors / %d warnings" % (errors, warnings)
    print message
    assert errors + warnings == 0, message
Esempio n. 15
0
 def do_test(self):
     #print "PATH:", filepath
     arglist = ['--exclude=lib', filepath]
     pep8.process_options(arglist)
     pep8.input_dir(filepath)
     output = pep8.get_statistics()
     #print "PEP8 OUTPUT: " + str(output)
     self.assertEqual(len(output), 0)
Esempio n. 16
0
def run_pep8(options):
    import pep8
    from settings import testable_modules as modules

    # alas, pep8 can out go to stdout
    arglist = ["-r"] + modules
    pep8.process_options(arglist)
    for module in modules:
        pep8.input_dir(module, runner=pep8.input_file)
Esempio n. 17
0
    def test_fullhouse_dashboard_py(self):
        ''' Check style guide in dashboard root level. This excludes the
        south migration folder.
        '''
        filepath = os.path.join(settings.PROJECT_ROOT,
                                'fullhouse/dashboard/*.py')

        arglist = [filepath]
        pep8.process_options(arglist)
        pep8.input_dir(filepath)
Esempio n. 18
0
def run_pep8():
    """ Use the pep8 package to analyze the Dragonfly source code. """
    import pep8
    argv = [
        sys.argv[0],
        "--filename=*.py",
    ]
    from pkg_resources import resource_filename
    setup_path = os.path.abspath(resource_filename(__name__, "setup.py"))
    directory = os.path.dirname(setup_path)
    pep8.process_options(argv)
    pep8.input_dir(directory)
Esempio n. 19
0
def run_pep8():
    """ Use the pep8 package to analyze the Dragonfly source code. """
    import pep8
    argv = [
            sys.argv[0],
            "--filename=*.py",
           ]
    from pkg_resources import resource_filename
    setup_path = os.path.abspath(resource_filename(__name__, "setup.py"))
    directory = os.path.dirname(setup_path)
    pep8.process_options(argv)
    pep8.input_dir(directory)
Esempio n. 20
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()
Esempio n. 21
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()
Esempio n. 22
0
    def teardown_test_environment(self, **kwargs):
        locations = [os.path.dirname(get_app(app_name.split('.')[-1]).__file__) \
                     for app_name in get_apps_under_test(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
            filepath = relpath(instance.filename)
            message = re.sub(r'([WE]\d+)', r'[\1] PEP8:', text)
            sourceline = instance.line_offset + line_number
            self.output.write('%s:%s: %s\n' % (filepath, sourceline, message))
        pep8.Checker.report_error = report_error

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

        self.output.close()
Esempio n. 23
0
    def test_pep8(self):
        arglist = [
                '--statistics',
                '--filename=*.py',
                '--show-source',
                '--repeat',
                CURRENT_DIR,
                ]
        options, args = pep8.process_options(arglist)
        runner = pep8.input_file

        for path in args:
            if isdir(path):
                pep8.input_dir(path, runner=runner)
            elif not pep8.excluded(path):
                options.counters['files'] += 1
                runner(path)

        pep8.print_statistics()
        errors = pep8.get_count('E')
        warnings = pep8.get_count('W')
        message = 'pep8: {0} errors / {1} warnings'.format(errors, warnings)
        self.assertEqual(errors, warnings, message)
Esempio n. 24
0
    def teardown_test_environment(self, **kwargs):
        locations = [
            os.path.dirname(get_app(app_name.split(".")[-1]).__file__)
            for app_name in get_apps_under_test(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
            filepath = relpath(instance.filename)
            message = re.sub(r"([WE]\d+)", r"[\1] PEP8:", text)
            sourceline = instance.line_offset + line_number
            self.output.write("%s:%s: %s\n" % (filepath, sourceline, message))

        pep8.Checker.report_error = report_error

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

        self.output.close()
Esempio n. 25
0
 def beforeDirectory(self, path):
     def seen_runner(filename):
         if self.want_file(filename):
             pep8.input_file(filename)
     pep8.input_dir(path, runner=seen_runner)
Esempio n. 26
0
in the :ref:`coding-style-guide`. Be sure to read those documents if you
intend to contribute code to ObsPy.

Here are the results of the automatic PEP 8 syntax checker:

""")


# backup stdout
stdout = sys.stdout
sys.stdout = StringIO()

# clean up runner options
options, args = process_options()
options.repeat = True
input_dir(path, runner=input_file)
sys.stdout.seek(0)
data = sys.stdout.read()
statistic = get_statistics('')
count = get_count()

if count == 0:
    fh.write("The PEP 8 checker didn't find any issues.\n")
else:
    fh.write("\n")
    fh.write(".. rubric:: Statistic\n")
    fh.write("\n")
    fh.write("======= =====================================================\n")
    fh.write("Count   PEP 8 message string                                 \n")
    fh.write("======= =====================================================\n")
    for stat in statistic:
Esempio n. 27
0
Code) and :pep:`257` (Docstring Conventions) with the modifications documented
in the :ref:`coding-style-guide`. Be sure to read those documents if you
intend to contribute code to ObsPy.

Here are the results of the automatic PEP 8 syntax checker:

""")

# backup stdout
stdout = sys.stdout
sys.stdout = StringIO()

# clean up runner options
options, args = process_options()
options.repeat = True
input_dir(path, runner=input_file)
sys.stdout.seek(0)
data = sys.stdout.read()
statistic = get_statistics('')
count = get_count()

if count == 0:
    fh.write("The PEP 8 checker didn't find any issues.\n")
else:
    fh.write("\n")
    fh.write(".. rubric:: Statistic\n")
    fh.write("\n")
    fh.write("======= =====================================================\n")
    fh.write("Count   PEP 8 message string                                 \n")
    fh.write("======= =====================================================\n")
    for stat in statistic:
Esempio n. 28
0
    def test_pep8():
        if pep8.__version__ >= '1.3':
            arglist = [['statistics', True],
                       ['show-source', True],
                       ['repeat', True],
                       ['exclude', []],
                       ['paths', [BASE_DIR]]]

            pep8style = pep8.StyleGuide(arglist,
                                        parse_argv=False,
                                        config_file=True)
            options = pep8style.options
            if options.doctest:
                import doctest
                fail_d, done_d = doctest.testmod(report=False,
                                                 verbose=options.verbose)
                fail_s, done_s = selftest(options)
                count_failed = fail_s + fail_d
                if not options.quiet:
                    count_passed = done_d + done_s - count_failed
                    print("%d passed and %d failed." % (count_passed,
                                                        count_failed))
                    print("Test failed." if count_failed else "Test passed.")
                if count_failed:
                    sys.exit(1)
            if options.testsuite:
                init_tests(pep8style)
            report = pep8style.check_files()
            if options.statistics:
                report.print_statistics()
            if options.benchmark:
                report.print_benchmark()
            if options.testsuite and not options.quiet:
                report.print_results()
            if report.total_errors:
                if options.count:
                    sys.stderr.write(str(report.total_errors) + '\n')
                sys.exit(1)
            # reporting errors (additional summary)
            errors = report.get_count('E')
            warnings = report.get_count('W')
            message = 'pep8: %d errors / %d warnings' % (errors, warnings)
            print(message)
            assert report.total_errors == 0, message
        else:
            # under pep8 1.3
            arglist = [
                '--statistics',
                '--filename=*.py',
                '--show-source',
                '--benchmark',
                '--repeat',
                '--show-pep8',
                #'--qq',
                #'-v',
                BASE_DIR, ]

            options, args = pep8.process_options(arglist)
            runner = pep8.input_file

            for path in args:
                if os.path.isdir(path):
                    pep8.input_dir(path, runner=runner)
                elif not pep8.excluded(path):
                    options.counters['files'] += 1
                    runner(path)

            pep8.print_statistics()
            errors = pep8.get_count('E')
            warnings = pep8.get_count('W')
            message = 'pep8: %d errors / %d warnings' % (errors, warnings)
            print(message)
            assert errors + warnings == 0, message
Esempio n. 29
0
 def beforeDirectory(self, path):
     def seen_runner(filename):
         if filename not in self.seen:
             pep8.input_file(filename)
             self.seen.append(filename)
     pep8.input_dir(path, runner=seen_runner)
Esempio n. 30
0
 def test_all_code(self):
     for package in self.packages:
         pep8.input_dir(os.path.dirname(package.__file__))
     self.assertEqual([], self.errors)