(
max_shebang_length, # type: int
*extra_args # type: str
)
| 538 | python_exe = sys.executable |
| 539 | |
| 540 | def execute_script( |
| 541 | max_shebang_length, # type: int |
| 542 | *extra_args # type: str |
| 543 | ): |
| 544 | # type: (...) -> str |
| 545 | with open(os.path.join(str(tmpdir), "script.py"), "w") as fp: |
| 546 | fp.write( |
| 547 | dedent( |
| 548 | """\ |
| 549 | {shebang} |
| 550 | |
| 551 | import json |
| 552 | import sys |
| 553 | |
| 554 | |
| 555 | with open(sys.argv[0]) as fp: |
| 556 | json.dump(dict(shebang=fp.readline(), argv=sys.argv), sys.stdout) |
| 557 | """ |
| 558 | ).format( |
| 559 | shebang=create_shebang( |
| 560 | python_exe=python_exe, max_shebang_length=max_shebang_length |
| 561 | ) |
| 562 | ) |
| 563 | ) |
| 564 | chmod_plus_x(fp.name) |
| 565 | result = json.loads( |
| 566 | subprocess.check_output(args=[fp.name] + list(extra_args)).decode("utf-8") |
| 567 | ) |
| 568 | assert [fp.name] + list(extra_args) == result["argv"] |
| 569 | return cast(str, result["shebang"]) |
| 570 | |
| 571 | assert "#!{python_exe}\n".format(python_exe=python_exe) == execute_script(len(python_exe) * 2) |
| 572 | assert "#!{python_exe}\n".format(python_exe=python_exe) == execute_script( |
no test coverage detected