77
88from seiscat .self .install_detection import InstallContext
99from seiscat .self .update import (
10+ _schedule_windows_uv_tool_install ,
1011 _pip_update_git ,
1112 _uv_update_git ,
13+ _uv_update_release ,
1214 uninstall_seiscat ,
1315 update_seiscat ,
1416)
@@ -18,7 +20,7 @@ class TestSelfUpdatePolicy(unittest.TestCase):
1820 """Validate release/git policy for `seiscat self update`."""
1921
2022 @patch ('seiscat.self.update.shutil.which' , return_value = '/usr/bin/uv' )
21- @patch ('seiscat.self.update._uv_update_release' )
23+ @patch ('seiscat.self.update._uv_update_release' , return_value = False )
2224 @patch ('seiscat.self.update.detect_install_context' )
2325 @patch (
2426 'seiscat.self.update.get_latest_release_version' ,
@@ -172,9 +174,11 @@ def test_pip_update_git_installs_extras(self, mock_run_checked):
172174 ])
173175
174176 @patch ('seiscat.self.update._run_checked' )
177+ @patch ('seiscat.self.update.os.name' , 'posix' )
175178 def test_uv_update_git_installs_extras (self , mock_run_checked ):
176- _uv_update_git ()
179+ deferred = _uv_update_git ()
177180
181+ self .assertFalse (deferred )
178182 mock_run_checked .assert_called_once_with ([
179183 'uv' ,
180184 'tool' ,
@@ -184,3 +188,55 @@ def test_uv_update_git_installs_extras(self, mock_run_checked):
184188 '--upgrade' ,
185189 '--force' ,
186190 ])
191+
192+ @patch ('seiscat.self.update._schedule_windows_uv_tool_install' )
193+ @patch ('seiscat.self.update.os.name' , 'nt' )
194+ def test_uv_update_git_is_deferred_on_windows (self , mock_schedule ):
195+ deferred = _uv_update_git ()
196+
197+ self .assertTrue (deferred )
198+ mock_schedule .assert_called_once_with (
199+ 'seiscat[cartopy,plotly,folium] @ '
200+ 'git+https://github.com/SeismicSource/seiscat.git'
201+ )
202+
203+ @patch ('seiscat.self.update._schedule_windows_uv_tool_install' )
204+ @patch ('seiscat.self.update.os.name' , 'nt' )
205+ def test_uv_update_release_is_deferred_on_windows (self , mock_schedule ):
206+ deferred = _uv_update_release ()
207+
208+ self .assertTrue (deferred )
209+ mock_schedule .assert_called_once_with ('seiscat' )
210+
211+ @patch ('seiscat.self.update.shutil.which' , return_value = 'uv' )
212+ @patch ('seiscat.self.update.detect_install_context' )
213+ @patch ('seiscat.self.update._uv_update_git' , return_value = True )
214+ def test_update_git_reports_scheduled_on_windows (
215+ self ,
216+ _mock_uv_update_git ,
217+ mock_detect ,
218+ _mock_which ):
219+ mock_detect .return_value = InstallContext (
220+ installer = 'uv' ,
221+ channel = 'release' ,
222+ version_installed = '0.9.1' ,
223+ source_url = None ,
224+ editable = False ,
225+ confidence = 'high' ,
226+ )
227+
228+ msg = update_seiscat (git = True )
229+ self .assertIn ('scheduled' , msg )
230+
231+ @patch ('seiscat.self.update.os.getpid' , return_value = 1234 )
232+ @patch ('seiscat.self.update.sys.executable' , 'C:/Python/python.exe' )
233+ @patch ('seiscat.self.update.subprocess.Popen' )
234+ def test_windows_uv_helper_uses_retry_loop (self , mock_popen , _mock_getpid ):
235+ _schedule_windows_uv_tool_install ('seiscat' )
236+
237+ mock_popen .assert_called_once ()
238+ cmd = mock_popen .call_args [0 ][0 ]
239+ self .assertEqual (cmd [0 ], 'C:/Python/python.exe' )
240+ self .assertEqual (cmd [1 ], '-c' )
241+ self .assertIn ('for _ in range(8):' , cmd [2 ])
242+ self .assertIn ('time.sleep(1)' , cmd [2 ])
0 commit comments