Skip to content

Commit

Permalink
chore(options): Remove pytest and black #103 (#122)
Browse files Browse the repository at this point in the history
Pytest and Black are used by default in pre-commit.

closes #103
  • Loading branch information
imAsparky committed Sep 23, 2021
1 parent 5b64753 commit 85a729f
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 111 deletions.
2 changes: 0 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"project_short_description": "Python 3 Package Boilerplate contains all the boilerplate you need to create a Python package.",
"pypi_username": "{{ cookiecutter.github_username }}",
"version": "0.1.0",
"use_pytest": "n",
"use_black": "n",
"add_pyup_badge": "n",
"command_line_interface": ["Click", "Argparse", "No command-line interface"],
"create_author_file": "y",
Expand Down
74 changes: 10 additions & 64 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import subprocess # nosec
import sys
from contextlib import contextmanager
import pytest
from click.testing import CliRunner
from cookiecutter.utils import rmtree

Expand Down Expand Up @@ -209,15 +208,16 @@ def test_bake_without_author_file(cookies):
assert "AUTHORS.rst" not in manifest_file.read()


def test_make_help(cookies):
"""
Test make help.
"""
with bake_in_temp_dir(cookies) as result:
# The supplied Makefile does not support win32
if sys.platform != "win32":
output = check_output_inside_dir("make help", str(result.project))
assert b"check code coverage quickly with the default Python" in output
# This test not deleted for future reference...
# def test_make_help(cookies):
# """
# Test make help.
# """
# with bake_in_temp_dir(cookies) as result:
# # The supplied Makefile does not support win32
# if sys.platform != "win32":
# output = check_output_inside_dir("make help", str(result.project))
# assert b"check code coverage quickly with the default Python" in output


def test_bake_selecting_license(cookies):
Expand Down Expand Up @@ -253,44 +253,6 @@ def test_bake_not_open_source(cookies):
assert "License" not in result.project.join("README.rst").read()


def test_using_pytest(cookies):
"""
Test cookiecutter created the package using pytest.
.. note::
A reminder if anything stops working. This line is commented out due to
W0106: Expression "run_inside_dir('python setup.py test',
str(result.project)) == 0" is assigned to nothing
(expression-not-assigned) pre-commit pylint error.
"""
with bake_in_temp_dir(
cookies,
extra_context={"use_pytest": "y"},
) as result:
assert result.project.isdir()
test_file_path = result.project.join(
"tests/test_python_3_package_boilerplate.py"
)
lines = test_file_path.readlines()
assert "import pytest" in "".join(lines)
# Test the new pytest target
# run_inside_dir('pytest', str(result.project)) == 0


def test_not_using_pytest(cookies):
"""
Test cookiecutter created the package without using pytest.
"""
with bake_in_temp_dir(cookies) as result:
assert result.project.isdir()
test_file_path = result.project.join(
"tests/test_python_3_package_boilerplate.py"
)
lines = test_file_path.readlines()
assert "import unittest" in "".join(lines)
assert "import pytest" not in "".join(lines)


def test_bake_with_no_console_script(cookies):
"""
Test cookiecutter created the package without console script files.
Expand Down Expand Up @@ -384,22 +346,6 @@ def test_bake_with_argparse_console_script_cli(cookies):
assert "Show this message" in help_result.output


@pytest.mark.parametrize("use_black,expected", [("y", True), ("n", False)])
def test_black(cookies, use_black, expected):
"""
Test cookiecutter created the package with black configured.
"""
with bake_in_temp_dir(
cookies,
extra_context={"use_black": use_black},
) as result:
assert result.project.isdir()
requirements_path = result.project.join("requirements_dev.txt")
assert ("black" in requirements_path.read()) is expected
makefile_path = result.project.join("Makefile")
assert ("black --check" in makefile_path.read()) is expected


def test_bake_with_conventional_commits_message(cookies):
"""
Test cookiecutter created the package with a conventional commits message.
Expand Down
6 changes: 3 additions & 3 deletions {{cookiecutter.git_project_name}}/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ Tips

To run a subset of tests::

{% if cookiecutter.use_pytest == 'y' -%}

$ pytest tests.test_{{ cookiecutter.project_slug }}
{% else %}

$ python -m unittest tests.test_{{ cookiecutter.project_slug }}
{%- endif %}


Deploying
---------
Expand Down
21 changes: 0 additions & 21 deletions {{cookiecutter.git_project_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,11 @@ clean-test: ## remove test and coverage artifacts
lint/flake8: ## check style with flake8
flake8 {{ cookiecutter.project_slug }} tests

{%- if cookiecutter.use_black == 'y' %}
lint/black: ## check style with black
black --check {{ cookiecutter.project_slug }} tests
{%- endif %}

lint: lint/flake8{%- if cookiecutter.use_black == 'y' %} lint/black{%- endif %} ## check style

test: ## run tests quickly with the default Python
{%- if cookiecutter.use_pytest == 'y' %}
pytest
{%- else %}
python setup.py test
{%- endif %}

test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
{%- if cookiecutter.use_pytest == 'y' %}
coverage run --source {{ cookiecutter.project_slug }} -m pytest
{%- else %}
coverage run --source {{ cookiecutter.project_slug }} setup.py test
{%- endif %}
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/{{ cookiecutter.project_slug }}.rst
Expand Down
4 changes: 0 additions & 4 deletions {{cookiecutter.git_project_name}}/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@ watchdog==2.1.5

{% if cookiecutter.command_line_interface|lower == 'click' -%}
Click==8.0.1{% endif %}
{% if cookiecutter.use_pytest == 'y' -%}
pytest==6.2.4{% endif %}
{% if cookiecutter.use_black == 'y' -%}
black==21.7b0{% endif %}
5 changes: 0 additions & 5 deletions {{cookiecutter.git_project_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ universal = 1

[flake8]
exclude = docs

{%- if cookiecutter.use_pytest == 'y' %}
[tool:pytest]
collect_ignore = ['setup.py']
{%- endif %}
2 changes: 0 additions & 2 deletions {{cookiecutter.git_project_name}}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

requirements = [{%- if cookiecutter.command_line_interface|lower == 'click' %}'Click>=7.0',{%- endif %} ]

test_requirements = [{%- if cookiecutter.use_pytest == 'y' %}'pytest>=3',{%- endif %} ]

{%- set license_classifiers = {
'MIT license': 'License :: OSI Approved :: MIT License',
'BSD license': 'License :: OSI Approved :: BSD License',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@

"""Tests for `{{ cookiecutter.project_slug }}` package."""

{% if cookiecutter.use_pytest == 'y' -%}
import pytest

{% else %}
import unittest

{%- endif %}
{%- if cookiecutter.command_line_interface|lower == 'click' %}

from click.testing import CliRunner

{%- endif %}

from {{cookiecutter.project_slug}} import {{ cookiecutter.project_slug }}

{%- if cookiecutter.command_line_interface|lower == 'click' %}

from {{cookiecutter.project_slug}} import cli

{%- endif %}

{%- if cookiecutter.use_pytest == 'y' %}


@pytest.fixture
def response():
"""Sample pytest fixture.
Expand Down Expand Up @@ -51,7 +45,7 @@ def test_command_line_interface():
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output
{%- endif %}
{%- else %}



class Test{{ cookiecutter.project_slug|title }}(unittest.TestCase):
Expand All @@ -77,4 +71,3 @@ def test_command_line_interface(self):
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output
{%- endif %}
{%- endif %}

0 comments on commit 85a729f

Please sign in to comment.