Skip to content

Commit

Permalink
Test local (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl authored Jan 25, 2024
2 parents 956744d + 60b898f commit a090630
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- run: find
fetch-depth: 0

- name: Setup python
uses: actions/setup-python@v5
Expand Down
60 changes: 45 additions & 15 deletions tests/test_example.py
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

Expand Down Expand Up @@ -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

0 comments on commit a090630

Please sign in to comment.