pax_global_header00006660000000000000000000000064142742102220014506gustar00rootroot0000000000000052 comment=a552dfe711ab5c4d7881532c6945b83e877b549b vikingco-flake8-pytest-a552dfe/000077500000000000000000000000001427421022200165125ustar00rootroot00000000000000vikingco-flake8-pytest-a552dfe/.gitignore000066400000000000000000000000361427421022200205010ustar00rootroot00000000000000*.egg-info *.pyc dist/ build/ vikingco-flake8-pytest-a552dfe/CODEOWNERS000066400000000000000000000002051427421022200201020ustar00rootroot00000000000000# Lines starting with '#' are comments. # Each line is a file pattern followed by one or more owners. * @nielsvanoch @kristofclaes vikingco-flake8-pytest-a552dfe/LICENSE000066400000000000000000000020341427421022200175160ustar00rootroot00000000000000Copyright 2017 Unleashed NV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. vikingco-flake8-pytest-a552dfe/README.rst000066400000000000000000000011671427421022200202060ustar00rootroot00000000000000Flake8 pytest plugin ==================== Check for uses of Django-style assert-statements in tests. So no more ``self.assertEqual(a, b)``, but instead ``assert a == b``. This module provides a plugin for ``flake8``, the Python code checker. Installation ------------ You can install or upgrade ``flake8-pytest`` with these commands:: $ pip install flake8-pytest $ pip install --upgrade flake8-pytest Plugin for Flake8 ----------------- When both ``flake8`` and ``flake8-pytest`` are installed, the plugin is available in ``flake8``:: $ flake8 --version 2.0 (pep8: 1.4.5, flake8-pytest: 1.1, pyflakes: 0.6.1) vikingco-flake8-pytest-a552dfe/flake8_pytest.py000066400000000000000000000044241427421022200216520ustar00rootroot00000000000000import ast import tokenize from sys import stdin __version__ = '1.4' PYTEST_ERROR_CODE = 'T003' PYTEST_ERROR_MESSAGE = 'use of Django-style assert statement found (instead of regular assert)' ASSERTS = ('assertAlmostEqual', 'assertAlmostEquals', 'assertDictEqual', 'assertEqual', 'assertEquals', 'assertFalse', 'assertGreater', 'assertGreaterEqual', 'assertIn', 'assertIs', 'assertIsInstance', 'assertIsNone', 'assertIsNot', 'assertIsNotNone', 'assertItemsEqual', 'assertLess', 'assertLessEqual', 'assertMultiLineEqual', 'assertNotAlmostEqual', 'assertNotAlmostEquals', 'assertNotContains', 'assertNotEqual', 'assertNotEquals', 'assertNotIn', 'assertNotIsInstance', 'assertNotRegexpMatches', 'assertRaises', 'assertRaisesMessage', 'assertRaisesRegexp', 'assertRegexpMatches', 'assertSetEqual', 'assertTrue', 'assert_') class PytestAssertChecker(object): name = 'flake8-pytest' version = __version__ def __init__(self, tree, filename='(none)', builtins=None): self.tree = tree self.filename = (filename == 'stdin' and stdin) or filename def run(self): # Get lines to ignore if self.filename == stdin: noqa = _get_noqa_lines(self.filename) else: with open(self.filename, 'r') as file_to_check: noqa = _get_noqa_lines(file_to_check.readlines()) # Run the actual check errors = [] for node in ast.walk(self.tree): if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr in ASSERTS and node.lineno not in noqa: errors.append({ "message": '{0} {1}: {2}'.format(PYTEST_ERROR_CODE, PYTEST_ERROR_MESSAGE, node.func.attr), "line": node.lineno, "col": node.col_offset }) # Yield the found errors for error in errors: yield (error.get("line"), error.get("col"), error.get("message"), type(self)) def _get_noqa_lines(code): tokens = tokenize.generate_tokens(lambda L=iter(code): next(L)) return [token[2][0] for token in tokens if token[0] == tokenize.COMMENT and (token[1].endswith('noqa') or (isinstance(token[0], str) and token[0].endswith('noqa')))] vikingco-flake8-pytest-a552dfe/requirements.txt000066400000000000000000000000071427421022200217730ustar00rootroot00000000000000flake8 vikingco-flake8-pytest-a552dfe/setup.cfg000066400000000000000000000000341427421022200203300ustar00rootroot00000000000000[bdist_wheel] universal = 1 vikingco-flake8-pytest-a552dfe/setup.py000066400000000000000000000027671427421022200202400ustar00rootroot00000000000000from __future__ import with_statement from setuptools import setup def get_version(fname='flake8_pytest.py'): with open(fname) as f: for line in f: if line.startswith('__version__'): return eval(line.split('=')[-1]) def get_long_description(): descr = [] for fname in ('README.rst',): with open(fname) as f: descr.append(f.read()) return '\n\n'.join(descr) install_requires = ['flake8'] setup( name='flake8-pytest', version=get_version(), description="pytest assert checker plugin for flake8", long_description=get_long_description(), keywords='flake8 pytest', author='VikingCo NV', author_email='technology@vikingco.com', url='https://github.com/vikingco/flake8-pytest', license='MIT', py_modules=['flake8_pytest'], zip_safe=False, entry_points={ 'flake8.extension': [ 'T = flake8_pytest:PytestAssertChecker', ], }, install_requires=install_requires, classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Console', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Quality Assurance', ], )