Exemple #1
0
    def test_parseable_output_deprecated(self):
        with warnings.catch_warnings(record=True) as cm:
            warnings.simplefilter("always")
            ParseableTextReporter()

        self.assertEqual(len(cm), 1)
        self.assertIsInstance(cm[0].message, DeprecationWarning)
    def _run_pylint(self, pylint_args):
        '''runs pylint with supplied args, returns '''

        pylint_output = _WritableOutput()
        pylint_reporter = ParseableTextReporter(pylint_output)
        lint.Run(pylint_args, reporter=pylint_reporter, exit=False)
        return pylint_output.content
Exemple #3
0
def test_parseable_output_deprecated():
    with warnings.catch_warnings(record=True) as cm:
        warnings.simplefilter("always")
        ParseableTextReporter()

    assert len(cm) == 1
    assert isinstance(cm[0].message, DeprecationWarning)
Exemple #4
0
def run_pylint(src_file):
    '''
    Dispatch to pylint, once per module
    
    We need to fiddle with stderr because pylint insists on repeatedly telling
    us about its lack of a configuration file.  We don't want to suppress all 
    of stderr, so we instead selectively target offending messages.
    '''
    buf = StringIO.StringIO()
    try:
        with quality.liason.PatchContext(
                sys, 'stderr',
                quality.liason.FilteredFileProxy(
                    sys.stderr,
                    'No config file found, using default configuration')):
            pylint.lint.Run(['-r', 'n', src_file],
                            reporter=ParseableTextReporter(output=buf),
                            exit=False)
    except Exception:
        warnings.warn(
            'pylint encountered a fatal error attempting to process the file: %s\n%s'
            % (src_file, traceback.format_exc()))

    buf.seek(0)
    return buf
Exemple #5
0
    def run(self, argv):
        output = _FilteredStringIO(self.FALSE_POSITIVES)
        with OutputCapture():
            from pylint import lint
            from pylint.reporters.text import ParseableTextReporter

            lint.Run(['--rcfile', self._pylintrc] + argv, reporter=ParseableTextReporter(output=output), exit=False)
        return output
    def teardown_test_environment(self, **kwargs):        
        args = ["--rcfile=%s" % self.config_path] 
        if self.errors_only:
            args += ['--errors-only']
        args += get_apps_under_test(self.test_labels, self.test_all)

        lint.Run(args, reporter=ParseableTextReporter(output=self.output), exit=False)

        return True
Exemple #7
0
def make_pylint_output():
    from os.path import expanduser
    from pylint.lint import Run
    from pylint.reporters.text import ParseableTextReporter
    if not os.path.exists('reports'):
        os.mkdir('reports')
    with open('reports/pylint.report', 'wb') as handle:
        args = ['django_tables2', 'example', 'tests']
        Run(args, reporter=ParseableTextReporter(output=handle), exit=False)
    def teardown_test_environment(self, **kwargs):
        if PROJECT_APPS:
            args = ["--rcfile=%s" % self.config_path]
            if self.errors_only:
                args += ['--errors-only']
            args += PROJECT_APPS

            lint.Run(args,
                     reporter=ParseableTextReporter(output=self.output),
                     exit=False)
Exemple #9
0
def run_pylint(filelist):
    "Executes pylint on python files programmatically."
    sys.path = sys.path + pythonpath
    args = ["--rcfile=/opt/dev-tools/pylint/pylintrc"] + filelist
    pylint_output = WriteableObject()
    original_exit = sys.exit
    sys.exit = no_exit
    lint.Run(args, reporter=ParseableTextReporter(pylint_output))
    sys.exit = original_exit
    return [line.strip() for line in pylint_output.content if line.strip()]
Exemple #10
0
    def handle(self, *args, **options):
        output_file = options.get('output_file')
        if output_file:
            output = open(output_file, 'w')
        else:
            output = sys.stdout

        config = "--rcfile=" + Command.default_config_path()
        lint.Run([config] + list(args),
                 reporter=ParseableTextReporter(output=output),
                 exit=False)
Exemple #11
0
def run_lint(options):
    from pylint import lint
    from pylint.reporters.text import ParseableTextReporter
    from settings import testable_modules as modules

    if options.outfile:
        output = open(options.outfile, 'w')
    else:
        output = sys.stdout

    config = "--rcfile=" + path.join(PROJECT_ROOT, 'pylint.rc')
    lint.Run([config] + modules,
             reporter=ParseableTextReporter(output=output), exit=False)
