Skip to content

Commit

Permalink
Change tests to be self contained (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl authored Jan 25, 2024
2 parents d887b49 + fa6f5c0 commit 956744d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 25 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# This file is for use as a devcontainer
#
# The devcontainer should use the developer target and run as root with podman
# or docker with user namespaces.
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} as developer
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
graphviz \
&& rm -rf /var/lib/apt/lists/*
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
ENV PATH=/venv/bin:$PATH
4 changes: 2 additions & 2 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repo_name:
help: Name of the repository
default: "{{ package_name | replace('_', '-') }}"
validator: >-
{% if not (repo_name | regex_search('^[a-zA-Z][a-zA-Z_\-0-9]+$')) %}
{% if not (repo_name | regex_search('^[a-zA-Z][a-zA-Z_\\-0-9]+$')) %}
{{ repo_name }} is not a valid repo name
{% endif %}
Expand Down Expand Up @@ -88,4 +88,4 @@ docs_url:
when: false

_tasks:
- "git init --initial-branch=main"
- "git init --initial-branch=main"
2 changes: 0 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ sphinxcontrib-serializinghtml==1.1.10
tornado==6.4
tox==3.28.0
tox-direct==0.4
treecomp==1.0.0
typer==0.9.0
typing-extensions==4.9.0
urllib3==2.1.0
virtualenv==20.25.0
Expand Down
1 change: 0 additions & 1 deletion example
Submodule example deleted from 24c2b7
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "python-copier-template"
version = "0.0"
dynamic = ["version"]

[project.optional-dependencies]
dev = [
Expand All @@ -15,7 +19,6 @@ dev = [
"sphinx-copybutton",
"sphinx-design",
"tox-direct",
"treecomp",
]

[tool.pytest.ini_options]
Expand Down
2 changes: 1 addition & 1 deletion template/README.rst.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{package_name}}
===========================
=============================================================================

|code_ci| |docs_ci| |coverage| |pypi_version| |license|

Expand Down
61 changes: 48 additions & 13 deletions tests/test_example.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
import shutil
import shlex
import subprocess
from pathlib import Path

import treecomp
import yaml
import pytest
from copier import run_copy
from prompt_toolkit.validation import ValidationError

TOP = Path(__file__).absolute().parent.parent
INPUT = TOP / "example"
OUTPUT = TOP / "build" / "example"


def test_template():
shutil.rmtree(OUTPUT, ignore_errors=True)
answers = yaml.safe_load((INPUT / ".copier-answers.yml").read_text())
def copy_project(
project_path: Path,
author_email="[email protected]",
author_name="Tom Cobb",
component_owner="group:default/sscc",
description="An expanded python-copier-template with all the options",
distribution_name="dls-python-copier-template-example",
docker=True,
docs_type="sphinx",
git_platform="github.com",
github_org="DiamondLightSource",
package_name="python_copier_template_example",
repo_name="python-copier-template-example",
):
answers = locals()
answers.pop("project_path")
run_copy(
src_path=str(TOP),
dst_path=OUTPUT,
dst_path=project_path,
data=answers,
vcs_ref="HEAD",
unsafe=True,
)
#
comparison = treecomp.diff_file_trees(INPUT, OUTPUT, ignore=[".copier-answers.yml"])
if comparison.diffs:
raise AssertionError(str(comparison))


def test_template(tmp_path: Path):
project = tmp_path / "project"
venv = tmp_path / "venv"
copy_project(project)

def run(cmd: str):
sp = subprocess.run(
shlex.split(cmd),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=str(project),
)
assert sp.returncode == 0, sp.stdout.decode()

run(f"python -m venv {venv}")
run(f"{venv}/bin/python -m pip install -e .[dev]")
run(f"{venv}/bin/tox -p")


def test_bad_repo_name(tmp_path: Path):
with pytest.raises(ValidationError, match="bad:thing is not a valid repo name"):
copy_project(tmp_path, repo_name="bad:thing")


# TODO: check that copier update python-copier-template-example matches generated

0 comments on commit 956744d

Please sign in to comment.