Skip to content

Commit

Permalink
Coverage for launch on, nt, cygwin, darwin and posix
Browse files Browse the repository at this point in the history
  • Loading branch information
robtaylor committed Oct 4, 2024
1 parent 1c2a757 commit e29d3cb
Showing 1 changed file with 36 additions and 0 deletions.
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 e29d3cb

Please sign in to comment.