MCPcopy
hub / github.com/pytest-dev/pytest / _makefile

Method _makefile

src/_pytest/pytester.py:759–794  ·  view source on GitHub ↗
(
        self,
        ext: str,
        lines: Sequence[Any | bytes],
        files: Mapping[str, _FileContent],
        encoding: str = "utf-8",
    )

Source from the content-addressed store, hash-verified

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

Callers 3

makefileMethod · 0.95
makepyfileMethod · 0.95
maketxtfileMethod · 0.95

Calls 6

SourceClass · 0.90
joinMethod · 0.80
insertMethod · 0.80
write_textMethod · 0.80
stripMethod · 0.80
mkdirMethod · 0.45

Tested by

no test coverage detected