@@ -282,37 +282,65 @@ def test_open_file_with_default_app_macos(self):
282282 with patch ('tkface.widget.pathbrowser.utils.IS_WINDOWS' , False ):
283283 with patch ('tkface.widget.pathbrowser.utils.IS_LINUX' , False ):
284284 with patch ('tkface.widget.pathbrowser.utils.subprocess.run' ) as mock_run :
285- result = utils .open_file_with_default_app ("/test/file.txt" )
286- assert result is True
287- mock_run .assert_called_once_with (["open" , "/test/file.txt" ], check = False )
285+ with patch ('tkface.widget.pathbrowser.utils.shutil.which' ) as mock_which :
286+ mock_which .return_value = "/usr/bin/open"
287+ result = utils .open_file_with_default_app ("/test/file.txt" )
288+ assert result is True
289+ mock_run .assert_called_once_with (["/usr/bin/open" , "/test/file.txt" ], check = False )
288290
289291 def test_open_file_with_default_app_macos_exception (self ):
290292 """Test open_file_with_default_app function on macOS with exception."""
291293 with patch ('tkface.widget.pathbrowser.utils.IS_MACOS' , True ):
292294 with patch ('tkface.widget.pathbrowser.utils.IS_WINDOWS' , False ):
293295 with patch ('tkface.widget.pathbrowser.utils.IS_LINUX' , False ):
294296 with patch ('tkface.widget.pathbrowser.utils.subprocess.run' ) as mock_run :
295- mock_run .side_effect = Exception ("Command not found" )
296- result = utils .open_file_with_default_app ("/test/file.txt" )
297- assert result is False
297+ with patch ('tkface.widget.pathbrowser.utils.shutil.which' ) as mock_which :
298+ mock_which .return_value = "/usr/bin/open"
299+ mock_run .side_effect = Exception ("Command not found" )
300+ result = utils .open_file_with_default_app ("/test/file.txt" )
301+ assert result is False
298302
299303 def test_open_file_with_default_app_linux (self ):
300304 """Test open_file_with_default_app function on Linux."""
301305 with patch ('tkface.widget.pathbrowser.utils.IS_LINUX' , True ):
302306 with patch ('tkface.widget.pathbrowser.utils.IS_WINDOWS' , False ):
303307 with patch ('tkface.widget.pathbrowser.utils.IS_MACOS' , False ):
304308 with patch ('tkface.widget.pathbrowser.utils.subprocess.run' ) as mock_run :
305- result = utils .open_file_with_default_app ("/test/file.txt" )
306- assert result is True
307- mock_run .assert_called_once_with (["xdg-open" , "/test/file.txt" ], check = False )
309+ with patch ('tkface.widget.pathbrowser.utils.shutil.which' ) as mock_which :
310+ mock_which .return_value = "/usr/bin/xdg-open"
311+ result = utils .open_file_with_default_app ("/test/file.txt" )
312+ assert result is True
313+ mock_run .assert_called_once_with (["/usr/bin/xdg-open" , "/test/file.txt" ], check = False )
308314
309315 def test_open_file_with_default_app_linux_exception (self ):
310316 """Test open_file_with_default_app function on Linux with exception."""
311317 with patch ('tkface.widget.pathbrowser.utils.IS_LINUX' , True ):
312318 with patch ('tkface.widget.pathbrowser.utils.IS_WINDOWS' , False ):
313319 with patch ('tkface.widget.pathbrowser.utils.IS_MACOS' , False ):
314320 with patch ('tkface.widget.pathbrowser.utils.subprocess.run' ) as mock_run :
315- mock_run .side_effect = Exception ("Command not found" )
321+ with patch ('tkface.widget.pathbrowser.utils.shutil.which' ) as mock_which :
322+ mock_which .return_value = "/usr/bin/xdg-open"
323+ mock_run .side_effect = Exception ("Command not found" )
324+ result = utils .open_file_with_default_app ("/test/file.txt" )
325+ assert result is False
326+
327+ def test_open_file_with_default_app_macos_command_not_found (self ):
328+ """Test open_file_with_default_app function on macOS when command not found."""
329+ with patch ('tkface.widget.pathbrowser.utils.IS_MACOS' , True ):
330+ with patch ('tkface.widget.pathbrowser.utils.IS_WINDOWS' , False ):
331+ with patch ('tkface.widget.pathbrowser.utils.IS_LINUX' , False ):
332+ with patch ('tkface.widget.pathbrowser.utils.shutil.which' ) as mock_which :
333+ mock_which .return_value = None
334+ result = utils .open_file_with_default_app ("/test/file.txt" )
335+ assert result is False
336+
337+ def test_open_file_with_default_app_linux_command_not_found (self ):
338+ """Test open_file_with_default_app function on Linux when command not found."""
339+ with patch ('tkface.widget.pathbrowser.utils.IS_LINUX' , True ):
340+ with patch ('tkface.widget.pathbrowser.utils.IS_WINDOWS' , False ):
341+ with patch ('tkface.widget.pathbrowser.utils.IS_MACOS' , False ):
342+ with patch ('tkface.widget.pathbrowser.utils.shutil.which' ) as mock_which :
343+ mock_which .return_value = None
316344 result = utils .open_file_with_default_app ("/test/file.txt" )
317345 assert result is False
318346
0 commit comments