Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use assignment expression #6

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions pytest_copie/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ def copie(self, extra_context: Any = None, template: Any = None) -> Result:
@pytest.fixture
def _copier_config_file(tmp_path_factory):
"""Return a temporary copier config file."""
# create a user from the tmp_path_factory fixture
user_dir = tmp_path_factory.mktemp("user_dir")
config_file = user_dir / "config"

copier_dir = user_dir / "copier"
copier_dir.mkdir()
replay_dir = user_dir / "replay_dir"
replay_dir.mkdir()
# create the different folders and files
(copier_dir := user_dir / "copier").mkdir()
(replay_dir := user_dir / "replay_dir").mkdir()

# set up the configuration parameters in a config file
config = {
"copier_dir": str(copier_dir),
"replay_dir": str(replay_dir),
}

with config_file.open("w") as f:
yaml.dump(config, f, Dumper=yaml.Dumper)
(config_file := user_dir / "config").write_text(yaml.dump(config))

return config_file

Expand All @@ -125,12 +125,10 @@ def copie(request, tmp_path: Path, _copier_config_file: Path) -> Generator:
res = copie.copie(extra_context={"project_name": "foo"})
"""
template_dir = Path(".")
output_dir = tmp_path / "copie"
output_dir.mkdir()
(output_dir := tmp_path / "copie").mkdir()

def output_factory(dirname: str) -> Path:
new_dir = output_dir / dirname
new_dir.mkdir()
(new_dir := output_dir / dirname).mkdir()
return new_dir

yield Copie(template_dir, output_factory, _copier_config_file)
Expand Down
15 changes: 7 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@
@pytest.fixture
def copier_template(tmpdir) -> Path:
"""Create a default template for the copier project generation."""
template_dir = tmpdir / "copie-template"
template_dir.mkdir()
template_file = template_dir / "copier.yaml"
# set up the configuration parameters
template_config = {
"repo_name": {"type": "str", "default": "foobar"},
"short_description": {
"type": "str",
"default": "Test Project",
},
}
template_file.write_text(yaml.dump(template_config))

# content of a fake readme file
template_readme = [
r"{{ repo_name }}",
"{% for _ in repo_name %}={% endfor %}",
r"{{ short_description }}",
]

repo_dir = template_dir / r"{{ repo_name }}"
repo_dir.mkdir()
readm_file = repo_dir / "README.rst"
readm_file.write_text("\n".join(template_readme))
# create all the folders and files
(template_dir := tmpdir / "copie-template").mkdir()
(template_dir / "copier.yaml").write_text(yaml.dump(template_config))
(repo_dir := template_dir / r"{{ repo_name }}").mkdir()
(repo_dir / "README.rst").write_text("\n".join(template_readme))

return template_dir

Expand Down
Loading