Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmgaudecker committed Dec 19, 2023
1 parent eda143b commit 1af30db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
5 changes: 4 additions & 1 deletion docs/source/getting_started/cookiecutter_dialogue.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
**github_email** -- The email linked to your GitHub account (only relevant for your
local machine, will be different for coauthors / other group members).

**git_remote_url** -- Paste your remote URL here if applicable.
**git_remote_url** -- Paste your GIT remote URL here if applicable. Must be of the
form `https://github.com/<user or organisation name>/<repo name>`. I.e., a
`https://`-link and without `.git` at the end. This is required because it will be
used in multiple places. Need not be github.

**make_initial_commit** -- Whether we should make the first commit for you.

Expand Down
9 changes: 8 additions & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Hooks which are executed after the template is rendered."""
from __future__ import annotations

import re
import shutil
import subprocess
import warnings
Expand Down Expand Up @@ -64,8 +65,14 @@ def main() -> None:
)

if "{{ cookiecutter.git_remote_url }}":
assert re.match(r"https://(?!.+\.git$)", "{{ cookiecutter.git_remote_url }}"), (

Check warning on line 68 in hooks/post_gen_project.py

View check run for this annotation

Codecov / codecov/patch

hooks/post_gen_project.py#L68

Added line #L68 was not covered by tests
"The git remote url does not follow the form "
"`https://github.com/<user or organisation name>/<repo name>`. "
"I.e., a `https://`-link and without `.git` at the end. This is required "
"because it will be used in multiple places. Need not be github."
)
subprocess.call(
["git", "remote", "add", "origin", "{{ cookiecutter.git_remote_url }}"],
["git", "remote", "add", "origin", "{{ cookiecutter.git_remote_url }}.git"],
)

if "{{ cookiecutter.make_initial_commit }}" == "yes":
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ exclude = [

[tool.ruff.per-file-ignores]
"tests/*" = ["S101", "ANN", "D100", "D103"]
"hooks/post_gen_project.py" = ["C901", "PLR0912", "T201"]
"hooks/post_gen_project.py" = ["C901", "PLR0912", "S101", "T201"]
"docs/source/conf.py" = ["DTZ005", "D100"]
"docs/source/__init__.py" = ["D104"]
"hooks/__init__.py" = ["D104"]

[tool.ruff.pydocstyle]
convention = "numpy"


[tool.nbqa.config]
black = "pyproject.toml"

[tool.nbqa.mutate]
black = 1


[tool.pytest.ini_options]
filterwarnings = []
addopts = ["--doctest-modules"]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ def test_invalid_python_version(cookies):
assert str(result.exception).startswith("Hook script failed")


def test_valid_non_empty_git_remote_url(cookies):
result = cookies.bake(extra_context={"git_remote_url": "https://a.b/x/y"})
assert result.exit_code == 0
assert result.exception is None


def test_invalid_git_remote_url_not_https(cookies):
result = cookies.bake(extra_context={"git_remote_url": "ssh://a.b/x/y"})
assert result.exception is not None


def test_invalid_git_remote_url_ends_with_git(cookies):
result = cookies.bake(extra_context={"git_remote_url": "https://a.b/x/y.git"})
assert result.exception is not None


@pytest.mark.end_to_end()
def test_bake_project(cookies):
major, minor = sys.version_info[:2]
Expand Down
15 changes: 8 additions & 7 deletions {{cookiecutter.project_slug}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = {{ cookiecutter.project_slug }}
description = {{ cookiecutter.project_name }}
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}
long_description_content_type = text/markdown{% if cookiecutter.git_remote_url != '' %}
url = {{ cookiecutter.git_remote_url }}{% endif %}
author = {{ cookiecutter.author }}
author_email = {{ cookiecutter.email }}
license = {{ cookiecutter.open_source_license }}
Expand All @@ -16,12 +16,13 @@ classifiers =
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3 :: Only{% if cookiecutter.git_remote_url != '' %}
project_urls =
Changelog = https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}
Documentation = https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}
Github = https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}
Tracker = https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/issues
Changelog = {{ cookiecutter.git_remote_url }}
Documentation = {{ cookiecutter.git_remote_url }}
Github = {{ cookiecutter.git_remote_url }}
Tracker = {{ cookiecutter.git_remote_url }}/issues
{% endif %}

[options]
packages = find:
Expand Down

0 comments on commit 1af30db

Please sign in to comment.