| 19 | |
| 20 | @pytest.mark.skipif(WINDOWS, reason="This test checks posix expectations of a script.") |
| 21 | def test_is_script_posix(tmpdir): |
| 22 | # type: (Tempdir) -> None |
| 23 | |
| 24 | exe = tmpdir.join("exe") |
| 25 | |
| 26 | touch(exe) |
| 27 | assert not is_exe(exe) |
| 28 | assert not is_script(exe, pattern=None, check_executable=True) |
| 29 | |
| 30 | chmod_plus_x(exe) |
| 31 | assert is_exe(exe) |
| 32 | assert not is_script(exe, pattern=None, check_executable=True) |
| 33 | |
| 34 | with open(exe, "wb") as fp: |
| 35 | fp.write(bytearray([0xCA, 0xFE, 0xBA, 0xBE])) |
| 36 | assert not is_script(fp.name, pattern=None, check_executable=True) |
| 37 | |
| 38 | with open(exe, "wb") as fp: |
| 39 | fp.write(b"#!/mystery\n") |
| 40 | fp.write(bytearray([0xCA, 0xFE, 0xBA, 0xBE])) |
| 41 | assert is_script(exe, pattern=None, check_executable=True) |
| 42 | assert is_script(exe, pattern=br"^/mystery", check_executable=True) |
| 43 | assert not is_script(exe, pattern=br"^python", check_executable=True) |
| 44 | |
| 45 | os.chmod(exe, 0o665) |
| 46 | assert is_script(exe, pattern=None, check_executable=False) |
| 47 | assert not is_script(exe, pattern=None, check_executable=True) |
| 48 | assert not is_exe(exe) |
| 49 | |
| 50 | |
| 51 | def test_is_python_script(tmpdir): |