Skip to content

Commit

Permalink
Fix / improve recently merged patches + CI
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jul 8, 2019
1 parent f00d483 commit d4b0073
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# To activate, change the Appveyor settings to use `.appveyor.yml`.
install:
- python -m pip install --upgrade tox virtualenv
- python -m pip install --upgrade setuptools tox virtualenv

build: off

Expand Down
10 changes: 3 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ classifiers =
[options]
package_dir=
=src
packages =
flake8
flake8.api
flake8.formatting
flake8.main
flake8.options
flake8.plugins
packages = find:

install_requires=
# We document the reasoning for using ranges here:
Expand All @@ -57,6 +51,8 @@ install_requires=

python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*

[options.packages.find]
where = src

[options.entry_points]
distutils.commands=
Expand Down
2 changes: 1 addition & 1 deletion src/flake8/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, style_guide, arguments, checker_plugins):
"tokens": 0,
}
self.exclude = tuple(
itertools.chain(self.options.exclude, self.options.extend_exclude),
itertools.chain(self.options.exclude, self.options.extend_exclude)
)

def _process_statistics(self):
Expand Down
2 changes: 1 addition & 1 deletion src/flake8/main/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def register_default_options(option_manager):
parse_from_config=True,
comma_separated_list=True,
help="Comma-separated list of files or directories to add to the list"
" of excluded ones."
" of excluded ones.",
)

add_option(
Expand Down
4 changes: 2 additions & 2 deletions src/flake8/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def filenames_from(arg, predicate=None):


def fnmatch(filename, patterns):
# type: (str, List[str]) -> bool
# type: (str, Sequence[str]) -> bool
"""Wrap :func:`fnmatch.fnmatch` to add some functionality.
:param str filename:
Expand Down Expand Up @@ -453,7 +453,7 @@ def parameters_for(plugin):


def matches_filename(path, patterns, log_message, logger):
# type: (str, List[str], str, logging.Logger) -> bool
# type: (str, Sequence[str], str, logging.Logger) -> bool
"""Use fnmatch to discern if a path exists in patterns.
:param str path:
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Integration tests for the main entrypoint of flake8."""
import os

import mock

from flake8 import utils
Expand Down Expand Up @@ -69,10 +71,11 @@ def test_extend_exclude(tmpdir, capsys):
application.Application().run(['--extend-exclude=vendor,legacy'])

out, err = capsys.readouterr()
assert out == '''\
expected_out = '''\
./project/t.py:1:1: F401 'os' imported but unused
./project/t.py:2:1: F401 'sys' imported but unused
'''
assert out == expected_out.replace('/', os.sep)
assert err == ''


Expand Down
61 changes: 45 additions & 16 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,39 +163,68 @@ def test_fnmatch(filename, patterns, expected):
assert utils.fnmatch(filename, patterns) is expected


@pytest.fixture
def files_dir(tmpdir):
"""Create test dir for testing filenames_from."""
with tmpdir.as_cwd():
tmpdir.join('a/b/c.py').ensure()
tmpdir.join('a/b/d.py').ensure()
tmpdir.join('a/b/e/f.py').ensure()
yield tmpdir


def _normpath(s):
return s.replace('/', os.sep)


def _normpaths(pths):
return {_normpath(pth) for pth in pths}


@pytest.mark.usefixtures('files_dir')
def test_filenames_from_a_directory():
"""Verify that filenames_from walks a directory."""
filenames = list(utils.filenames_from('src/flake8/'))
assert len(filenames) > 2
assert 'src/flake8/__init__.py' in filenames
filenames = set(utils.filenames_from(_normpath('a/b/')))
# should include all files
expected = _normpaths(('a/b/c.py', 'a/b/d.py', 'a/b/e/f.py'))
assert filenames == expected


@pytest.mark.usefixtures('files_dir')
def test_filenames_from_a_directory_with_a_predicate():
"""Verify that predicates filter filenames_from."""
filenames = list(utils.filenames_from(
arg='src/flake8/',
predicate=lambda filename: filename == 'flake8/__init__.py',
filenames = set(utils.filenames_from(
arg=_normpath('a/b/'),
predicate=lambda path: path.endswith(_normpath('b/c.py')),
))
assert len(filenames) > 2
assert 'flake8/__init__.py' not in filenames
# should not include c.py
expected = _normpaths(('a/b/d.py', 'a/b/e/f.py'))
assert filenames == expected


@pytest.mark.usefixtures('files_dir')
def test_filenames_from_a_directory_with_a_predicate_from_the_current_dir():
"""Verify that predicates filter filenames_from."""
filenames = list(utils.filenames_from(
arg='./src/flake8',
predicate=lambda filename: filename == '__init__.py',
filenames = set(utils.filenames_from(
arg=_normpath('./a/b'),
predicate=lambda path: path == 'c.py',
))
assert len(filenames) > 2
assert './src/flake8/__init__.py' in filenames
# none should have matched the predicate so all returned
expected = _normpaths(('./a/b/c.py', './a/b/d.py', './a/b/e/f.py'))
assert filenames == expected


@pytest.mark.usefixtures('files_dir')
def test_filenames_from_a_single_file():
"""Verify that we simply yield that filename."""
filenames = list(utils.filenames_from('flake8/__init__.py'))
filenames = set(utils.filenames_from(_normpath('a/b/c.py')))
assert filenames == {_normpath('a/b/c.py')}


assert len(filenames) == 1
assert ['flake8/__init__.py'] == filenames
def test_filenames_from_a_single_file_does_not_exist():
"""Verify that a passed filename which does not exist is returned back."""
filenames = set(utils.filenames_from(_normpath('d/n/e.py')))
assert filenames == {_normpath('d/n/e.py')}


def test_filenames_from_exclude_doesnt_exclude_directory_names(tmpdir):
Expand Down

0 comments on commit d4b0073

Please sign in to comment.