Ensure it's possible to create one-off boilerplate files that are not managed during updates via `_exclude` using the `_copier_operation` context variable.
(
tmp_path_factory: pytest.TempPathFactory,
)
| 66 | |
| 67 | |
| 68 | def test_exclude_templating_with_operation( |
| 69 | tmp_path_factory: pytest.TempPathFactory, |
| 70 | ) -> None: |
| 71 | """ |
| 72 | Ensure it's possible to create one-off boilerplate files that are not |
| 73 | managed during updates via `_exclude` using the `_copier_operation` context |
| 74 | variable. |
| 75 | """ |
| 76 | src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) |
| 77 | |
| 78 | template = "{% if _copier_operation == 'update' %}copy-only{% endif %}" |
| 79 | with local.cwd(src): |
| 80 | build_file_tree( |
| 81 | { |
| 82 | "copier.yml": f'_exclude:\n - "{template}"', |
| 83 | "{{ _copier_conf.answers_file }}.jinja": "{{ _copier_answers|to_yaml }}", |
| 84 | "copy-only": "foo", |
| 85 | "copy-and-update": "foo", |
| 86 | } |
| 87 | ) |
| 88 | git_save(tag="1.0.0") |
| 89 | build_file_tree( |
| 90 | { |
| 91 | "copy-only": "bar", |
| 92 | "copy-and-update": "bar", |
| 93 | } |
| 94 | ) |
| 95 | git_save(tag="2.0.0") |
| 96 | copy_only = dst / "copy-only" |
| 97 | copy_and_update = dst / "copy-and-update" |
| 98 | |
| 99 | copier.run_copy(str(src), dst, defaults=True, overwrite=True, vcs_ref="1.0.0") |
| 100 | for file in (copy_only, copy_and_update): |
| 101 | assert file.exists() |
| 102 | assert file.read_text() == "foo" |
| 103 | |
| 104 | with local.cwd(dst): |
| 105 | git_save() |
| 106 | |
| 107 | copier.run_update(str(dst), overwrite=True) |
| 108 | assert copy_only.read_text() == "foo" |
| 109 | assert copy_and_update.read_text() == "bar" |
| 110 | |
| 111 | |
| 112 | def test_exclude_templating_with_operation_added_in_new_version( |
nothing calls this directly
no test coverage detected