Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from Robpol86/unicode_fix
Browse files Browse the repository at this point in the history
Unicode fix.
  • Loading branch information
Robpol86 committed Jun 1, 2015
2 parents a0acf1e + 68df683 commit 086fb46
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 115 deletions.
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
requirements*.txt

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -48,14 +49,6 @@ coverage.xml
*.mo
*.pot

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log

Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ install:

script:
- tox
- (cd ./tests && ls .coverage.py34 .coverage.py33 .coverage.pypy3 .coverage.pypy .coverage.py27 .coverage.py26)
- tox -e combine py34 py33 pypy3 pypy py27 py26

after_success:
- mv tests/.coverage* .
- coverage combine
- mv tests/.coverage .
- codecov
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

29 changes: 17 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ validating docstrings.
:target: https://pypi.python.org/pypi/flake8-pep257/
:alt: Downloads

`Quickstart`_
=============
Quickstart
==========

Install:

Expand All @@ -43,31 +43,36 @@ Run:
flake8
`Error Codes`_
==============
Error Codes
===========

List of error codes are available here: http://pep257.readthedocs.org/en/latest/error_codes.html

`Configuration`_
================
Configuration
=============

Settings may be specified in ``tox.ini`` (under the ``[flake8]`` or ``[pep257]`` sections), ``setup.cfg``, and/or
``.pep257``. Refer to `this page <http://pep257.readthedocs.org/en/latest/usage.html>`_ for more information.

When specifying settings in ``tox.ini`` under the ``[flake8]`` section, use ``show-source`` instead of ``source`` and
``show-pep257`` instead of ``explain``.

`Changelog`_
============
Changelog
=========

This project adheres to `Semantic Versioning <http://semver.org/>`_.

`1.0.2 - 2015-04-04`_
---------------------
1.0.3 - 2015-05-31
------------------

* Fixed unicode bug.

1.0.2 - 2015-04-04
------------------

* Fixed setup.py requirements bug.

`1.0.0 - 2015-04-04`_
---------------------
1.0.0 - 2015-04-04
------------------

* Initial release.
7 changes: 2 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ build_script:

test_script:
- tox
- cd tests
- ps: ls .coverage.py34x64, .coverage.py34, .coverage.py33x64, .coverage.py33, .coverage.py27x64, .coverage.py27
- cd ..
- tox -e combine py34x64 py34 py33x64 py33 py27x64 py27

after_test:
- mv tests/.coverage.* .
- coverage combine
- mv tests/.coverage .
- codecov
6 changes: 4 additions & 2 deletions flake8_pep257.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
https://pypi.python.org/pypi/flake8-pep257
"""

from codecs import open

import pep257
import pep8

__author__ = '@Robpol86'
__license__ = 'MIT'
__version__ = '1.0.2'
__version__ = '1.0.3'


def load_file(filename):
Expand All @@ -25,7 +27,7 @@ def load_file(filename):
"""
if filename in ('stdin', '-', None):
return 'stdin', pep8.stdin_get_value()
with open(filename) as f:
with open(filename, encoding='utf-8') as f:
return filename, f.read()


Expand Down
2 changes: 0 additions & 2 deletions requirements-test.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

71 changes: 6 additions & 65 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#!/usr/bin/env python
"""Setup script for the project."""

import atexit
import codecs
import os
import re
import subprocess
import sys
from distutils.spawn import find_executable

import setuptools
from setuptools.command.test import test

_PACKAGES = lambda: [os.path.join(r, s) for r, d, _ in os.walk(NAME_FILE) for s in d if s != '__pycache__']
_VERSION_RE = re.compile(r"^__(version|author|license)__ = '([\w\.@]+)'$", re.MULTILINE)
Expand Down Expand Up @@ -38,19 +33,12 @@
NAME = 'flake8-pep257'
NAME_FILE = NAME.replace('-', '_')
PACKAGE = False
REQUIRES_INSTALL = ['flake8', 'pep257']
REQUIRES_TEST = ['pytest-cov']
REQUIRES_ALL = REQUIRES_INSTALL + REQUIRES_TEST
VERSION_FILE = os.path.join(NAME_FILE, '__init__.py') if PACKAGE else '{0}.py'.format(NAME_FILE)


def _requires(path):
"""Read requirements file."""
if not os.path.exists(os.path.join(HERE, path)):
return list()
file_handle = codecs.open(os.path.join(HERE, path), encoding='utf-8')
requirements = [i.strip() for i in file_handle if i[0] != '-']
file_handle.close()
return requirements


def _safe_read(path, length):
"""Read file contents."""
if not os.path.exists(os.path.join(HERE, path)):
Expand All @@ -61,63 +49,17 @@ def _safe_read(path, length):
return contents


class PyTest(test):
"""Run tests with pytest."""

description = 'Run all tests.'
user_options = []
CMD = 'test'
TEST_ARGS = ['--cov-report', 'term-missing', '--cov', NAME_FILE, 'tests']

def finalize_options(self):
"""Finalize options."""
overflow_args = sys.argv[sys.argv.index(self.CMD) + 1:]
test.finalize_options(self)
setattr(self, 'test_args', self.TEST_ARGS + overflow_args)
setattr(self, 'test_suite', True)

def run_tests(self):
"""Run the tests."""
# Import here, cause outside the eggs aren't loaded.
pytest = __import__('pytest')
err_no = pytest.main(self.test_args)
sys.exit(err_no)


class PyTestPdb(PyTest):
"""Run tests with pytest and drop to debugger on test failure/errors."""

_ipdb = 'ipdb' if sys.version_info[:2] > (2, 6) else 'pdb'
description = 'Run all tests, drops to {0} upon unhandled exception.'.format(_ipdb)
CMD = 'testpdb'
TEST_ARGS = ['--{0}'.format(_ipdb), 'tests']


