| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import TYPE_CHECKING |
| 4 |
|
| 5 |
from tox.execute.util import shebang |
| 6 |
|
| 7 |
if TYPE_CHECKING: |
| 8 |
from pathlib import Path |
| 9 |
|
| 10 |
|
| 11 |
def test_shebang_found(tmp_path: Path) -> None: |
| 12 |
script_path = tmp_path / "a" |
| 13 |
script_path.write_text("#! /bin/python \t-c\t") |
| 14 |
assert shebang(str(script_path)) == ["/bin/python", "-c"] |
| 15 |
|
| 16 |
|
| 17 |
def test_shebang_file_missing(tmp_path: Path) -> None: |
| 18 |
script_path = tmp_path / "a" |
| 19 |
assert shebang(str(script_path)) is None |
| 20 |
|
| 21 |
|
| 22 |
def test_shebang_no_shebang(tmp_path: Path) -> None: |
| 23 |
script_path = tmp_path / "a" |
| 24 |
script_path.write_bytes(b"magic") |
| 25 |
assert shebang(str(script_path)) is None |
| 26 |
|
| 27 |
|
| 28 |
def test_shebang_non_utf8_file(tmp_path: Path) -> None: |
| 29 |
script_path, content = tmp_path / "a", b"#!" + bytearray.fromhex("c0") |
| 30 |
script_path.write_bytes(content) |
| 31 |
assert shebang(str(script_path)) is None |