From 1c2a757949c8dc20b0c5ff30791e2bb6bcdecf83 Mon Sep 17 00:00:00 2001 From: Rob Taylor Date: Sun, 29 Sep 2024 22:25:13 -0400 Subject: [PATCH 1/2] Remove dependency on distutils, fixes #657 --- doorstop/core/editor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doorstop/core/editor.py b/doorstop/core/editor.py index 6dbdde0d9..7e14a1c76 100644 --- a/doorstop/core/editor.py +++ b/doorstop/core/editor.py @@ -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 @@ -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: From e29d3cb46487bad6757952394d004d35d83277ff Mon Sep 17 00:00:00 2001 From: Rob Taylor Date: Thu, 3 Oct 2024 20:44:41 -0400 Subject: [PATCH 2/2] Coverage for launch on, nt, cygwin, darwin and posix --- doorstop/core/tests/test_item.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doorstop/core/tests/test_item.py b/doorstop/core/tests/test_item.py index 8f6088ca8..cc7ad31f4 100644 --- a/doorstop/core/tests/test_item.py +++ b/doorstop/core/tests/test_item.py @@ -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 @@ -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")