MCPcopy
hub / github.com/copier-org/copier / test_new_version_uses_subdirectory

Function test_new_version_uses_subdirectory

tests/test_subdirectory.py:204–274  ·  view source on GitHub ↗
(
    tmp_path_factory: pytest.TempPathFactory,
    conflict: Literal["rej", "inline"],
    readme: str,
    expect_reject: bool,
)

Source from the content-addressed store, hash-verified

202 ],
203)
204def test_new_version_uses_subdirectory(
205 tmp_path_factory: pytest.TempPathFactory,
206 conflict: Literal["rej", "inline"],
207 readme: str,
208 expect_reject: bool,
209) -> None:
210 # Template in v1 doesn't have a _subdirectory;
211 # in v2 it moves all things into a subdir and adds that key to copier.yml.
212 # Some files change. Downstream project has evolved too. Does that work as expected?
213 src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
214
215 # First, create the template with an initial README
216 build_file_tree(
217 {
218 (src / "README.md"): "upstream version 1",
219 (src / "{{_copier_conf.answers_file}}.jinja"): (
220 "{{_copier_answers|to_nice_yaml}}"
221 ),
222 }
223 )
224 with local.cwd(src):
225 git_init("hello template")
226 git("tag", "v1")
227
228 # Generate the project a first time, assert the README exists
229 copier.run_copy(str(src), dst, defaults=True, overwrite=True)
230 assert (dst / "README.md").exists()
231 assert load_answersfile_data(dst).get("_commit") == "v1"
232
233 # Start versioning the generated project
234 with local.cwd(dst):
235 git_init("hello project")
236
237 # After first commit, change the README, commit again
238 Path("README.md").write_text("downstream version 1")
239 git("commit", "-am", "updated readme")
240
241 # Now change the template
242 with local.cwd(src):
243 # Update the README
244 Path("README.md").write_text("upstream version 2")
245
246 # Create a subdirectory, move files into it
247 subdir = Path("subdir")
248 subdir.mkdir()
249 Path("README.md").rename(subdir / "README.md")
250 Path("{{_copier_conf.answers_file}}.jinja").rename(
251 subdir / "{{_copier_conf.answers_file}}.jinja"
252 )
253
254 # Add the subdirectory option to copier.yml
255 Path("copier.yml").write_text(f"_subdirectory: {subdir}")
256
257 # Commit the changes
258 git("add", ".", "-A")
259 git("commit", "-m", "use a subdirectory now")
260 git("tag", "v2")
261

Callers

nothing calls this directly

Calls 5

load_answersfile_dataFunction · 0.90
build_file_treeFunction · 0.85
git_initFunction · 0.85
run_copyMethod · 0.80
run_updateMethod · 0.80

Tested by

no test coverage detected