Skip to content

Commit

Permalink
Add: Add new testing function for writing content to a temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks committed Aug 9, 2022
1 parent 4220c1c commit 045d9ac
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import tempfile
from contextlib import contextmanager
from pathlib import Path
from typing import Generator
from typing import Generator, Optional

from autohooks.utils import exec_git

Expand Down Expand Up @@ -51,3 +51,11 @@ def tempgitdir() -> Generator[Path, None, None]:
yield temp_path

temp_dir.cleanup()


@contextmanager
def testfile(content: str, *, name: Optional[str] = "test.toml") -> Path:
with tempdir() as tmp_dir:
test_file = tmp_dir / name
test_file.write_text(content, encoding="utf8")
yield test_file

0 comments on commit 045d9ac

Please sign in to comment.