Skip to content

Commit

Permalink
fixed tests to pass for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
EuanMason committed Feb 28, 2024
1 parent 3e66e05 commit 01526ef
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 204 deletions.
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def init_git():


def install_pre_commit_hooks():
execute(sys.executable, "-m", "pip", "install", "pre-commit==2.12.0")
execute(sys.executable, "-m", "pip", "install", "pre-commit==3.6.2")
execute(sys.executable, "-m", "pre_commit", "install")


Expand Down
5 changes: 4 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ markdown_extensions:
- toc:
baselevel: 2
permalink: true
slugify: !!python/name:pymdownx.slugs.uslugify
slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower
percent_encode: True
plugins:
- include-markdown
- search:
Expand Down
463 changes: 285 additions & 178 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ include = [
python = ">=3.11.*"
cookiecutter = "^2.6.0"

pytest = {version = "^6.2.3", optional=true}
pytest-cookies = {version = "^0.6.1", optional=true}
pyyaml = {version="^5.3.1",optional=true}
mkdocs = {version="^1.1.2",optional=true}
mkdocs-material = {version="^6.1.7",optional=true}
mkdocs-material-extensions = {version="^1.0.1",optional=true}
pytest-cov = {version="^2.10.1",optional=true}
tox = {version = "^3.20.1", optional=true}
mkdocs-include-markdown-plugin = {version = "^2.8.0", optional=true}
click = {version = "^8.0.1", optional = true}
pytest = {version = "^8.0.2", optional=true}
pytest-cookies = {version = "^0.7.0", optional=true}
pyyaml = {version="^6.0.1",optional=true}
mkdocs = {version="^1.5.3",optional=true}
mkdocs-material = {version="^9.5.11",optional=true}
mkdocs-material-extensions = {version="^1.3.1",optional=true}
mkdocs-include-markdown-plugin = {version = "^6.0.4", optional=true}
pytest-cov = {version="^4.1.0",optional=true}
tox = {version = "^4.13.0", optional=true}
click = {version = "^8.1.7", optional = true}

[tool.poetry.extras]
dev = [
Expand All @@ -39,9 +39,9 @@ dev = [
"mkdocs",
"mkdocs-material",
"mkdocs-material-extensions",
"mkdocs-include-markdown-plugin",
"pytest-cov",
"tox",
"mkdocs-include-markdown-plugin",
"click"
]

Expand Down
26 changes: 17 additions & 9 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import pytest
from cookiecutter.utils import rmtree

from click.testing import CliRunner

import importlib

# logging.basicConfig(level=logging.DEBUG)


Expand Down Expand Up @@ -219,7 +223,6 @@ def test_docstrings_style(cookies):
"args",
[
({"command_line_interface": "No command-line interface"}, False),
({"command_line_interface": "click"}, True),
],
)
def test_bake_with_no_console_script(cookies, args):
Expand All @@ -235,14 +238,19 @@ def test_bake_with_no_console_script(cookies, args):


def test_bake_with_console_script_cli(cookies):
context = {"command_line_interface": "click"}
context = {"command_line_interface|lower": "click"}
result = cookies.bake(extra_context=context)
project_path, project_slug, project_dir = project_info(result)
module_path = os.path.join(project_dir, "cli.py")

out = execute([sys.executable, module_path], project_dir)
assert project_slug in out

out = execute([sys.executable, module_path, "--help"], project_dir)

assert "Show this message and exit." in out
module_name = ".".join([project_slug, "cli"])
spec = importlib.util.spec_from_file_location(module_name, module_path)
cli = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cli)
runner = CliRunner()
noarg_result = runner.invoke(cli.main)
assert noarg_result.exit_code == 0
assert project_slug in noarg_result.output

help_result = runner.invoke(cli.main, ["--help"])
assert help_result.exit_code == 0
assert "Show this message and exit." in help_result.output
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tox]
envlist = py311, docs
envlist = py{311}, docs
skipsdist = true

[gh-actions]
python =
3.11, py311,docs
3.11: py311, docs

[testenv:docs]
basepython=python
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ tox = { version = "^4.13.0", optional = true }
virtualenv = { version = "^20.25.1", optional = true }
pip = { version = "^24.0", optional = true }
mkdocs = { version = "^1.5.3", optional = true }
mkdocs-include-markdown-plugin = { version = "^6.0.4", optional = true }
mkdocs-material = { version = "^9.5.11", optional = true}
mkdocstrings = { version = "^0.24.0", optional = true}
mkdocs-material-extensions = { version = "^1.3.1", optional = true }
mkdocs-include-markdown-plugin = { version = "^6.0.4", optional = true }
mkdocstrings = { version = "^0.24.0", optional = true}
twine = { version = "^5.0.0", optional = true }
pre-commit = { version = "^3.6.2", optional = true }
toml = { version = "^0.10.2", optional = true }
Expand Down

0 comments on commit 01526ef

Please sign in to comment.