Exemple #12
0
 def run_pylint(filename):
     """Run pylint on the given file.
     """
     args = ["-r","n"]
     pylint_output = io.StringIO()
     lint.Run([filename]+args, 
              reporter=ParseableTextReporter(pylint_output), exit=False)
     pylint_output.seek(0)
     result = pylint_output.read()
     kill_regexps = make_kill_regexps()
     for re_name, my_re in kill_regexps.items():
         logging.debug('Cleaning output with re %s', re_name)
         result = re.sub(my_re, '', result, flags=re.M)
     return result
 def test_parseable_output_regression(self):
     output = six.StringIO()
     linter = PyLinter(reporter=ParseableTextReporter())
     checkers.initialize(linter)
     linter.config.persistent = 0
     linter.reporter.set_output(output)
     linter.set_option('output-format', 'parseable')
     linter.open()
     linter.set_current_module('0123')
     linter.add_message('line-too-long', line=1, args=(1, 2))
     self.assertMultiLineEqual(
         output.getvalue(), '************* Module 0123\n'
         '0123:1: [C0301(line-too-long), ] '
         'Line too long (1/2)\n')
Exemple #14
0
def test_parseable_output_regression():
    output = StringIO()
    with warnings.catch_warnings(record=True):
        linter = PyLinter(reporter=ParseableTextReporter())

    checkers.initialize(linter)
    linter.config.persistent = 0
    linter.reporter.set_output(output)
    linter.set_option("output-format", "parseable")
    linter.open()
    linter.set_current_module("0123")
    linter.add_message("line-too-long", line=1, args=(1, 2))
    assert (output.getvalue() == "************* Module 0123\n"
            "0123:1: [C0301(line-too-long), ] "
            "Line too long (1/2)\n")
Exemple #15
0
def run_tests(parser_args):
    import unittest
    import logging
    import settings
    settings.enable_test_mode()

    def unittest_main(test_runner=None):
        try:
            argv = [sys.argv[0]]
            if parser_args.extra_parameters:
                argv += parser_args.extra_parameters
            else:
                # workaround to avoid full unit test discovery
                # and limit test suite to settings.test_cases
                # argv.append('__main__.load_all_tests')
                argv.append('__main__.load_all_tests')

            unittest.main(module=None, argv=argv, testRunner=test_runner)
        except SystemExit as e:
            if e.code == 0:
                logging.info('PASS')
            else:
                logging.error('FAIL')
                raise

    if parser_args.pylint:
        from pylint import lint
        from pylint.reporters.text import ParseableTextReporter

        output = sys.stdout
        if parser_args.outfile:
            output = open(parser_args.outfile, 'w')

        config = "--rcfile=" + path.join(PROJECT_ROOT, 'pylint.rc')
        lint.Run([config] + settings.testable_modules,
                 reporter=ParseableTextReporter(output=output),
                 exit=False)

    elif parser_args.xunit:
        import xmlrunner

        output = 'reports'
        if parser_args.outfile:
            output = parser_args.outfile
        unittest_main(xmlrunner.XMLTestRunner(output=output))

    else:
        unittest_main(None)
def test_parseable_output_regression():
    output = six.StringIO()
    with warnings.catch_warnings(record=True):
        linter = PyLinter(reporter=ParseableTextReporter())

    checkers.initialize(linter)
    linter.config.persistent = 0
    linter.reporter.set_output(output)
    linter.set_option('output-format', 'parseable')
    linter.open()
    linter.set_current_module('0123')
    linter.add_message('line-too-long', line=1, args=(1, 2))
    assert output.getvalue() == \
        '************* Module 0123\n' \
        '0123:1: [C0301(line-too-long), ] ' \
        'Line too long (1/2)\n'