class PyTestCovWeb(PyTest):
"""Run the tests and open a web browser (OS X only) showing coverage information."""

description = 'Generates HTML report on test coverage.'
CMD = 'testcovweb'
TEST_ARGS = ['--cov-report', 'html', '--cov', NAME_FILE, 'tests']

def run_tests(self):
"""Run the tests and then open."""
if find_executable('open'):
atexit.register(lambda: subprocess.call(['open', os.path.join(HERE, 'htmlcov', 'index.html')]))
PyTest.run_tests(self)


ALL_DATA = dict(
author_email='[email protected]',
classifiers=CLASSIFIERS,
cmdclass={PyTest.CMD: PyTest, PyTestPdb.CMD: PyTestPdb, PyTestCovWeb.CMD: PyTestCovWeb},
description=DESCRIPTION,
entry_points={'flake8.extension': 'D = flake8_pep257:Main'},
install_requires=_requires('requirements.txt'),
install_requires=REQUIRES_INSTALL,
keywords=KEYWORDS,
long_description=_safe_read('README.rst', 15000),
name=NAME,
tests_require=_requires('requirements-test.txt'),
requires=REQUIRES_INSTALL,
tests_require=REQUIRES_TEST,
url='https://github.com/Robpol86/{0}'.format(NAME),
zip_safe=True,
)
Expand All @@ -126,7 +68,6 @@ def run_tests(self):
# noinspection PyTypeChecker
ALL_DATA.update(dict(_VERSION_RE.findall(_safe_read(VERSION_FILE, 1500).replace('\r\n', '\n'))))
ALL_DATA.update(dict(py_modules=[NAME_FILE]) if not PACKAGE else dict(packages=[NAME_FILE] + _PACKAGES()))
ALL_DATA['requires'] = ALL_DATA['install_requires']


if __name__ == '__main__':
Expand Down
35 changes: 35 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding=utf-8
"""Plugins for pytest."""

from textwrap import dedent
Expand All @@ -13,6 +14,40 @@ def sample_module():
import sys
def error(message, code=1):
'''Prints error message to stderr and exits with a status of 1.'''
if message:
print('ERROR: {0}'.format(message))
else:
print()
sys.exit(code)
class Test(object):
'''Does nothing.'''
pass
"""
return dedent(code)


@pytest.fixture
def sample_module_unicode():
"""Sample python module for testing with Unicode characters."""
code = u"""\
#!/usr/bin/env python
import sys
UNICODE_TABLE = '''
+Foods----+--------+---------+
| Name | Color | Type |
+---------+--------+---------+
| Avocado | green | nut |
| Cupuaçu | yellow | fruit |
| äöüß | | neither |
+---------+--------+---------+
'''
def error(message, code=1):
'''Prints error message to stderr and exits with a status of 1.'''
if message:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def test_ignore(tmpdir, capsys, sample_module, monkeypatch, stdin, which_cfg):
with pytest.raises(SystemExit):
flake8.main.main()
out, err = capsys.readouterr()
assert not err
if 'DeprecationWarning' in err and (True, 'tox.ini', (2, 6)) == (stdin, which_cfg, sys.version_info[:2]):
assert err # Temporary hack until flake8 fixes https://gitlab.com/pycqa/flake8/blob/master/flake8/engine.py#L33
else:
assert not err

expected = (
'./sample_module.py:1:1: D100 Missing docstring in public module\n'
Expand Down
17 changes: 8 additions & 9 deletions tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@


@pytest.mark.parametrize('stdin', [True, False])
def test(tmpdir, capsys, sample_module, monkeypatch, stdin):
def test(tmpdir, capsys, sample_module_unicode, monkeypatch, stdin):
"""Test default settings."""
sys.argv = ['flake8', '-' if stdin else '.', '-j1']
os.chdir(str(tmpdir.ensure('project_dir', dir=True)))

if stdin:
monkeypatch.setattr('pep8.stdin_get_value', lambda: sample_module)
monkeypatch.setattr('pep8.stdin_get_value', lambda: sample_module_unicode)
else:
with open('sample_module.py', 'w') as f:
f.write(sample_module)
tmpdir.join('project_dir', 'sample_module.py').write(sample_module_unicode.encode('utf-8'), 'wb')

with pytest.raises(SystemExit):
flake8.main.main()
Expand All @@ -26,11 +25,11 @@ def test(tmpdir, capsys, sample_module, monkeypatch, stdin):

expected = (
'./sample_module.py:1:1: D100 Missing docstring in public module\n'
'./sample_module.py:5:1: D300 Use """triple double quotes""" (found \'\'\'-quotes)\n'
'./sample_module.py:5:1: D401 First line should be in imperative mood (\'Print\', not \'Prints\')\n'
'./sample_module.py:14:1: D203 1 blank line required before class docstring (found 0)\n'
'./sample_module.py:14:1: D204 1 blank line required after class docstring (found 0)\n'
'./sample_module.py:14:1: D300 Use """triple double quotes""" (found \'\'\'-quotes)\n'
'./sample_module.py:15:1: D300 Use """triple double quotes""" (found \'\'\'-quotes)\n'
'./sample_module.py:15:1: D401 First line should be in imperative mood (\'Print\', not \'Prints\')\n'
'./sample_module.py:24:1: D203 1 blank line required before class docstring (found 0)\n'
'./sample_module.py:24:1: D204 1 blank line required after class docstring (found 0)\n'
'./sample_module.py:24:1: D300 Use """triple double quotes""" (found \'\'\'-quotes)\n'
)
if stdin:
expected = expected.replace('./sample_module.py:', 'stdin:')
Expand Down
Loading

0 comments on commit 086fb46

Please sign in to comment.