Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on distutils, fixes #657 #664

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doorstop/core/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"""Functions to edit documents and items."""

import os
import shutil
import subprocess
import sys
import tempfile
import time
from distutils.spawn import find_executable

from doorstop import common
from doorstop.common import DoorstopError
Expand Down Expand Up @@ -87,7 +87,7 @@ def launch(path, tool=None):
elif sys.platform.startswith("darwin"):
args = ["open", path]
elif os.name == "nt":
cygstart = find_executable("cygstart")
cygstart = shutil.which("cygstart")
if cygstart:
args = [cygstart, path]
else:
Expand Down
36 changes: 36 additions & 0 deletions doorstop/core/tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest
from unittest.mock import MagicMock, Mock, patch

import doorstop.core.editor
from doorstop import common, settings
from doorstop.common import DoorstopError
from doorstop.core.item import Item, UnknownItem
Expand Down Expand Up @@ -471,6 +472,41 @@ def test_edit(self, mock_launch, mock_load):
mock_launch.assert_called_once_with(self.item.path, tool="mock_editor")
mock_load.assert_called_once_with(True)

@patch("doorstop.core.editor.os.name", "nt")
@patch("doorstop.core.editor.sys.platform", "nt")
@patch("doorstop.core.editor.shutil.which")
@patch("doorstop.core.editor._call")
def test_launch_os_nt_cygwin(self, mock_call, mock_which):
mock_call.side_effect = FileNotFoundError
mock_which.return_value = "cygstart"
self.assertRaises(DoorstopError, doorstop.core.editor.launch, "")
mock_call.assert_called_once_with(["cygstart", ""])

@patch("doorstop.core.editor.os.name", "nt")
@patch("doorstop.core.editor.sys.platform", "nt")
@patch("doorstop.core.editor.shutil.which")
@patch("doorstop.core.editor._call")
def test_launch_os_nt(self, mock_call, mock_which):
mock_call.side_effect = FileNotFoundError
mock_which.return_value = "start"
self.assertRaises(DoorstopError, doorstop.core.editor.launch, "")
mock_call.assert_called_once_with(["start", ""])

@patch("doorstop.core.editor.sys.platform", "darwin")
@patch("doorstop.core.editor._call")
def test_launch_os_darwin(self, mock_call):
mock_call.side_effect = FileNotFoundError
self.assertRaises(DoorstopError, doorstop.core.editor.launch, "")
mock_call.assert_called_once_with(["open", ""])

@patch("doorstop.core.editor.os.name", "posix")
@patch("doorstop.core.editor.sys.platform", "posix")
@patch("doorstop.core.editor._call")
def test_launch_os_posix(self, mock_call):
mock_call.side_effect = FileNotFoundError
self.assertRaises(DoorstopError, doorstop.core.editor.launch, "")
mock_call.assert_called_once_with(["xdg-open", ""])

def test_link(self):
"""Verify links can be added to an item."""
self.item.link("abc")
Expand Down
Loading