(self, name: str, code: str)
| 29 | |
| 30 | @contextlib.contextmanager |
| 31 | def mock_program_with_code(self, name: str, code: str): |
| 32 | import textwrap |
| 33 | |
| 34 | content = f"#!{sys.executable}\n{textwrap.dedent(code)}" |
| 35 | program_path = self.directory / name |
| 36 | assert not program_path.is_file() |
| 37 | |
| 38 | with open(program_path, "w") as f: |
| 39 | f.write(content) |
| 40 | os.chmod(program_path, 0o700) |
| 41 | |
| 42 | yield program_path |
| 43 | |
| 44 | os.unlink(program_path) |
no outgoing calls