Пример #1
0
def test_tool_plugin_is_valid_executable_valid():
    """Test that is_valid_executable returns True for executable files."""

    # Create an executable file
    tmp_file = tempfile.NamedTemporaryFile()
    st = os.stat(tmp_file.name)
    os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)
    assert ToolPlugin.is_valid_executable(tmp_file.name)
Пример #2
0
def test_tool_plugin_is_valid_executable_no_exe_flag():
    """
    Test that is_valid_executable returns False for a non-executable file.

    NOTE: any platform which doesn't have executable bits should skip
    this test, since the os.stat call will always say that the file is
    executable
    """

    if sys.platform.startswith('win32'):
        pytest.skip("windows doesn't have executable flags")
    # Create a file
    tmp_file = tempfile.NamedTemporaryFile()
    assert not ToolPlugin.is_valid_executable(tmp_file.name)
Пример #3
0
def test_tool_plugin_is_valid_executable_noextension_pathext(monkeypatch):
    """
    Test that is_valid_executable works correctly with no extension and a set PATHEXT

    is_valid_executable should find the file as created.
    """

    # Monkeypatch the environment to set
    monkeypatch.setenv("PATHEXT", ".exe;.bat")

    # Make a temporary executable
    with tempfile.NamedTemporaryFile() as tmp_file:
        st = os.stat(tmp_file.name)
        os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)
        assert ToolPlugin.is_valid_executable(tmp_file.name)
Пример #4
0
def test_tool_plugin_is_valid_executable_extension_nopathext(monkeypatch):
    """
    Test that is_valid_executable works correctly with .exe appended, no PATHEXT

    is_valid_executable should find the file as created.
    """

    # Monkeypatch the environment to clear PATHEXT
    monkeypatch.delenv("PATHEXT", raising=False)

    # Make a temporary executable
    with tempfile.NamedTemporaryFile(suffix=".exe") as tmp_file:
        st = os.stat(tmp_file.name)
        os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)
        assert ToolPlugin.is_valid_executable(tmp_file.name)
Пример #5
0
def test_tool_plugin_is_valid_executable_wrongextension_pathext(monkeypatch):
    """
    Test that is_valid_executable works correctly with a set PATHEXT and a non-PATHEXT extension.

    is_valid_executable should NOT find the file.
    """

    # Monkeypatch the environment to set
    monkeypatch.setenv("PATHEXT", ".exe;.bat")

    # Make a temporary executable
    with tempfile.NamedTemporaryFile(suffix=".potato") as tmp_file:
        st = os.stat(tmp_file.name)
        os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)
        # Get the created file minus the suffix
        no_ext_path, _ = os.path.splitext(tmp_file.name)
        assert not ToolPlugin.is_valid_executable(no_ext_path)
Пример #6
0
def test_tool_plugin_is_valid_executable_nonexistent():
    """Test that is_valid_executable returns False for a nonexistent file."""
    assert not ToolPlugin.is_valid_executable('nonexistent')