commit python-pep8 for openSUSE:Factory
![](https://seccdn.libravatar.org/avatar/e2145bc5cf53dda95c308a3c75e8fef3.jpg?s=120&d=mm&r=g)
Hello community, here is the log from the commit of package python-pep8 for openSUSE:Factory checked in at 2013-06-05 13:35:39 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pep8 (Old) and /work/SRC/openSUSE:Factory/.python-pep8.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-pep8" Changes: -------- --- /work/SRC/openSUSE:Factory/python-pep8/python-pep8.changes 2013-02-25 21:41:59.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.python-pep8.new/python-pep8.changes 2013-06-05 13:35:41.000000000 +0200 @@ -1,0 +2,22 @@ +Tue May 28 07:32:40 UTC 2013 - speilicke@suse.com + +- Drop old tarball +- Document no-tox-test.diff + +------------------------------------------------------------------- +Sat May 18 19:52:53 UTC 2013 - dmueller@suse.com + +- udpate to 1.4.5: +* When no path is specified, do not try to read from stdin. +* Do not require ``setuptools`` in setup.py. It works around an issue + with ``pip`` and Python 3. (Issue #172) +* Add ``__pycache__`` to the ignore list. +* Change misleading message for E251. (Issue #171) +* Do not report false E302 when the source file has a coding cookie or a + comment on the first line. (Issue #174) +* Reorganize the tests and add tests for the API and for the command line + usage and options. (Issues #161 and #162) +* Ignore all checks which are not explicitly selected when ``select`` is + passed to the ``StyleGuide`` constructor + +------------------------------------------------------------------- --- /work/SRC/openSUSE:Factory/python-pep8/python3-pep8.changes 2013-02-25 21:41:59.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.python-pep8.new/python3-pep8.changes 2013-06-05 13:35:41.000000000 +0200 @@ -1,0 +2,16 @@ +Sat May 18 19:52:53 UTC 2013 - dmueller@suse.com + +- udpate to 1.4.5: +* When no path is specified, do not try to read from stdin. +* Do not require ``setuptools`` in setup.py. It works around an issue + with ``pip`` and Python 3. (Issue #172) +* Add ``__pycache__`` to the ignore list. +* Change misleading message for E251. (Issue #171) +* Do not report false E302 when the source file has a coding cookie or a + comment on the first line. (Issue #174) +* Reorganize the tests and add tests for the API and for the command line + usage and options. (Issues #161 and #162) +* Ignore all checks which are not explicitly selected when ``select`` is + passed to the ``StyleGuide`` constructor + +------------------------------------------------------------------- Old: ---- pep8-1.4.4.tar.gz New: ---- no-tox-test.diff pep8-1.4.5.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pep8.spec ++++++ --- /var/tmp/diff_new_pack.fDdAoS/_old 2013-06-05 13:35:42.000000000 +0200 +++ /var/tmp/diff_new_pack.fDdAoS/_new 2013-06-05 13:35:42.000000000 +0200 @@ -17,13 +17,16 @@ Name: python-pep8 -Version: 1.4.4 +Version: 1.4.5 Release: 0 Url: http://github.com/jcrocholl/pep8 Summary: Python style guide checker License: MIT Group: Development/Languages/Python Source: http://pypi.python.org/packages/source/p/pep8/pep8-%{version}.tar.gz +# PATCH-FIX-OPENSUSE: speilicke@suse.com -- Upstream forgot tox.init in sdist +# release, seems to be present in never codebase +Patch0: no-tox-test.diff BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: fdupes BuildRequires: python-devel @@ -41,6 +44,7 @@ %prep %setup -q -n pep8-%{version} +%patch0 %build python setup.py build ++++++ python3-pep8.spec ++++++ --- /var/tmp/diff_new_pack.fDdAoS/_old 2013-06-05 13:35:42.000000000 +0200 +++ /var/tmp/diff_new_pack.fDdAoS/_new 2013-06-05 13:35:42.000000000 +0200 @@ -17,7 +17,7 @@ Name: python3-pep8 -Version: 1.4.4 +Version: 1.4.5 Release: 0 Url: http://github.com/jcrocholl/pep8 Summary: Python style guide checker ++++++ no-tox-test.diff ++++++ --- testsuite/test_shell.py +++ testsuite/test_shell.py @@ -79,9 +79,6 @@ self.assertEqual(x, str(num)) self.assertEqual(y, str(col)) self.assertTrue(msg.startswith(' E11')) - # Config file read from the pep8's tox.ini - (config_filename,) = self._config_filenames - self.assertTrue(config_filename.endswith('tox.ini')) def test_check_stdin(self): pep8.PROJECT_CONFIG = () ++++++ pep8-1.4.4.tar.gz -> pep8-1.4.5.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/CHANGES.txt new/pep8-1.4.5/CHANGES.txt --- old/pep8-1.4.4/CHANGES.txt 2013-02-24 16:26:38.000000000 +0100 +++ new/pep8-1.4.5/CHANGES.txt 2013-03-06 19:51:09.000000000 +0100 @@ -2,6 +2,31 @@ ========= +1.4.5 (2013-03-06) +------------------ + +* When no path is specified, do not try to read from stdin. The feature + was added in 1.4.3, but it is not supported on Windows. Use ``-`` + filename argument to read from stdin. This usage is supported + since 1.3.4. (Issue #170) + +* Do not require ``setuptools`` in setup.py. It works around an issue + with ``pip`` and Python 3. (Issue #172) + +* Add ``__pycache__`` to the ignore list. + +* Change misleading message for E251. (Issue #171) + +* Do not report false E302 when the source file has a coding cookie or a + comment on the first line. (Issue #174) + +* Reorganize the tests and add tests for the API and for the command line + usage and options. (Issues #161 and #162) + +* Ignore all checks which are not explicitly selected when ``select`` is + passed to the ``StyleGuide`` constructor. + + 1.4.4 (2013-02-24) ------------------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/PKG-INFO new/pep8-1.4.5/PKG-INFO --- old/pep8-1.4.4/PKG-INFO 2013-02-24 16:29:45.000000000 +0100 +++ new/pep8-1.4.5/PKG-INFO 2013-03-06 19:54:12.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pep8 -Version: 1.4.4 +Version: 1.4.5 Summary: Python style guide checker Home-page: http://pep8.readthedocs.org/ Author: Johann C. Rocholl @@ -99,6 +99,31 @@ ========= + 1.4.5 (2013-03-06) + ------------------ + + * When no path is specified, do not try to read from stdin. The feature + was added in 1.4.3, but it is not supported on Windows. Use ``-`` + filename argument to read from stdin. This usage is supported + since 1.3.4. (Issue #170) + + * Do not require ``setuptools`` in setup.py. It works around an issue + with ``pip`` and Python 3. (Issue #172) + + * Add ``__pycache__`` to the ignore list. + + * Change misleading message for E251. (Issue #171) + + * Do not report false E302 when the source file has a coding cookie or a + comment on the first line. (Issue #174) + + * Reorganize the tests and add tests for the API and for the command line + usage and options. (Issues #161 and #162) + + * Ignore all checks which are not explicitly selected when ``select`` is + passed to the ``StyleGuide`` constructor. + + 1.4.4 (2013-02-24) ------------------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/docs/intro.rst new/pep8-1.4.5/docs/intro.rst --- old/pep8-1.4.4/docs/intro.rst 2013-02-24 12:07:58.000000000 +0100 +++ new/pep8-1.4.5/docs/intro.rst 2013-02-26 14:24:19.000000000 +0100 @@ -245,7 +245,7 @@ | E242 (*) | tab after ',' | +----------+----------------------------------------------------------------------+ +----------+----------------------------------------------------------------------+ -| E251 | no spaces around keyword / parameter equals | +| E251 | unexpected spaces around keyword / parameter equals | +----------+----------------------------------------------------------------------+ +----------+----------------------------------------------------------------------+ | E261 | at least two spaces before inline comment | diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/pep8.egg-info/PKG-INFO new/pep8-1.4.5/pep8.egg-info/PKG-INFO --- old/pep8-1.4.4/pep8.egg-info/PKG-INFO 2013-02-24 16:29:45.000000000 +0100 +++ new/pep8-1.4.5/pep8.egg-info/PKG-INFO 2013-03-06 19:54:12.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pep8 -Version: 1.4.4 +Version: 1.4.5 Summary: Python style guide checker Home-page: http://pep8.readthedocs.org/ Author: Johann C. Rocholl @@ -99,6 +99,31 @@ ========= + 1.4.5 (2013-03-06) + ------------------ + + * When no path is specified, do not try to read from stdin. The feature + was added in 1.4.3, but it is not supported on Windows. Use ``-`` + filename argument to read from stdin. This usage is supported + since 1.3.4. (Issue #170) + + * Do not require ``setuptools`` in setup.py. It works around an issue + with ``pip`` and Python 3. (Issue #172) + + * Add ``__pycache__`` to the ignore list. + + * Change misleading message for E251. (Issue #171) + + * Do not report false E302 when the source file has a coding cookie or a + comment on the first line. (Issue #174) + + * Reorganize the tests and add tests for the API and for the command line + usage and options. (Issues #161 and #162) + + * Ignore all checks which are not explicitly selected when ``select`` is + passed to the ``StyleGuide`` constructor. + + 1.4.4 (2013-02-24) ------------------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/pep8.egg-info/SOURCES.txt new/pep8-1.4.5/pep8.egg-info/SOURCES.txt --- old/pep8-1.4.4/pep8.egg-info/SOURCES.txt 2013-02-24 16:29:45.000000000 +0100 +++ new/pep8-1.4.5/pep8.egg-info/SOURCES.txt 2013-03-06 19:54:12.000000000 +0100 @@ -17,7 +17,6 @@ pep8.egg-info/entry_points.txt pep8.egg-info/namespace_packages.txt pep8.egg-info/not-zip-safe -pep8.egg-info/requires.txt pep8.egg-info/top_level.txt testsuite/E10.py testsuite/E11.py @@ -43,7 +42,11 @@ testsuite/W29.py testsuite/W39.py testsuite/W60.py +testsuite/__init__.py testsuite/latin-1.py testsuite/python3.py -testsuite/test_pep8.py +testsuite/support.py +testsuite/test_all.py +testsuite/test_api.py +testsuite/test_shell.py testsuite/utf-8.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/pep8.egg-info/requires.txt new/pep8-1.4.5/pep8.egg-info/requires.txt --- old/pep8-1.4.4/pep8.egg-info/requires.txt 2013-02-24 16:29:45.000000000 +0100 +++ new/pep8-1.4.5/pep8.egg-info/requires.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -setuptools \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/pep8.py new/pep8-1.4.5/pep8.py --- old/pep8-1.4.4/pep8.py 2013-02-24 16:27:10.000000000 +0100 +++ new/pep8-1.4.5/pep8.py 2013-03-06 19:51:19.000000000 +0100 @@ -45,7 +45,7 @@ 700 statements 900 syntax error """ -__version__ = '1.4.4' +__version__ = '1.4.5' import os import sys @@ -62,7 +62,7 @@ except ImportError: from ConfigParser import RawConfigParser -DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git' +DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__' DEFAULT_IGNORE = 'E226,E24' if sys.platform == 'win32': DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') @@ -82,7 +82,7 @@ KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) -WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) +WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) WS_NEEDED_OPERATORS = frozenset([ '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>', '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=']) @@ -92,7 +92,7 @@ BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines'] INDENT_REGEX = re.compile(r'([ \t]*)') -RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*(,)') +RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,') RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,\s*\w+\s*,\s*\w+') ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') DOCSTRING_REGEX = re.compile(r'u?r?["\']') @@ -256,7 +256,7 @@ E303: def a():\n\n\n\n pass E304: @decorator\n\ndef a():\n pass """ - if line_number == 1: + if line_number < 3 and not previous_logical: return # Don't expect blank lines before the first line if previous_logical.startswith('@'): if blank_lines: @@ -691,10 +691,7 @@ binary_usage = (prev_type not in SKIP_TOKENS) if binary_usage: - if text in WS_OPTIONAL_OPERATORS: - need_space = None - else: - need_space = True + need_space = None elif text in WS_OPTIONAL_OPERATORS: need_space = None @@ -751,12 +748,12 @@ parens = 0 no_space = False prev_end = None + message = "E251 unexpected spaces around keyword / parameter equals" for token_type, text, start, end, line in tokens: if no_space: no_space = False if start != prev_end: - yield (prev_end, - "E251 no spaces around keyword / parameter equals") + yield (prev_end, message) elif token_type == tokenize.OP: if text == '(': parens += 1 @@ -765,8 +762,7 @@ elif parens and text == '=': no_space = True if start != prev_end: - yield (prev_end, - "E251 no spaces around keyword / parameter equals") + yield (prev_end, message) prev_end = end @@ -948,7 +944,7 @@ inst = match.group(1) if inst and isidentifier(inst) and inst not in SINGLETONS: return # Allow comparison for types which are not obvious - yield match.start(0), "E721 do not compare types, use 'isinstance()'" + yield match.start(), "E721 do not compare types, use 'isinstance()'" def python_3000_has_key(logical_line): @@ -979,7 +975,7 @@ """ match = RAISE_COMMA_REGEX.match(logical_line) if match and not RERAISE_COMMA_REGEX.match(logical_line): - yield match.start(1), "W602 deprecated form of raising exception" + yield match.end() - 1, "W602 deprecated form of raising exception" def python_3000_not_equal(logical_line): @@ -1575,9 +1571,14 @@ for index, value in enumerate(options.exclude): options.exclude[index] = value.rstrip('/') - # Ignore all checks which are not explicitly selected options.select = tuple(options.select or ()) - options.ignore = tuple(options.ignore or options.select and ('',)) + if not (options.select or options.ignore or + options.testsuite or options.doctest) and DEFAULT_IGNORE: + # The default choice: ignore controversial checks + options.ignore = tuple(DEFAULT_IGNORE.split(',')) + else: + # Ignore all checks which are not explicitly selected + options.ignore = tuple(options.ignore or options.select and ('',)) options.benchmark_keys = BENCHMARK_KEYS[:] options.ignore_code = self.ignore_code options.physical_checks = self.get_checks('physical_line') @@ -1810,18 +1811,11 @@ args.append(options.testsuite) elif not options.ensure_value('doctest', False): if parse_argv and not args: - if options.diff: + if options.diff or any(os.path.exists(name) + for name in PROJECT_CONFIG): args = ['.'] else: - import select - # wait for 1 second on the stdin fd - reads, __, __ = select.select([sys.stdin], [], [], 1.) - if reads: - args = ['-'] - elif any(os.path.exists(name) for name in PROJECT_CONFIG): - args = ['.'] - else: - parser.error('input not specified') + parser.error('input not specified') options = read_config(options, args, arglist, parser) options.reporter = parse_argv and options.quiet == 1 and FileReport @@ -1832,11 +1826,6 @@ options.select = options.select.split(',') if options.ignore: options.ignore = options.ignore.split(',') - elif not (options.select or - options.testsuite or options.doctest) and DEFAULT_IGNORE: - # The default choice: ignore controversial checks - # (for doctest and testsuite, all checks are required) - options.ignore = DEFAULT_IGNORE.split(',') if options.diff: options.reporter = DiffReport @@ -1852,10 +1841,8 @@ pep8style = StyleGuide(parse_argv=True, config_file=True) options = pep8style.options if options.doctest or options.testsuite: - sys.path[:0] = [TESTSUITE_PATH] - from test_pep8 import run_tests - del sys.path[0] - report = run_tests(pep8style, options.doctest, options.testsuite) + from testsuite.support import run_tests + report = run_tests(pep8style) else: report = pep8style.check_files() if options.statistics: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/setup.py new/pep8-1.4.5/setup.py --- old/pep8-1.4.4/setup.py 2013-02-09 22:25:59.000000000 +0100 +++ new/pep8-1.4.5/setup.py 2013-03-02 10:13:30.000000000 +0100 @@ -33,8 +33,8 @@ include_package_data=True, zip_safe=False, install_requires=[ - 'setuptools', - # -*- Extra requirements: -*- + # Broken with Python 3: https://github.com/pypa/pip/issues/650 + # 'setuptools', ], entry_points={ 'console_scripts': [ @@ -52,4 +52,5 @@ 'Programming Language :: Python :: 3', 'Topic :: Software Development :: Libraries :: Python Modules', ], + test_suite='testsuite.test_all.suite', ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/E30.py new/pep8-1.4.5/testsuite/E30.py --- old/pep8-1.4.4/testsuite/E30.py 2012-04-06 17:36:29.000000000 +0200 +++ new/pep8-1.4.5/testsuite/E30.py 2013-03-01 16:27:39.000000000 +0100 @@ -17,6 +17,19 @@ #: E302 +#!python +# -*- coding: utf-8 -*- +def a(): + pass +#: E302 +"""Main module.""" +def _main(): + pass +#: E302 +import sys +def get_sys_path(): + return sys.path +#: E302 def a(): pass diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/E30not.py new/pep8-1.4.5/testsuite/E30not.py --- old/pep8-1.4.4/testsuite/E30not.py 2012-06-01 08:48:52.000000000 +0200 +++ new/pep8-1.4.5/testsuite/E30not.py 2013-03-01 16:27:46.000000000 +0100 @@ -1,3 +1,19 @@ +#: Okay +class X: + pass +#: Okay + +def foo(): + pass +#: Okay +# -*- coding: utf-8 -*- +class X: + pass +#: Okay +# -*- coding: utf-8 -*- +def foo(): + pass +#: Okay class X: def a(): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/support.py new/pep8-1.4.5/testsuite/support.py --- old/pep8-1.4.4/testsuite/support.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pep8-1.4.5/testsuite/support.py 2013-03-02 11:06:57.000000000 +0100 @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- +import os.path +import re +import sys + +from pep8 import Checker, BaseReport, StandardReport, readlines + +SELFTEST_REGEX = re.compile(r'\b(Okay|[EW]\d{3}):\s(.*)') +ROOT_DIR = os.path.dirname(os.path.dirname(__file__)) + + +class PseudoFile(list): + """Simplified file interface.""" + write = list.append + + def getvalue(self): + return ''.join(self) + + +class TestReport(StandardReport): + """Collect the results for the tests.""" + + def __init__(self, options): + options.benchmark_keys += ['test cases', 'failed tests'] + super(TestReport, self).__init__(options) + self._verbose = options.verbose + + def get_file_results(self): + # Check if the expected errors were found + label = '%s:%s:1' % (self.filename, self.line_offset) + codes = sorted(self.expected) + for code in codes: + if not self.counters.get(code): + self.file_errors += 1 + self.total_errors += 1 + print('%s: error %s not found' % (label, code)) + if self._verbose and not self.file_errors: + print('%s: passed (%s)' % + (label, ' '.join(codes) or 'Okay')) + self.counters['test cases'] += 1 + if self.file_errors: + self.counters['failed tests'] += 1 + # Reset counters + for key in set(self.counters) - set(self._benchmark_keys): + del self.counters[key] + self.messages = {} + return super(TestReport, self).get_file_results() + + def print_results(self): + results = ("%(physical lines)d lines tested: %(files)d files, " + "%(test cases)d test cases%%s." % self.counters) + if self.total_errors: + print(results % ", %s failures" % self.total_errors) + else: + print(results % "") + print("Test failed." if self.total_errors else "Test passed.") + + +def selftest(options): + """ + Test all check functions with test cases in docstrings. + """ + count_failed = count_all = 0 + report = BaseReport(options) + counters = report.counters + checks = options.physical_checks + options.logical_checks + for name, check, argument_names in checks: + for line in check.__doc__.splitlines(): + line = line.lstrip() + match = SELFTEST_REGEX.match(line) + if match is None: + continue + code, source = match.groups() + lines = [part.replace(r'\t', '\t') + '\n' + for part in source.split(r'\n')] + checker = Checker(lines=lines, options=options, report=report) + checker.check_all() + error = None + if code == 'Okay': + if len(counters) > len(options.benchmark_keys): + codes = [key for key in counters + if key not in options.benchmark_keys] + error = "incorrectly found %s" % ', '.join(codes) + elif not counters.get(code): + error = "failed to find %s" % code + # Keep showing errors for multiple tests + for key in set(counters) - set(options.benchmark_keys): + del counters[key] + report.messages = {} + count_all += 1 + if not error: + if options.verbose: + print("%s: %s" % (code, source)) + else: + count_failed += 1 + print("pep8.py: %s:" % error) + for line in checker.lines: + print(line.rstrip()) + return count_failed, count_all + + +def init_tests(pep8style): + """ + Initialize testing framework. + + A test file can provide many tests. Each test starts with a + declaration. This declaration is a single line starting with '#:'. + It declares codes of expected failures, separated by spaces or 'Okay' + if no failure is expected. + If the file does not contain such declaration, it should pass all + tests. If the declaration is empty, following lines are not checked, + until next declaration. + + Examples: + + * Only E224 and W701 are expected: #: E224 W701 + * Following example is conform: #: Okay + * Don't check these lines: #: + """ + report = pep8style.init_report(TestReport) + runner = pep8style.input_file + + def run_tests(filename): + """Run all the tests from a file.""" + lines = readlines(filename) + ['#:\n'] + line_offset = 0 + codes = ['Okay'] + testcase = [] + count_files = report.counters['files'] + for index, line in enumerate(lines): + if not line.startswith('#:'): + if codes: + # Collect the lines of the test case + testcase.append(line) + continue + if codes and index: + codes = [c for c in codes if c != 'Okay'] + # Run the checker + runner(filename, testcase, expected=codes, + line_offset=line_offset) + # output the real line numbers + line_offset = index + 1 + # configure the expected errors + codes = line.split()[1:] + # empty the test case buffer + del testcase[:] + report.counters['files'] = count_files + 1 + return report.counters['failed tests'] + + pep8style.runner = run_tests + + +def run_tests(style): + options = style.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(style) + return style.check_files() + +# nose should not collect these functions +init_tests.__test__ = run_tests.__test__ = False diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/test_all.py new/pep8-1.4.5/testsuite/test_all.py --- old/pep8-1.4.4/testsuite/test_all.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pep8-1.4.5/testsuite/test_all.py 2013-03-02 16:30:45.000000000 +0100 @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os.path +import sys +import unittest + +import pep8 +from testsuite.support import init_tests, selftest, ROOT_DIR + +# Note: please only use a subset of unittest methods which were present +# in Python 2.5: assert(True|False|Equal|NotEqual|Raises) + + +class Pep8TestCase(unittest.TestCase): + """Test the standard errors and warnings (E and W).""" + + def setUp(self): + self._style = pep8.StyleGuide( + paths=[os.path.join(ROOT_DIR, 'testsuite')], + select='E,W', quiet=True) + + def test_doctest(self): + import doctest + fail_d, done_d = doctest.testmod(pep8, verbose=False, report=False) + self.assertTrue(done_d, msg='tests not found') + self.assertFalse(fail_d, msg='%s failure(s)' % fail_d) + + def test_selftest(self): + fail_s, done_s = selftest(self._style.options) + self.assertTrue(done_s, msg='tests not found') + self.assertFalse(fail_s, msg='%s failure(s)' % fail_s) + + def test_checkers_testsuite(self): + init_tests(self._style) + report = self._style.check_files() + self.assertFalse(report.total_errors, + msg='%s failure(s)' % report.total_errors) + + def test_own_dog_food(self): + files = [pep8.__file__.rstrip('oc'), __file__.rstrip('oc'), + os.path.join(ROOT_DIR, 'setup.py')] + report = self._style.init_report(pep8.StandardReport) + report = self._style.check_files(files) + self.assertFalse(report.total_errors, + msg='Failures: %s' % report.messages) + + +def suite(): + from testsuite import test_api, test_shell + + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(Pep8TestCase)) + suite.addTest(unittest.makeSuite(test_api.APITestCase)) + suite.addTest(unittest.makeSuite(test_shell.ShellTestCase)) + return suite + + +def _main(): + return unittest.TextTestRunner(verbosity=2).run(suite()) + +if __name__ == '__main__': + sys.exit(not _main()) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/test_api.py new/pep8-1.4.5/testsuite/test_api.py --- old/pep8-1.4.4/testsuite/test_api.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pep8-1.4.5/testsuite/test_api.py 2013-03-02 18:54:11.000000000 +0100 @@ -0,0 +1,296 @@ +# -*- coding: utf-8 -*- +import os.path +import shlex +import sys +import unittest + +import pep8 +from testsuite.support import ROOT_DIR, PseudoFile + +E11 = os.path.join(ROOT_DIR, 'testsuite', 'E11.py') + + +class APITestCase(unittest.TestCase): + """Test the public methods.""" + + def setUp(self): + self._saved_stdout = sys.stdout + self._saved_stderr = sys.stderr + self._saved_checks = pep8._checks + sys.stdout = PseudoFile() + sys.stderr = PseudoFile() + pep8._checks = dict((k, dict((f, (vals[0][:], vals[1])) + for (f, vals) in v.items())) + for (k, v) in self._saved_checks.items()) + + def tearDown(self): + sys.stdout = self._saved_stdout + sys.stderr = self._saved_stderr + pep8._checks = self._saved_checks + + def reset(self): + del sys.stdout[:], sys.stderr[:] + + def test_register_physical_check(self): + def check_dummy(physical_line, line_number): + if False: + yield + pep8.register_check(check_dummy, ['Z001']) + + self.assertTrue(check_dummy in pep8._checks['physical_line']) + codes, args = pep8._checks['physical_line'][check_dummy] + self.assertTrue('Z001' in codes) + self.assertEqual(args, ['physical_line', 'line_number']) + + options = pep8.StyleGuide().options + self.assertTrue(any(func == check_dummy + for name, func, args in options.physical_checks)) + + def test_register_logical_check(self): + def check_dummy(logical_line, tokens): + if False: + yield + pep8.register_check(check_dummy, ['Z401']) + + self.assertTrue(check_dummy in pep8._checks['logical_line']) + codes, args = pep8._checks['logical_line'][check_dummy] + self.assertTrue('Z401' in codes) + self.assertEqual(args, ['logical_line', 'tokens']) + + pep8.register_check(check_dummy, []) + pep8.register_check(check_dummy, ['Z402', 'Z403']) + codes, args = pep8._checks['logical_line'][check_dummy] + self.assertEqual(codes, ['Z401', 'Z402', 'Z403']) + self.assertEqual(args, ['logical_line', 'tokens']) + + options = pep8.StyleGuide().options + self.assertTrue(any(func == check_dummy + for name, func, args in options.logical_checks)) + + def test_register_ast_check(self): + class DummyChecker(object): + def __init__(self, tree, filename): + pass + + def run(self): + if False: + yield + pep8.register_check(DummyChecker, ['Z701']) + + self.assertTrue(DummyChecker in pep8._checks['tree']) + codes, args = pep8._checks['tree'][DummyChecker] + self.assertTrue('Z701' in codes) + self.assertTrue(args is None) + + options = pep8.StyleGuide().options + self.assertTrue(any(cls == DummyChecker + for name, cls, args in options.ast_checks)) + + def test_register_invalid_check(self): + class DummyChecker(object): + def __init__(self, filename): + pass + + def run(self): + if False: + yield + + def check_dummy(logical, tokens): + if False: + yield + pep8.register_check(DummyChecker, ['Z741']) + pep8.register_check(check_dummy, ['Z441']) + + for checkers in pep8._checks.values(): + self.assertTrue(DummyChecker not in checkers) + self.assertTrue(check_dummy not in checkers) + + self.assertRaises(TypeError, pep8.register_check) + + def test_styleguide(self): + report = pep8.StyleGuide().check_files() + self.assertEqual(report.total_errors, 0) + self.assertFalse(sys.stdout) + self.assertFalse(sys.stderr) + self.reset() + + report = pep8.StyleGuide().check_files(['missing-file']) + stdout = sys.stdout.getvalue().splitlines() + self.assertEqual(len(stdout), report.total_errors) + self.assertEqual(report.total_errors, 1) + # < 3.3 returns IOError; >= 3.3 returns FileNotFoundError + self.assertTrue(stdout[0].startswith("missing-file:1:1: E902 ")) + self.assertFalse(sys.stderr) + self.reset() + + report = pep8.StyleGuide().check_files([E11]) + stdout = sys.stdout.getvalue().splitlines() + self.assertEqual(len(stdout), report.total_errors) + self.assertEqual(report.total_errors, 4) + self.assertFalse(sys.stderr) + self.reset() + + # Passing the paths in the constructor gives same result + report = pep8.StyleGuide(paths=[E11]).check_files() + stdout = sys.stdout.getvalue().splitlines() + self.assertEqual(len(stdout), report.total_errors) + self.assertEqual(report.total_errors, 4) + self.assertFalse(sys.stderr) + self.reset() + + def test_styleguide_options(self): + # Instanciate a simple checker + pep8style = pep8.StyleGuide(paths=[E11]) + + # Check style's attributes + self.assertEqual(pep8style.checker_class, pep8.Checker) + self.assertEqual(pep8style.paths, [E11]) + self.assertEqual(pep8style.runner, pep8style.input_file) + self.assertEqual(pep8style.options.ignore_code, pep8style.ignore_code) + self.assertEqual(pep8style.options.paths, pep8style.paths) + + # Check unset options + for o in ('benchmark', 'config', 'count', 'diff', + 'doctest', 'quiet', 'show_pep8', 'show_source', + 'statistics', 'testsuite', 'verbose'): + oval = getattr(pep8style.options, o) + self.assertTrue(oval in (None, False), msg='%s = %r' % (o, oval)) + + # Check default options + self.assertTrue(pep8style.options.repeat) + self.assertEqual(pep8style.options.benchmark_keys, + ['directories', 'files', + 'logical lines', 'physical lines']) + self.assertEqual(pep8style.options.exclude, + ['.svn', 'CVS', '.bzr', '.hg', '.git', '__pycache__']) + self.assertEqual(pep8style.options.filename, ['*.py']) + self.assertEqual(pep8style.options.format, 'default') + self.assertEqual(pep8style.options.select, ()) + self.assertEqual(pep8style.options.ignore, ('E226', 'E24')) + self.assertEqual(pep8style.options.max_line_length, 79) + + def test_styleguide_ignore_code(self): + def parse_argv(argstring): + _saved_argv = sys.argv + sys.argv = shlex.split('pep8 %s /dev/null' % argstring) + try: + return pep8.StyleGuide(parse_argv=True) + finally: + sys.argv = _saved_argv + + options = parse_argv('').options + self.assertEqual(options.select, ()) + self.assertEqual(options.ignore, ('E226', 'E24')) + + options = parse_argv('--doctest').options + self.assertEqual(options.select, ()) + self.assertEqual(options.ignore, ()) + + options = parse_argv('--ignore E,W').options + self.assertEqual(options.select, ()) + self.assertEqual(options.ignore, ('E', 'W')) + + options = parse_argv('--select E,W').options + self.assertEqual(options.select, ('E', 'W')) + self.assertEqual(options.ignore, ('',)) + + pep8style = pep8.StyleGuide(paths=[E11]) + self.assertFalse(pep8style.ignore_code('E112')) + self.assertFalse(pep8style.ignore_code('W191')) + self.assertTrue(pep8style.ignore_code('E241')) + + pep8style = pep8.StyleGuide(select='E', paths=[E11]) + self.assertFalse(pep8style.ignore_code('E112')) + self.assertTrue(pep8style.ignore_code('W191')) + self.assertFalse(pep8style.ignore_code('E241')) + + pep8style = pep8.StyleGuide(select='W', paths=[E11]) + self.assertTrue(pep8style.ignore_code('E112')) + self.assertFalse(pep8style.ignore_code('W191')) + self.assertTrue(pep8style.ignore_code('E241')) + + def test_styleguide_excluded(self): + pep8style = pep8.StyleGuide(paths=[E11]) + + self.assertFalse(pep8style.excluded('./foo/bar')) + self.assertFalse(pep8style.excluded('./foo/bar/main.py')) + + self.assertTrue(pep8style.excluded('./CVS')) + self.assertTrue(pep8style.excluded('./subdir/CVS')) + self.assertTrue(pep8style.excluded('__pycache__')) + self.assertTrue(pep8style.excluded('./__pycache__')) + self.assertTrue(pep8style.excluded('subdir/__pycache__')) + + self.assertFalse(pep8style.excluded('draftCVS')) + self.assertFalse(pep8style.excluded('./CVSoup')) + self.assertFalse(pep8style.excluded('./CVS/subdir')) + + def test_styleguide_checks(self): + pep8style = pep8.StyleGuide(paths=[E11]) + + # Default lists of checkers + self.assertTrue(len(pep8style.options.physical_checks) > 5) + self.assertTrue(len(pep8style.options.logical_checks) > 10) + self.assertEqual(len(pep8style.options.ast_checks), 0) + + # Sanity check + for name, check, args in pep8style.options.physical_checks: + self.assertEqual(check.__name__, name) + self.assertEqual(args[0], 'physical_line') + for name, check, args in pep8style.options.logical_checks: + self.assertEqual(check.__name__, name) + self.assertEqual(args[0], 'logical_line') + + # Do run E11 checks + options = pep8.StyleGuide().options + self.assertTrue(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + options = pep8.StyleGuide(select=['E']).options + self.assertTrue(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + options = pep8.StyleGuide(ignore=['W']).options + self.assertTrue(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + options = pep8.StyleGuide(ignore=['E12']).options + self.assertTrue(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + + # Do not run E11 checks + options = pep8.StyleGuide(select=['W']).options + self.assertFalse(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + options = pep8.StyleGuide(ignore=['E']).options + self.assertFalse(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + options = pep8.StyleGuide(ignore=['E11']).options + self.assertFalse(any(func == pep8.indentation + for name, func, args in options.logical_checks)) + + def test_styleguide_init_report(self): + pep8style = pep8.StyleGuide(paths=[E11]) + + self.assertEqual(pep8style.options.reporter, pep8.StandardReport) + self.assertEqual(type(pep8style.options.report), pep8.StandardReport) + + class MinorityReport(pep8.BaseReport): + pass + + report = pep8style.init_report(MinorityReport) + self.assertEqual(pep8style.options.report, report) + self.assertEqual(type(report), MinorityReport) + + pep8style = pep8.StyleGuide(paths=[E11], reporter=MinorityReport) + self.assertEqual(type(pep8style.options.report), MinorityReport) + self.assertEqual(pep8style.options.reporter, MinorityReport) + + def test_styleguide_check_files(self): + pep8style = pep8.StyleGuide(paths=[E11]) + + report = pep8style.check_files() + self.assertTrue(report.total_errors) + + self.assertRaises(TypeError, pep8style.check_files, 42) + # < 3.3 raises TypeError; >= 3.3 raises AttributeError + self.assertRaises(Exception, pep8style.check_files, [42]) + # TODO: runner + # TODO: input_file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/test_pep8.py new/pep8-1.4.5/testsuite/test_pep8.py --- old/pep8-1.4.4/testsuite/test_pep8.py 2013-02-24 12:22:13.000000000 +0100 +++ new/pep8-1.4.5/testsuite/test_pep8.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,170 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import os.path -import re -import sys - -import pep8 -from pep8 import Checker, StyleGuide, BaseReport, StandardReport, readlines - -SELFTEST_REGEX = re.compile(r'\b(Okay|[EW]\d{3}):\s(.*)') - - -class TestReport(StandardReport): - """Collect the results for the tests.""" - - def __init__(self, options): - options.benchmark_keys += ['test cases', 'failed tests'] - super(TestReport, self).__init__(options) - self._verbose = options.verbose - - def get_file_results(self): - # Check if the expected errors were found - label = '%s:%s:1' % (self.filename, self.line_offset) - codes = sorted(self.expected) - for code in codes: - if not self.counters.get(code): - self.file_errors += 1 - self.total_errors += 1 - print('%s: error %s not found' % (label, code)) - if self._verbose and not self.file_errors: - print('%s: passed (%s)' % - (label, ' '.join(codes) or 'Okay')) - self.counters['test cases'] += 1 - if self.file_errors: - self.counters['failed tests'] += 1 - # Reset counters - for key in set(self.counters) - set(self._benchmark_keys): - del self.counters[key] - self.messages = {} - return super(TestReport, self).get_file_results() - - def print_results(self): - results = ("%(physical lines)d lines tested: %(files)d files, " - "%(test cases)d test cases%%s." % self.counters) - if self.total_errors: - print(results % ", %s failures" % self.total_errors) - else: - print(results % "") - print("Test failed." if self.total_errors else "Test passed.") - - -def init_tests(pep8style): - """ - Initialize testing framework. - - A test file can provide many tests. Each test starts with a - declaration. This declaration is a single line starting with '#:'. - It declares codes of expected failures, separated by spaces or 'Okay' - if no failure is expected. - If the file does not contain such declaration, it should pass all - tests. If the declaration is empty, following lines are not checked, - until next declaration. - - Examples: - - * Only E224 and W701 are expected: #: E224 W701 - * Following example is conform: #: Okay - * Don't check these lines: #: - """ - report = pep8style.init_report(TestReport) - runner = pep8style.input_file - - def run_tests(filename): - """Run all the tests from a file.""" - lines = readlines(filename) + ['#:\n'] - line_offset = 0 - codes = ['Okay'] - testcase = [] - count_files = report.counters['files'] - for index, line in enumerate(lines): - if not line.startswith('#:'): - if codes: - # Collect the lines of the test case - testcase.append(line) - continue - if codes and index: - codes = [c for c in codes if c != 'Okay'] - # Run the checker - runner(filename, testcase, expected=codes, - line_offset=line_offset) - # output the real line numbers - line_offset = index + 1 - # configure the expected errors - codes = line.split()[1:] - # empty the test case buffer - del testcase[:] - report.counters['files'] = count_files + 1 - return report.counters['failed tests'] - - pep8style.runner = run_tests - - -def selftest(options): - """ - Test all check functions with test cases in docstrings. - """ - count_failed = count_all = 0 - report = BaseReport(options) - counters = report.counters - checks = options.physical_checks + options.logical_checks - for name, check, argument_names in checks: - for line in check.__doc__.splitlines(): - line = line.lstrip() - match = SELFTEST_REGEX.match(line) - if match is None: - continue - code, source = match.groups() - lines = [part.replace(r'\t', '\t') + '\n' - for part in source.split(r'\n')] - checker = Checker(lines=lines, options=options, report=report) - checker.check_all() - error = None - if code == 'Okay': - if len(counters) > len(options.benchmark_keys): - codes = [key for key in counters - if key not in options.benchmark_keys] - error = "incorrectly found %s" % ', '.join(codes) - elif not counters.get(code): - error = "failed to find %s" % code - # Keep showing errors for multiple tests - for key in set(counters) - set(options.benchmark_keys): - del counters[key] - report.messages = {} - count_all += 1 - if not error: - if options.verbose: - print("%s: %s" % (code, source)) - else: - count_failed += 1 - print("%s: %s:" % (pep8.__file__, error)) - for line in checker.lines: - print(line.rstrip()) - return count_failed, count_all - - -def run_tests(style, doctest=True, testsuite=False): - options = style.options - if 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 testsuite: - init_tests(style) - return style.check_files() - - -if __name__ == '__main__': - if len(sys.argv) > 1: - sys.exit(pep8._main()) - pep8style = StyleGuide(paths=[os.path.dirname(__file__)], ignore=None) - report = run_tests(pep8style, doctest=True, testsuite=True) - report.print_results() - sys.exit(1 if report.total_errors else 0) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pep8-1.4.4/testsuite/test_shell.py new/pep8-1.4.5/testsuite/test_shell.py --- old/pep8-1.4.4/testsuite/test_shell.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pep8-1.4.5/testsuite/test_shell.py 2013-03-02 15:04:11.000000000 +0100 @@ -0,0 +1,185 @@ +# -*- coding: utf-8 -*- +import os.path +import sys +import unittest + +import pep8 +from testsuite.support import ROOT_DIR, PseudoFile + + +class ShellTestCase(unittest.TestCase): + """Test the usual CLI options and output.""" + + def setUp(self): + self._saved_argv = sys.argv + self._saved_stdout = sys.stdout + self._saved_stderr = sys.stderr + self._saved_pconfig = pep8.PROJECT_CONFIG + self._saved_cpread = pep8.RawConfigParser.read + self._saved_stdin_get_value = pep8.stdin_get_value + self._config_filenames = [] + self.stdin = '' + sys.argv = ['pep8'] + sys.stdout = PseudoFile() + sys.stderr = PseudoFile() + pep8.RawConfigParser.read = self._config_filenames.append + pep8.stdin_get_value = self.stdin_get_value + + def tearDown(self): + sys.argv = self._saved_argv + sys.stdout = self._saved_stdout + sys.stderr = self._saved_stderr + pep8.PROJECT_CONFIG = self._saved_pconfig + pep8.RawConfigParser.read = self._saved_cpread + pep8.stdin_get_value = self._saved_stdin_get_value + + def stdin_get_value(self): + return self.stdin + + def pep8(self, *args): + del sys.stdout[:], sys.stderr[:] + sys.argv[1:] = args + try: + pep8._main() + errorcode = None + except SystemExit: + errorcode = sys.exc_info()[1].code + return sys.stdout.getvalue(), sys.stderr.getvalue(), errorcode + + def test_print_usage(self): + stdout, stderr, errcode = self.pep8('--help') + self.assertFalse(errcode) + self.assertFalse(stderr) + self.assertTrue(stdout.startswith("Usage: pep8 [options] input")) + + stdout, stderr, errcode = self.pep8('--version') + self.assertFalse(errcode) + self.assertFalse(stderr) + self.assertEqual(stdout.count('\n'), 1) + + stdout, stderr, errcode = self.pep8('--obfuscated') + self.assertEqual(errcode, 2) + self.assertEqual(stderr.splitlines(), + ["Usage: pep8 [options] input ...", "", + "pep8: error: no such option: --obfuscated"]) + self.assertFalse(stdout) + + self.assertFalse(self._config_filenames) + + def test_check_simple(self): + E11 = os.path.join(ROOT_DIR, 'testsuite', 'E11.py') + stdout, stderr, errcode = self.pep8(E11) + stdout = stdout.splitlines() + self.assertEqual(errcode, 1) + self.assertFalse(stderr) + self.assertEqual(len(stdout), 4) + for line, num, col in zip(stdout, (3, 6, 9, 12), (3, 6, 1, 5)): + path, x, y, msg = line.split(':') + self.assertTrue(path.endswith(E11)) + self.assertEqual(x, str(num)) + self.assertEqual(y, str(col)) + self.assertTrue(msg.startswith(' E11')) + # Config file read from the pep8's tox.ini + (config_filename,) = self._config_filenames + self.assertTrue(config_filename.endswith('tox.ini')) + + def test_check_stdin(self): + pep8.PROJECT_CONFIG = () + stdout, stderr, errcode = self.pep8('-') + self.assertFalse(errcode) + self.assertFalse(stderr) + self.assertFalse(stdout) + + self.stdin = 'import os, sys\n' + stdout, stderr, errcode = self.pep8('-') + stdout = stdout.splitlines() + self.assertEqual(errcode, 1) + self.assertFalse(stderr) + self.assertEqual(stdout, + ['stdin:1:10: E401 multiple imports on one line']) + + def test_check_non_existent(self): + self.stdin = 'import os, sys\n' + stdout, stderr, errcode = self.pep8('fictitious.py') + self.assertEqual(errcode, 1) + self.assertFalse(stderr) + self.assertTrue(stdout.startswith('fictitious.py:1:1: E902 ')) + + def test_check_noarg(self): + # issue #170: do not read stdin by default + pep8.PROJECT_CONFIG = () + stdout, stderr, errcode = self.pep8() + self.assertEqual(errcode, 2) + self.assertEqual(stderr.splitlines(), + ["Usage: pep8 [options] input ...", "", + "pep8: error: input not specified"]) + self.assertFalse(self._config_filenames) + + def test_check_diff(self): + pep8.PROJECT_CONFIG = () + diff_lines = [ + "--- testsuite/E11.py 2006-06-01 08:49:50 +0500", + "+++ testsuite/E11.py 2008-04-06 17:36:29 +0500", + "@@ -2,4 +2,7 @@", + " if x > 2:", + " print x", + "+#: E111", + "+if True:", + "+ print", + " #: E112", + " if False:", + "", + ] + + self.stdin = '\n'.join(diff_lines) + stdout, stderr, errcode = self.pep8('--diff') + stdout = stdout.splitlines() + self.assertEqual(errcode, 1) + self.assertFalse(stderr) + for line, num, col in zip(stdout, (3, 6), (3, 6)): + path, x, y, msg = line.split(':') + self.assertEqual(x, str(num)) + self.assertEqual(y, str(col)) + self.assertTrue(msg.startswith(' E11')) + + diff_lines[:2] = ["--- a/testsuite/E11.py 2006-06-01 08:49 +0400", + "+++ b/testsuite/E11.py 2008-04-06 17:36 +0400"] + self.stdin = '\n'.join(diff_lines) + stdout, stderr, errcode = self.pep8('--diff') + stdout = stdout.splitlines() + self.assertEqual(errcode, 1) + self.assertFalse(stderr) + for line, num, col in zip(stdout, (3, 6), (3, 6)): + path, x, y, msg = line.split(':') + self.assertEqual(x, str(num)) + self.assertEqual(y, str(col)) + self.assertTrue(msg.startswith(' E11')) + + # issue #127, #137: one-line chunks + diff_lines[:-1] = ["diff --git a/testsuite/E11.py b/testsuite/E11.py", + "index 8735e25..2ecb529 100644", + "--- a/testsuite/E11.py", + "+++ b/testsuite/E11.py", + "@@ -5,0 +6 @@ if True:", + "+ print"] + self.stdin = '\n'.join(diff_lines) + stdout, stderr, errcode = self.pep8('--diff') + (stdout,) = stdout.splitlines() + self.assertEqual(errcode, 1) + self.assertFalse(stderr) + self.assertTrue('testsuite/E11.py:6:6: E111 ' in stdout) + + # missing '--diff' + self.stdin = '\n'.join(diff_lines) + stdout, stderr, errcode = self.pep8() + self.assertEqual(errcode, 2) + self.assertFalse(stdout) + self.assertTrue(stderr.startswith('Usage: pep8 [options] input ...')) + + # no matching file in the diff + diff_lines[3] = "+++ b/testsuite/lost/E11.py" + self.stdin = '\n'.join(diff_lines) + stdout, stderr, errcode = self.pep8('--diff') + self.assertFalse(errcode) + self.assertFalse(stdout) + self.assertFalse(stderr) -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@hilbert.suse.de