From 3e5f7267dce7a73df87ea1c585eeb06f711a87c9 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Thu, 25 Jan 2024 14:20:15 +0000 Subject: [PATCH 1/3] Added test that example updates ok --- tests/test_example.py | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/tests/test_example.py b/tests/test_example.py index f5b8170a..2af332f2 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -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,23 +36,26 @@ 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): @@ -58,4 +63,26 @@ def test_bad_repo_name(tmp_path: Path): 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_pipe(f"git -C {example_path} commit -am 'Update src'") + run_pipe(f"copier update --trust --vcs-ref=HEAD -A {example_path}") + output = run_pipe( + "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 From 114543a314700549a1f901bf5f8d15be93b09158 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Thu, 25 Jan 2024 14:45:09 +0000 Subject: [PATCH 2/3] Fix git config --- tests/test_example.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_example.py b/tests/test_example.py index 2af332f2..c2bab029 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -76,9 +76,12 @@ def test_example_repo_updates(tmp_path: Path): d["_src_path"] = str(TOP) with open(example_path / ".copier-answers.yml", "w") as f: yaml.dump(d, f) - run_pipe(f"git -C {example_path} commit -am 'Update src'") - run_pipe(f"copier update --trust --vcs-ref=HEAD -A {example_path}") - output = run_pipe( + run = functools.partial(run_pipe, cwd=str(example_path)) + run("git config user.email 'you@example.com'") + 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}" ) From 60b898fd1fc45d42a2fe0c258bb36f8671e42eab Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Thu, 25 Jan 2024 15:07:55 +0000 Subject: [PATCH 3/3] Depth smaller --- .github/workflows/_tox.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/_tox.yml b/.github/workflows/_tox.yml index e1f58bfc..6e4b312c 100644 --- a/.github/workflows/_tox.yml +++ b/.github/workflows/_tox.yml @@ -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