-
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.
- Loading branch information
Showing
2 changed files
with
46 additions
and
18 deletions.
There are no files selected for viewing
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,8 +1,10 @@ | ||
import functools | ||
import shlex | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
import yaml | ||
from copier import run_copy | ||
from prompt_toolkit.validation import ValidationError | ||
|
||
|
@@ -34,28 +36,56 @@ def copy_project( | |
) | ||
|
||
|
||
def test_template(tmp_path: Path): | ||
project = tmp_path / "project" | ||
venv = tmp_path / "venv" | ||
copy_project(project) | ||
def run_pipe(cmd: str, cwd=None): | ||
sp = subprocess.run( | ||
shlex.split(cmd), | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
cwd=cwd, | ||
) | ||
output = sp.stdout.decode() | ||
assert sp.returncode == 0, output | ||
return output | ||
|
||
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_template(tmp_path: Path): | ||
project_path = tmp_path / "project" | ||
venv_path = tmp_path / "venv" | ||
copy_project(project_path) | ||
run = functools.partial(run_pipe, cwd=str(project_path)) | ||
run(f"python -m venv {venv_path}") | ||
run(f"{venv_path}/bin/python -m pip install -e .[dev]") | ||
run(f"{venv_path}/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") | ||
|
||
|
||
def test_example_repo_updates(tmp_path: Path): | ||
generated_path = tmp_path / "generated" | ||
example_url = ( | ||
"https://github.com/DiamondLightSource/python-copier-template-example.git" | ||
) | ||
example_path = tmp_path / "example" | ||
copy_project(generated_path) | ||
run_pipe(f"git clone {example_url} {example_path}") | ||
with open(example_path / ".copier-answers.yml") as f: | ||
d = yaml.safe_load(f) | ||
d["_src_path"] = str(TOP) | ||
with open(example_path / ".copier-answers.yml", "w") as f: | ||
yaml.dump(d, f) | ||
run = functools.partial(run_pipe, cwd=str(example_path)) | ||
run("git config user.email '[email protected]'") | ||
run("git config user.name 'Your Name'") | ||
run("git commit -am 'Update src'") | ||
run("copier update --trust --vcs-ref=HEAD -A") | ||
output = run( | ||
"diff -ur --exclude=.git --ignore-matching-lines='_commit: '" | ||
f" {generated_path} {example_path}" | ||
) | ||
assert not output, output | ||
|
||
|
||
# TODO: check that copier update python-copier-template-example matches generated |