(tmp_path_factory: pytest.TempPathFactory)
| 9 | |
| 10 | |
| 11 | def test_folder_loop(tmp_path_factory: pytest.TempPathFactory) -> None: |
| 12 | src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) |
| 13 | build_file_tree( |
| 14 | { |
| 15 | src / "copier.yml": "", |
| 16 | src |
| 17 | / "folder_loop" |
| 18 | / "{% yield item from strings %}{{ item }}{% endyield %}" |
| 19 | / "{{ item }}.txt.jinja": "Hello {{ item }}", |
| 20 | } |
| 21 | ) |
| 22 | with warnings.catch_warnings(): |
| 23 | warnings.simplefilter("error") |
| 24 | copier.run_copy( |
| 25 | str(src), |
| 26 | dst, |
| 27 | data={ |
| 28 | "strings": ["a", "b", "c"], |
| 29 | }, |
| 30 | defaults=True, |
| 31 | overwrite=True, |
| 32 | ) |
| 33 | |
| 34 | expected_files = [dst / f"folder_loop/{i}/{i}.txt" for i in ["a", "b", "c"]] |
| 35 | |
| 36 | for f in expected_files: |
| 37 | assert f.exists() |
| 38 | assert f.read_text() == f"Hello {f.parent.name}" |
| 39 | |
| 40 | all_files = [p for p in dst.rglob("*") if p.is_file()] |
| 41 | unexpected_files = set(all_files) - set(expected_files) |
| 42 | |
| 43 | assert not unexpected_files, f"Unexpected files found: {unexpected_files}" |
| 44 | |
| 45 | |
| 46 | def test_folder_loop_reports_path_when_yielded_part_rendering_fails( |
nothing calls this directly
no test coverage detected