Skip to content

Commit

Permalink
Merge pull request #135 from jamescooke/test-simple-files
Browse files Browse the repository at this point in the history
Add simple filenames to test file pattern
  • Loading branch information
jamescooke committed Mar 6, 2020
2 parents c5e8d51 + a9f4343 commit ba4b126
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Unreleased_
See also `latest documentation
<https://flake8-aaa.readthedocs.io/en/latest/#__unreleased_marker__>`_.

Changed
.......

* Simply named files are now checked. For example ``test.py`` and ``tests.py``
are now checked but were skipped before. `#124
<https://github.com/jamescooke/flake8-aaa/issues/124>`_.

Removed
.......

Expand Down
2 changes: 2 additions & 0 deletions examples/bad/bad_expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ examples/bad/test_aaa05.py:9:1: AAA05 blank line in block
examples/bad/test_example.py:4:5: AAA03 expected 1 blank line before Act block, found none
examples/bad/test_noqa_flake8.py:11:17: E225 missing whitespace around operator
examples/bad/test_noqa_flake8.py:5:10: E201 whitespace after '('
examples/bad/test.py:4:1: AAA01 no Act block found in test
examples/bad/tests.py:4:1: AAA01 no Act block found in test
6 changes: 6 additions & 0 deletions examples/bad/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Check that files named "test.py" are checked


def test():
action = sorted([3, 2, 1])
assert action == [1, 2, 3]
6 changes: 6 additions & 0 deletions examples/bad/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Check that files named "tests.py" are checked


def test():
action = sorted([3, 2, 1])
assert action == [1, 2, 3]
8 changes: 4 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ cryptography==2.8 # via secretstorage
docutils==0.16 # via -c test.txt, readme-renderer
idna==2.9 # via -c test.txt, requests
importlib-metadata==1.5.0 # via -c test.txt, keyring, twine
jeepney==0.4.2 # via keyring, secretstorage
keyring==21.1.0 # via twine
jeepney==0.4.3 # via keyring, secretstorage
keyring==21.1.1 # via twine
pip-tools==4.5.1 # via -r dev.in
pkginfo==1.5.0.1 # via twine
pycparser==2.19 # via cffi
pycparser==2.20 # via cffi
pygments==2.5.2 # via -c test.txt, readme-renderer
readme-renderer==24.0 # via twine
requests-toolbelt==0.9.1 # via twine
Expand All @@ -28,7 +28,7 @@ tqdm==4.43.0 # via twine
twine==3.1.1 # via -r dev.in
urllib3==1.25.8 # via -c test.txt, requests
webencodings==0.5.1 # via bleach
zipp==3.0.0 # via -c test.txt, importlib-metadata
zipp==3.1.0 # via -c test.txt, importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools
17 changes: 8 additions & 9 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ flake8==3.7.9 # via -c base.txt, -r test.in
idna==2.9 # via requests
imagesize==1.2.0 # via sphinx
importlib-metadata==1.5.0 # via pluggy, pytest, tox, virtualenv
importlib-resources==1.0.2 # via virtualenv
isort==4.3.21 # via -r test.in
jinja2==2.11.1 # via sphinx
markupsafe==1.1.1 # via jinja2
mccabe==0.6.1 # via -c base.txt, flake8
more-itertools==8.2.0 # via pytest
mypy-extensions==0.4.3 # via mypy
mypy==0.761 # via -r test.in
packaging==20.1 # via pytest, sphinx, tox
packaging==20.3 # via pytest, sphinx, tox
pluggy==0.13.1 # via pytest, tox
py==1.8.1 # via pytest, tox
pycodestyle==2.5.0 # via -c base.txt, flake8
Expand All @@ -40,22 +39,22 @@ restructuredtext-lint==1.3.0 # via -r test.in
six==1.14.0 # via -c base.txt, -r test.in, packaging, tox, virtualenv
snowballstemmer==2.0.0 # via sphinx
sphinx-rtd-theme==0.4.3 # via -r test.in
sphinx==2.4.3 # via -r test.in, sphinx-rtd-theme
sphinxcontrib-applehelp==1.0.1 # via sphinx
sphinxcontrib-devhelp==1.0.1 # via sphinx
sphinx==2.4.4 # via -r test.in, sphinx-rtd-theme
sphinxcontrib-applehelp==1.0.2 # via sphinx
sphinxcontrib-devhelp==1.0.2 # via sphinx
sphinxcontrib-htmlhelp==1.0.3 # via sphinx
sphinxcontrib-jsmath==1.0.1 # via sphinx
sphinxcontrib-qthelp==1.0.2 # via sphinx
sphinxcontrib-serializinghtml==1.1.3 # via sphinx
sphinxcontrib-qthelp==1.0.3 # via sphinx
sphinxcontrib-serializinghtml==1.1.4 # via sphinx
toml==0.10.0 # via tox
tox==3.14.5 # via -r test.in
typed-ast==1.4.1 # via mypy
typing-extensions==3.7.4.1 # via mypy
urllib3==1.25.8 # via requests
virtualenv==20.0.7 # via tox
virtualenv==20.0.8 # via tox
wcwidth==0.1.8 # via pytest
yapf==0.29.0 # via -r test.in
zipp==3.0.0 # via importlib-metadata
zipp==3.1.0 # via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools
5 changes: 4 additions & 1 deletion src/flake8_aaa/helpers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import ast
import os
import re
from typing import List, Set

from asttokens.util import Token

test_file_pattern = re.compile(r'test(_.*|s)?\.py$')


def is_test_file(filename: str) -> bool:
"""
Check that path to file being checked passed by flake8 looks like a pytest
test file.
"""
return os.path.basename(filename).startswith('test_')
return bool(test_file_pattern.match(os.path.basename(filename)))


def first_non_blank_char(line: str) -> int:
Expand Down
7 changes: 6 additions & 1 deletion tests/helpers/test_is_test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
'path, expected_result',
[
# Non-test files give False.
('./test.py', False),
('./helper.py', False),
('tests/conftest.py', False),
# Finds files that start with 'test_' to be test files.
('./test_helpers.py', True),
('tests/helpers/test_is_test_file.py', True),
# Finds simple test file names "test.py" and "tests.py".
('./test.py', True),
('project/app/tests.py', True),
# Finds accidental additional underscore test file
('project/app/test_.py', True),
]
)
def test(path, expected_result):
Expand Down

0 comments on commit ba4b126

Please sign in to comment.