Skip to content

Commit

Permalink
Merge pull request #664 from robtaylor/fix-657
Browse files Browse the repository at this point in the history
Remove dependency on distutils, fixes #657
  • Loading branch information
jacebrowning authored Oct 4, 2024
2 parents a3d8b7a + e29d3cb commit 8e58e29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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

0 comments on commit 8e58e29

Please sign in to comment.