|
35 | 35 | from pip._internal.models.target_python import TargetPython |
36 | 36 | from pip._internal.network.session import PipSession |
37 | 37 |
|
| 38 | +from tests.lib.filesystem import create_file |
38 | 39 | from tests.lib.venv import VirtualEnvironment |
39 | 40 | from tests.lib.wheel import make_wheel |
40 | 41 |
|
|
51 | 52 | _FilesState = dict[str, Union[FoundDir, FoundFile]] |
52 | 53 |
|
53 | 54 |
|
54 | | -def create_file(path: str, contents: str | None = None) -> None: |
55 | | - """Create a file on the path, with the given contents""" |
56 | | - from pip._internal.utils.misc import ensure_dir |
57 | | - |
58 | | - ensure_dir(os.path.dirname(path)) |
59 | | - with open(path, "w") as f: |
60 | | - if contents is not None: |
61 | | - f.write(contents) |
62 | | - else: |
63 | | - f.write("\n") |
64 | | - |
65 | | - |
66 | 55 | def make_test_search_scope( |
67 | 56 | find_links: list[str] | None = None, |
68 | 57 | index_urls: list[str] | None = None, |
@@ -769,6 +758,12 @@ def assert_installed_editable(self, dist_name: str) -> None: |
769 | 758 | and x.get("editable_project_location") |
770 | 759 | ) |
771 | 760 |
|
| 761 | + def temporary_file(self, filename: str, contents: str) -> pathlib.Path: |
| 762 | + """Create a temporary file with the given filename and contents.""" |
| 763 | + path = self.scratch_path.joinpath(filename) |
| 764 | + create_file(path, contents) |
| 765 | + return path |
| 766 | + |
772 | 767 |
|
773 | 768 | # FIXME ScriptTest does something similar, but only within a single |
774 | 769 | # ProcResult; this generalizes it so states can be compared across |
|
0 commit comments