Пример #1
0
def test_tool_plugin_command_exists_fullpath(monkeypatch):
    """Test that command_exists works correctly (full path given). """

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

    # Make a temporary directory which will be part of the path
    with TemporaryDirectory() as tmp_dir:
        # Make a temporary executable
        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp_file:
            st = os.stat(tmp_file.name)
            os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)
            assert ToolPlugin.command_exists(tmp_file.name)
Пример #2
0
def test_tool_plugin_command_exists_shortpath_invalid(monkeypatch):
    """Test that command_exists works correctly (only filename given, command is not on PATH). """

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

    # Make a temporary directory which will be part of the path
    with TemporaryDirectory() as tmp_dir:
        # Make a temporary executable
        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp_file:
            st = os.stat(tmp_file.name)
            os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)
            _, tmp_file_name = os.path.split(tmp_file.name)
            assert not ToolPlugin.command_exists(tmp_file_name)
Пример #3
0
def test_tool_plugin_command_exists_fullpath(monkeypatch):
    """Test that command_exists works correctly (full path given). """

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

    # Make a temporary directory which will be part of the path
    tmp_dir = tempfile.mkdtemp()

    # Make a temporary executable
    tmp_file = tempfile.NamedTemporaryFile(dir=tmp_dir)
    st = os.stat(tmp_file.name)
    os.chmod(tmp_file.name, st.st_mode | stat.S_IXUSR)

    assert ToolPlugin.command_exists(tmp_file.name)

    # Cleanup
    shutil.rmtree(tmp_dir, ignore_errors=True)