Files
cibuildwheel/test/test_projects/base.py
T
pre-commit-ci[bot]pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Grzegorz BokotaHenry Schreiner
c72e27e65a [pre-commit.ci] pre-commit autoupdate (#1423)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.249 → v0.0.253](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.249...v0.0.253)

* fix ruff warnings

* chore: fix pylint warnings

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-02-28 08:43:58 -05:00

45 lines
1.3 KiB
Python

from __future__ import annotations
from pathlib import Path
from typing import Any, Dict, Union
import jinja2
FilesDict = Dict[str, Union[str, jinja2.Template]]
TemplateContext = Dict[str, Any]
class TestProject:
"""
An object that represents a project that can be built by cibuildwheel.
Can be manipulated in tests by changing `files` and `template_context`.
Write out to the filesystem using `generate`.
"""
__test__ = False # Have pytest ignore this class on `from .test_projects import TestProject`
files: FilesDict
template_context: TemplateContext
def __init__(self):
self.files = {}
self.template_context = {}
def generate(self, path: Path):
for filename, content in self.files.items():
file_path = path / filename
file_path.parent.mkdir(parents=True, exist_ok=True)
with file_path.open("w", encoding="utf8") as f:
if isinstance(content, jinja2.Template):
content = content.render(self.template_context) # noqa: PLW2901
f.write(content)
def copy(self):
other = TestProject()
other.files = self.files.copy()
other.template_context = self.template_context.copy()
return other