(
tmp_path_factory: pytest.TempPathFactory,
)
| 275 | |
| 276 | |
| 277 | def test_new_version_changes_subdirectory( |
| 278 | tmp_path_factory: pytest.TempPathFactory, |
| 279 | ) -> None: |
| 280 | # Template in v3 changes from one subdirectory to another. |
| 281 | # Some file evolves also. Sub-project evolves separately. |
| 282 | # Sub-project is updated. Does that work as expected? |
| 283 | src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) |
| 284 | |
| 285 | # First, create the template with an initial subdirectory and README inside it |
| 286 | build_file_tree( |
| 287 | { |
| 288 | (src / "copier.yml"): "_subdirectory: subdir1\n", |
| 289 | (src / "subdir1" / "[[_copier_conf.answers_file]].tmpl"): ( |
| 290 | "[[_copier_answers|to_nice_yaml]]\n" |
| 291 | ), |
| 292 | (src / "subdir1" / "README.md"): "upstream version 1\n", |
| 293 | } |
| 294 | ) |
| 295 | with local.cwd(src): |
| 296 | git_init("hello template") |
| 297 | |
| 298 | # Generate the project a first time, assert the README exists |
| 299 | copier.run_copy(str(src), dst, defaults=True, overwrite=True) |
| 300 | assert (dst / "README.md").exists() |
| 301 | |
| 302 | # Start versioning the generated project |
| 303 | with local.cwd(dst): |
| 304 | git_init("hello project") |
| 305 | |
| 306 | # After first commit, change the README, commit again |
| 307 | Path("README.md").write_text("downstream version 1\n") |
| 308 | git("commit", "-am", "updated readme") |
| 309 | |
| 310 | # Now change the template |
| 311 | with local.cwd(src): |
| 312 | # Update the README |
| 313 | Path("subdir1", "README.md").write_text("upstream version 2\n") |
| 314 | |
| 315 | # Rename the subdirectory |
| 316 | Path("subdir1").rename("subdir2") |
| 317 | |
| 318 | # Update copier.yml to reflect this change |
| 319 | Path("copier.yml").write_text("_subdirectory: subdir2\n") |
| 320 | |
| 321 | # Commit the changes |
| 322 | git("add", ".", "-A") |
| 323 | git("commit", "-m", "changed from subdir1 to subdir2") |
| 324 | |
| 325 | # Finally, update the generated project |
| 326 | copier.run_copy( |
| 327 | str(src), dst, defaults=True, overwrite=True, skip_if_exists=["README.md"] |
| 328 | ) |
| 329 | |
| 330 | # Assert that the README still exists, and was NOT force updated |
| 331 | assert (dst / "README.md").exists() |
| 332 | assert (dst / "README.md").read_text() == "downstream version 1\n" |
| 333 | |
| 334 | # Also assert the subdirectories themselves were not rendered |
nothing calls this directly
no test coverage detected