././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734282913.0988023 pytest_black-0.6.0/0000755000076500000240000000000014727607241013375 5ustar00jaracostaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282893.0 pytest_black-0.6.0/.gitignore0000644000076500000240000000163614727607215015374 0ustar00jaracostaff# virtual environments .venv/ .venv # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py # Flask instance folder instance/ # Sphinx documentation docs/_build/ # MkDocs documentation /site/ # PyBuilder target/ # IPython Notebook .ipynb_checkpoints # pyenv .python-version ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734280852.0 pytest_black-0.6.0/LICENSE0000644000076500000240000000207014727603224014376 0ustar00jaracostaff The MIT License (MIT) Copyright (c) 2018 ShopKeep Inc 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. ././@PaxHeader0000000000000000000000000000003200000000000010210 xustar0026 mtime=1734282913.09859 pytest_black-0.6.0/PKG-INFO0000644000076500000240000000502314727607241014472 0ustar00jaracostaffMetadata-Version: 2.1 Name: pytest-black Version: 0.6.0 Summary: A pytest plugin to enable format checking with black Home-page: https://github.com/coherent-oss/pytest-black Author: ShopKeep, Inc. Author-email: oss@shopkeep.com Maintainer: Jason R. Coombs Maintainer-email: jaraco@jaraco.com License: MIT Classifier: Development Status :: 4 - Beta Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Testing Classifier: Programming Language :: Python :: 3 Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License Requires-Python: >=3.5 Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: pytest>=7.0.0 Requires-Dist: black; python_version >= "3.6" Requires-Dist: toml pytest-black ============ A pytest plugin to enable format checking with [black](https://github.com/ambv/black). Requirements ------------ * [pytest](https://docs.pytest.org/en/latest/) * [black](https://github.com/ambv/black) There is a minimum requirement of black 19.3b0 or later. Installation ------------ ``` $ pip install pytest-black ``` Usage ----- To run pytest with formatting checks provided by black: ``` $ pytest --black ``` The plugin will output a diff of suggested formatting changes (if any exist). Changes will _not_ be applied automatically. Configuration ------------- You can override default black configuration options by placing a `pyproject.toml` file in your project directory. See example configuration [here](https://github.com/ambv/black/blob/master/pyproject.toml). Python package management ------------------------- For *poetry* to work correctly, include this in your pyproject.toml configuration file: ``` [tool.poetry.dev-dependencies] ... black = { version = "*", allow-prereleases = true } ... ``` This is necessary because at the time of writing all the *black* releases in PyPI have been tagged as pre-releases (beta code), which breaks *poetry*'s dependency resolution. Testing ------- To run the tests against a selection of Python interpreters: ``` $ tox ``` To run against a specific interpreter (e.g. Python 3.6): ``` $ tox -e py36 ``` The `tox.ini` file in the root of this repository is used to configure the test environment. License ------- Distributed under the terms of the `MIT` license, `pytest-black` is free and open source software Issues ------ If you encounter any problems, please [file an issue](https://github.com/coherent-oss/pytest-black/issues) along with a detailed description. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282561.0 pytest_black-0.6.0/README.md0000644000076500000240000000335714727606501014662 0ustar00jaracostaffpytest-black ============ A pytest plugin to enable format checking with [black](https://github.com/ambv/black). Requirements ------------ * [pytest](https://docs.pytest.org/en/latest/) * [black](https://github.com/ambv/black) There is a minimum requirement of black 19.3b0 or later. Installation ------------ ``` $ pip install pytest-black ``` Usage ----- To run pytest with formatting checks provided by black: ``` $ pytest --black ``` The plugin will output a diff of suggested formatting changes (if any exist). Changes will _not_ be applied automatically. Configuration ------------- You can override default black configuration options by placing a `pyproject.toml` file in your project directory. See example configuration [here](https://github.com/ambv/black/blob/master/pyproject.toml). Python package management ------------------------- For *poetry* to work correctly, include this in your pyproject.toml configuration file: ``` [tool.poetry.dev-dependencies] ... black = { version = "*", allow-prereleases = true } ... ``` This is necessary because at the time of writing all the *black* releases in PyPI have been tagged as pre-releases (beta code), which breaks *poetry*'s dependency resolution. Testing ------- To run the tests against a selection of Python interpreters: ``` $ tox ``` To run against a specific interpreter (e.g. Python 3.6): ``` $ tox -e py36 ``` The `tox.ini` file in the root of this repository is used to configure the test environment. License ------- Distributed under the terms of the `MIT` license, `pytest-black` is free and open source software Issues ------ If you encounter any problems, please [file an issue](https://github.com/coherent-oss/pytest-black/issues) along with a detailed description. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734282913.0983374 pytest_black-0.6.0/pytest_black.egg-info/0000755000076500000240000000000014727607241017553 5ustar00jaracostaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282913.0 pytest_black-0.6.0/pytest_black.egg-info/PKG-INFO0000644000076500000240000000502314727607241020650 0ustar00jaracostaffMetadata-Version: 2.1 Name: pytest-black Version: 0.6.0 Summary: A pytest plugin to enable format checking with black Home-page: https://github.com/coherent-oss/pytest-black Author: ShopKeep, Inc. Author-email: oss@shopkeep.com Maintainer: Jason R. Coombs Maintainer-email: jaraco@jaraco.com License: MIT Classifier: Development Status :: 4 - Beta Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Testing Classifier: Programming Language :: Python :: 3 Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License Requires-Python: >=3.5 Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: pytest>=7.0.0 Requires-Dist: black; python_version >= "3.6" Requires-Dist: toml pytest-black ============ A pytest plugin to enable format checking with [black](https://github.com/ambv/black). Requirements ------------ * [pytest](https://docs.pytest.org/en/latest/) * [black](https://github.com/ambv/black) There is a minimum requirement of black 19.3b0 or later. Installation ------------ ``` $ pip install pytest-black ``` Usage ----- To run pytest with formatting checks provided by black: ``` $ pytest --black ``` The plugin will output a diff of suggested formatting changes (if any exist). Changes will _not_ be applied automatically. Configuration ------------- You can override default black configuration options by placing a `pyproject.toml` file in your project directory. See example configuration [here](https://github.com/ambv/black/blob/master/pyproject.toml). Python package management ------------------------- For *poetry* to work correctly, include this in your pyproject.toml configuration file: ``` [tool.poetry.dev-dependencies] ... black = { version = "*", allow-prereleases = true } ... ``` This is necessary because at the time of writing all the *black* releases in PyPI have been tagged as pre-releases (beta code), which breaks *poetry*'s dependency resolution. Testing ------- To run the tests against a selection of Python interpreters: ``` $ tox ``` To run against a specific interpreter (e.g. Python 3.6): ``` $ tox -e py36 ``` The `tox.ini` file in the root of this repository is used to configure the test environment. License ------- Distributed under the terms of the `MIT` license, `pytest-black` is free and open source software Issues ------ If you encounter any problems, please [file an issue](https://github.com/coherent-oss/pytest-black/issues) along with a detailed description. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282913.0 pytest_black-0.6.0/pytest_black.egg-info/SOURCES.txt0000644000076500000240000000052414727607241021440 0ustar00jaracostaff.gitignore LICENSE README.md pytest_black.py setup.py tox.ini pytest_black.egg-info/PKG-INFO pytest_black.egg-info/SOURCES.txt pytest_black.egg-info/dependency_links.txt pytest_black.egg-info/entry_points.txt pytest_black.egg-info/requires.txt pytest_black.egg-info/top_level.txt tests/conftest.py tests/test_black.py tests/test_no_black.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282913.0 pytest_black-0.6.0/pytest_black.egg-info/dependency_links.txt0000644000076500000240000000000114727607241023621 0ustar00jaracostaff ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282913.0 pytest_black-0.6.0/pytest_black.egg-info/entry_points.txt0000644000076500000240000000004014727607241023043 0ustar00jaracostaff[pytest11] black = pytest_black ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282913.0 pytest_black-0.6.0/pytest_black.egg-info/requires.txt0000644000076500000240000000006514727607241022154 0ustar00jaracostaffpytest>=7.0.0 toml [:python_version >= "3.6"] black ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282913.0 pytest_black-0.6.0/pytest_black.egg-info/top_level.txt0000644000076500000240000000001514727607241022301 0ustar00jaracostaffpytest_black ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282893.0 pytest_black-0.6.0/pytest_black.py0000644000076500000240000000673714727607215016451 0ustar00jaracostaff# -*- coding: utf-8 -*- # stdlib imports import subprocess import re import sys # third-party imports import pytest import toml HISTKEY = "black/mtimes" def pytest_addoption(parser): group = parser.getgroup("general") group.addoption( "--black", action="store_true", help="enable format checking with black" ) def pytest_collect_file(file_path, path, parent): config = parent.config if config.option.black and path.ext in [".py", ".pyi"]: return BlackFile.from_parent(parent, path=file_path) def pytest_configure(config): # load cached mtimes at session startup if config.option.black and hasattr(config, "cache"): config._blackmtimes = config.cache.get(HISTKEY, {}) config.addinivalue_line("markers", "black: enable format checking with black") def pytest_unconfigure(config): # save cached mtimes at end of session if hasattr(config, "_blackmtimes"): config.cache.set(HISTKEY, config._blackmtimes) class BlackFile(pytest.File): def collect(self): """ returns a list of children (items and collectors) for this collection node. """ yield BlackItem.from_parent(self, name="black") class BlackItem(pytest.Item): def __init__(self, **kwargs): super(BlackItem, self).__init__(**kwargs) self.add_marker("black") try: with open("pyproject.toml") as toml_file: settings = toml.load(toml_file)["tool"]["black"] if "include" in settings.keys(): settings["include"] = self._re_fix_verbose(settings["include"]) if "exclude" in settings.keys(): settings["exclude"] = self._re_fix_verbose(settings["exclude"]) self.pyproject = settings except Exception: self.pyproject = {} def setup(self): pytest.importorskip("black") mtimes = getattr(self.config, "_blackmtimes", {}) self._blackmtime = self.path.stat().st_mtime old = mtimes.get(str(self.path), 0) if self._blackmtime == old: pytest.skip("file(s) previously passed black format checks") if self._skip_test(): pytest.skip("file(s) excluded by pyproject.toml") def runtest(self): cmd = [sys.executable, "-m", "black", "--check", "--diff", "--quiet", str(self.path)] try: subprocess.run( cmd, check=True, stdout=subprocess.PIPE, universal_newlines=True ) except subprocess.CalledProcessError as e: raise BlackError(e) mtimes = getattr(self.config, "_blackmtimes", {}) mtimes[str(self.path)] = self._blackmtime def repr_failure(self, excinfo): if excinfo.errisinstance(BlackError): return excinfo.value.args[0].stdout return super(BlackItem, self).repr_failure(excinfo) def reportinfo(self): return (self.path, -1, "Black format check") def _skip_test(self): return self._excluded() or (not self._included()) def _included(self): if "include" not in self.pyproject: return True return re.search(self.pyproject["include"], str(self.path)) def _excluded(self): if "exclude" not in self.pyproject: return False return re.search(self.pyproject["exclude"], str(self.path)) def _re_fix_verbose(self, regex): if "\n" in regex: regex = "(?x)" + regex return re.compile(regex) class BlackError(Exception): pass ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734282913.0988462 pytest_black-0.6.0/setup.cfg0000644000076500000240000000004614727607241015216 0ustar00jaracostaff[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282561.0 pytest_black-0.6.0/setup.py0000644000076500000240000000263514727606501015113 0ustar00jaracostaff#!/usr/bin/env python # -*- coding: utf-8 -*- import os import codecs from setuptools import setup def read(fname): file_path = os.path.join(os.path.dirname(__file__), fname) return codecs.open(file_path, encoding="utf-8").read() setup( name="pytest-black", author="ShopKeep, Inc.", author_email="oss@shopkeep.com", maintainer="Jason R. Coombs", maintainer_email="jaraco@jaraco.com", license="MIT", url="https://github.com/coherent-oss/pytest-black", description="A pytest plugin to enable format checking with black", long_description=read("README.md"), long_description_content_type="text/markdown", py_modules=["pytest_black"], python_requires=">=3.5", install_requires=[ "pytest>=7.0.0", # Minimum requirement on black 19.3b0 or later is not declared here as # workaround for https://github.com/pypa/pipenv/issues/3928 'black; python_version >= "3.6"', "toml", ], use_scm_version=True, setup_requires=["setuptools_scm"], classifiers=[ "Development Status :: 4 - Beta", "Framework :: Pytest", "Intended Audience :: Developers", "Topic :: Software Development :: Testing", "Programming Language :: Python :: 3", "Operating System :: OS Independent", "License :: OSI Approved :: MIT License", ], entry_points={"pytest11": ["black = pytest_black"]}, ) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1734282913.098178 pytest_black-0.6.0/tests/0000755000076500000240000000000014727607241014537 5ustar00jaracostaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734280852.0 pytest_black-0.6.0/tests/conftest.py0000644000076500000240000000046614727603224016741 0ustar00jaracostaffimport importlib import pytest pytest_plugins = "pytester" @pytest.fixture def black_available(): pytest.importorskip('black') @pytest.fixture def black_unavailable(): try: importlib.import_module('black') pytest.skip("Black is available") except ImportError: return ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282852.0 pytest_black-0.6.0/tests/test_black.py0000644000076500000240000001055614727607144017235 0ustar00jaracostaff# -*- coding: utf-8 -*- import pytest pytestmark = pytest.mark.usefixtures('black_available') def test_help_message(testdir): result = testdir.runpytest("--help") result.stdout.fnmatch_lines(["*--black*enable format checking with black"]) def test_fail(testdir): """Assert test fails due to single quoted strings """ testdir.makepyfile( """ def hello(): print('Hello, world') """ ) result = testdir.runpytest("--black") result.assert_outcomes(failed=1) def test_pass(testdir): """Assert test passes when no formatting issues are found """ p = testdir.makepyfile( """ def hello(): print("Hello, world!") """ ) # replace trailing newline (stripped by testdir.makepyfile) p = p.write(p.read() + "\n") result = testdir.runpytest("--black") result.assert_outcomes(passed=1) def test_mtime_cache(testdir): """Assert test is skipped when file hasn't changed """ p = testdir.makepyfile( """ def hello(): print("Hello, world!") """ ) # replace trailing newline (stripped by testdir.makepyfile) contents = p.read() + "\n" p.write(contents) # Test once to populate the cache result = testdir.runpytest("--black") result.assert_outcomes(passed=1) # Run it again, it should be skipped result = testdir.runpytest("--black", "-rs") result.assert_outcomes(skipped=1) result.stdout.fnmatch_lines(["SKIP*previously passed black format checks"]) # Update the file and test again. p.write(contents) result = testdir.runpytest("--black") result.assert_outcomes(passed=1) def test_exclude(testdir): """Assert test is skipped if path is excluded even if also included """ testdir.makefile( "pyproject.toml", """ [tool.black] include = 'test_exclude.py' exclude = '.*' """, ) p = testdir.makepyfile( """ def hello(): print("Hello, world!") """ ) # replace trailing newline (stripped by testdir.makepyfile) p = p.write(p.read() + "\n") # Rename pyproject.toml ¯\_(ツ)_/¯ testdir.run("mv", "test_exclude.pyproject.toml", "pyproject.toml") result = testdir.runpytest("--black") result.assert_outcomes(skipped=1, passed=0) def test_exclude_folder(testdir): """Assert test is skipped for files in a folder """ testdir.makefile( "pyproject.toml", """ [tool.black] exclude = ''' ( /( first_folder | ignore_folder )/ ) ''' """, ) p = testdir.makepyfile( """ def hello(): print("Hello, world!") """ ) # replace trailing newline (stripped by testdir.makepyfile) p = p.write(p.read() + "\n") # Move file into folder that should be excluded ignore_folder = testdir.mkdir("ignore_folder") testdir.run("mv", "test_exclude_folder.py", ignore_folder) # Rename pyproject.toml ¯\_(ツ)_/¯ testdir.run("mv", "test_exclude_folder.pyproject.toml", "pyproject.toml") result = testdir.runpytest("--black") result.assert_outcomes(skipped=1, passed=0) def test_include(testdir): """Assert test is not skipped if path is included but not excluded """ testdir.makefile( "pyproject.toml", """ [tool.black] include = 'test_include' """, ) p = testdir.makepyfile( """ def hello(): print("Hello, world!") """ ) # replace trailing newline (stripped by testdir.makepyfile) p = p.write(p.read() + "\n") # Rename pyproject.toml ¯\_(ツ)_/¯ testdir.run("mv", "test_include.pyproject.toml", "pyproject.toml") result = testdir.runpytest("--black") result.assert_outcomes(skipped=0, passed=1) def test_pytest_deprecation_warning(testdir): """Assert no deprecation warning is raised during test.""" p = testdir.makepyfile( """ def hello(): print("Hello, world!") """ ) # replace trailing newline (stripped by testdir.makepyfile) p = p.write(p.read() + "\n") result = testdir.runpytest("--black") result.assert_outcomes(passed=1) out = "\n".join(result.stdout.lines) assert "PytestUnknownMarkWarning" not in out ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734280852.0 pytest_black-0.6.0/tests/test_no_black.py0000644000076500000240000000040214727603224017711 0ustar00jaracostaff# -*- coding: utf-8 -*- import pytest pytestmark = pytest.mark.usefixtures('black_unavailable') def test_skipped_when_black_unavailable(testdir): testdir.makepyfile("") result = testdir.runpytest("--black") result.assert_outcomes(skipped=1) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734282561.0 pytest_black-0.6.0/tox.ini0000644000076500000240000000047714727606501014716 0ustar00jaracostaff# For more information about tox, see https://tox.readthedocs.io/en/latest/ [flake8] ignore = E501 [tox] envlist = py35,py36,py37,py38,py39,py310,flake8 [testenv] deps = pytest>=7.0 commands = pytest {posargs:tests} [testenv:flake8] skip_install = true deps = flake8 commands = flake8 pytest_black.py setup.py tests