(
self,
ext: str,
lines: Sequence[Union[Any, bytes]],
files: Dict[str, str],
encoding: str = "utf-8",
)
| 766 | os.chdir(self.path) |
| 767 | |
| 768 | def _makefile( |
| 769 | self, |
| 770 | ext: str, |
| 771 | lines: Sequence[Union[Any, bytes]], |
| 772 | files: Dict[str, str], |
| 773 | encoding: str = "utf-8", |
| 774 | ) -> Path: |
| 775 | items = list(files.items()) |
| 776 | |
| 777 | if ext and not ext.startswith("."): |
| 778 | raise ValueError( |
| 779 | f"pytester.makefile expects a file extension, try .{ext} instead of {ext}" |
| 780 | ) |
| 781 | |
| 782 | def to_text(s: Union[Any, bytes]) -> str: |
| 783 | return s.decode(encoding) if isinstance(s, bytes) else str(s) |
| 784 | |
| 785 | if lines: |
| 786 | source = "\n".join(to_text(x) for x in lines) |
| 787 | basename = self._name |
| 788 | items.insert(0, (basename, source)) |
| 789 | |
| 790 | ret = None |
| 791 | for basename, value in items: |
| 792 | p = self.path.joinpath(basename).with_suffix(ext) |
| 793 | p.parent.mkdir(parents=True, exist_ok=True) |
| 794 | source_ = Source(value) |
| 795 | source = "\n".join(to_text(line) for line in source_.lines) |
| 796 | p.write_text(source.strip(), encoding=encoding) |
| 797 | if ret is None: |
| 798 | ret = p |
| 799 | assert ret is not None |
| 800 | return ret |
| 801 | |
| 802 | def makefile(self, ext: str, *args: str, **kwargs: str) -> Path: |
| 803 | r"""Create new text file(s) in the test directory. |
no test coverage detected