File: test_execute_util.py

package info (click to toggle)
tox 4.25.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,032 kB
  • sloc: python: 18,531; sh: 22; makefile: 14
file content (31 lines) | stat: -rw-r--r-- 874 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

from typing import TYPE_CHECKING

from tox.execute.util import shebang

if TYPE_CHECKING:
    from pathlib import Path


def test_shebang_found(tmp_path: Path) -> None:
    script_path = tmp_path / "a"
    script_path.write_text("#!  /bin/python \t-c\t")
    assert shebang(str(script_path)) == ["/bin/python", "-c"]


def test_shebang_file_missing(tmp_path: Path) -> None:
    script_path = tmp_path / "a"
    assert shebang(str(script_path)) is None


def test_shebang_no_shebang(tmp_path: Path) -> None:
    script_path = tmp_path / "a"
    script_path.write_bytes(b"magic")
    assert shebang(str(script_path)) is None


def test_shebang_non_utf8_file(tmp_path: Path) -> None:
    script_path, content = tmp_path / "a", b"#!" + bytearray.fromhex("c0")
    script_path.write_bytes(content)
    assert shebang(str(script_path)) is None