Exemple #17
0
 def pylint(self, pylint_file, pylint_rc_file=None, ignore_openerp=True):
     remove_file(pylint_file)
     with open(pylint_file, 'w') as pylintfile:
         args = [fname for fname in self.python_files if not ignore_openerp or '__openerp__.py' not in fname]
         if self.conf.get('max-line-length'):
             args.append('--max-line-length=%s' % self.conf.get('max-line-length'))
         if self.conf.get('min-similarity-lines'):
             args.append('--min-similarity-lines=%s' % self.conf.get('min-similarity-lines'))
         if self.conf.get('sys_path_for_pylint'):
             sys.path.extend(self.conf.get('sys_path_for_pylint').split(','))
         for key, value in conf.items():
             if key == 'pylint_file':
                 continue
             if key.startswith('pylint_'):
                 args.append('--%s=%s' % (key[7:], value))
         if pylint_rc_file:
             args.append('--rcfile=%s' % pylint_rc_file)
         lint.Run(args, ParseableTextReporter(pylintfile), exit=False)
Exemple #18
0
def run_pylint(fich):
    "run pylint on the given file and return synthetic results (note, error, reorder, warning)"
    from pylint import lint
    from pylint.reporters.text import TextReporter, ParseableTextReporter
#    pyl = lint.Run(args)
    pylint_output = WritableObject()
    lint.Run([fich]+ARGS, reporter=ParseableTextReporter(pylint_output), do_exit=False)
    ignored_error = ('Exter', 'E1103')  # 5 first char of ignored errors
    ignored_warn = ('none',)            # 5 first char of ignored warnings
    errors = 0
    warn = 0
    reorder = 0
    note = 0.0
    for l in pylint_output:
        if ' [E0001' in l:
            errors = 10000  # indicates crash
            break
        elif ' [E' in l:
            if l[0:5] not in ignored_error:
                errors += 1
                with open(ERROR_file,'a') as ERR:
                    ERR.write("%s: %s\n"%(fich,l))
        elif ' [W' in l:
            if l[0:5] not in ignored_warn:
                warn += 1
        elif ' [R' in l:
            reorder += 1
        elif l.startswith('Your code has been rated'):
            m = re.match(r'Your code has been rated at (-?\d+.\d.)/10', l)
            note = float(m.group(1))
        # elif l.find('External dependencies') !=-1:
        #     print "##############"
        #     dep = find_depedencies(pylint_output)
        #     print "##############"
    if errors == 10000:    # means crash
        note = -100
#    print(fich, note, errors, warn, reorder)
    return (note, errors, warn, reorder )
Exemple #19
0
#!/usr/bin/env python

from cStringIO import StringIO
from pylint.lint import PyLinter
from pylint.reporters.text import ParseableTextReporter

l = PyLinter()


reporter = ParseableTextReporter()
result = StringIO()
reporter.set_output(result)
l.check(__file__)
Exemple #20
0
    def test_parseable_output_deprecated(self):
        with testutils.catch_warnings() as cm:
            ParseableTextReporter()

        self.assertEqual(len(cm), 1)
        self.assertIsInstance(cm[0].message, DeprecationWarning)
Exemple #21
0
#!/usr/bin/env python3
import sys

from pylint import lint
from pylint.reporters.text import ParseableTextReporter

if len(sys.argv) > 1:
    output_stream = open(sys.argv[1], 'w')
else:
    output_stream = sys.stdout

reporter = ParseableTextReporter(output_stream)

run = lint.Run(['philips_hue_hooks'], reporter=reporter, do_exit=False)

if run.linter.stats['error'] > 0 or run.linter.stats['fatal'] > 0:
    print('Errors detected.')
    sys.exit(1)

score = run.linter.stats['global_note']

if score < 0:
    print(f'Negative score ({score}), failing.')
    sys.exit(1)
Exemple #22
0
    os.chdir(os.path.dirname(os.path.abspath(__file__)))

    # Options to control pylint process
    pylint_options = ["-r", "n", "--rcfile=.pylintrc"]

    # The files and directories to lint
    files_and_dirs = list(
        map(lambda file_or_dir: "../../{}".format(file_or_dir),
            ["euphonic", "scripts", "release.py", "setup.py"]))

    # Object to write pylint output to
    pylint_output = LintOutput()

    # Run the linting
    run = lint.Run(files_and_dirs + pylint_options,
                   reporter=ParseableTextReporter(pylint_output),
                   do_exit=False)

    # Write the lint output to file
    os.makedirs("reports", exist_ok=True)
    pylint_output.write_to_file("reports/pylint_output.txt")

    # Move back to original directory
    os.chdir(original_cwd)

    # If we have a score lower than the threshold fail the linting
    threshold = 2

    score = round(run.linter.stats['global_note'], 2)

    if score < threshold: