File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 12
12
import time
13
13
import webbrowser
14
14
from collections .abc import Iterable , Mapping , Sequence
15
+ from pathlib import Path
15
16
from typing import Any , Literal
16
17
17
18
import xarray as xr
@@ -580,7 +581,7 @@ def launch_external_viewer(fname: str, waiting: float = 0):
580
581
case "win32" : # Windows
581
582
os .startfile (fname ) # type:ignore[attr-defined] # noqa: S606
582
583
case _: # Fall back to the browser if can't recognize the operating system.
583
- webbrowser .open_new_tab (f"file://{ fname } " )
584
+ webbrowser .open_new_tab (f"file://{ Path ( fname ). resolve () } " )
584
585
if waiting > 0 :
585
586
# Preview images will be deleted when a GMT modern-mode session ends, but the
586
587
# external viewer program may take a few seconds to open the images.
Original file line number Diff line number Diff line change @@ -194,13 +194,16 @@ def test_launch_external_viewer_win32():
194
194
mock_startfile .assert_called_once_with ("preview.png" )
195
195
196
196
197
- def test_launch_external_viewer_unknown_os ():
197
+ @pytest .mark .parametrize ("fname" , ["preview.png" , "/full/path/to/preview.png" ])
198
+ def test_launch_external_viewer_unknown_os (fname ):
198
199
"""
199
200
Test that launch_external_viewer uses the webbrowser module as a fallback.
200
201
"""
201
202
with (
202
- patch ("webbrowser.open_new_tab" ) as mock_open ,
203
203
patch ("sys.platform" , "unknown" ),
204
+ patch ("webbrowser.open_new_tab" ) as mock_open ,
204
205
):
205
- launch_external_viewer ("preview.png" )
206
- mock_open .assert_called_once_with ("file://preview.png" )
206
+ launch_external_viewer (fname )
207
+ fullpath = Path (fname ).resolve ()
208
+ assert fullpath .is_absolute ()
209
+ mock_open .assert_called_once_with (f"file://{ fullpath } " )
You can’t perform that action at this time.
0 commit comments