-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change tests to be self contained (#26)
- Loading branch information
Showing
8 changed files
with
65 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule example
deleted from
24c2b7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |