66from manage import install_command as IC
77from manage import installs
88from manage .exceptions import NoInstallFoundError
9+ from manage .logging import LOGGER
910
1011
1112def test_print_cli_shortcuts (patched_installs , assert_log , monkeypatch , tmp_path ):
@@ -225,50 +226,51 @@ def __init__(self, tmp_path, *args, **kwargs):
225226 self .scratch = {
226227 "install_command.download_cache" : self .download_cache ,
227228 }
228- self .automatic = kwargs .get ("automatic" , False )
229- self .by_id = kwargs .get ("by_id" , False )
230- self .default_install_tag = kwargs .get ("default_install_tag" , "1" )
231- self .default_platform = kwargs .get ("default_platform" , "-32" )
232- self .default_tag = kwargs .get ("default_tag" , "1" )
233- self .download = kwargs .get ("download" )
229+ self .automatic = kwargs .pop ("automatic" , False )
230+ self .by_id = kwargs .pop ("by_id" , False )
231+ self .default_install_tag = kwargs .pop ("default_install_tag" , "1" )
232+ self .default_platform = kwargs .pop ("default_platform" , "-32" )
233+ self .default_tag = kwargs .pop ("default_tag" , "1" )
234+ self .download = kwargs .pop ("download" , None )
234235 if self .download :
235236 self .download = tmp_path / self .download
236- self .download_dir = tmp_path / kwargs .get ("download_dir" , "_cache" )
237- self .dry_run = kwargs .get ("dry_run" , True )
238- self .fallback_source = kwargs .get ("fallback_source" )
239- self .force = kwargs .get ("force" , True )
240- self .from_script = kwargs .get ("from_script" )
241- self .log_file = kwargs .get ("log_file" )
242- self .refresh = kwargs .get ("refresh" , False )
243- self .repair = kwargs .get ("repair" , False )
244- self .shebang_can_run_anything = kwargs .get ("shebang_can_run_anything" , False )
245- self .shebang_can_run_anything_silently = kwargs .get ("shebang_can_run_anything_silently" , False )
246- self .source = kwargs .get ("source" , "http://example.com/index.json" )
247- self .target = kwargs .get ("target" )
237+ self .download_dir = tmp_path / kwargs .pop ("download_dir" , "_cache" )
238+ self .dry_run = kwargs .pop ("dry_run" , True )
239+ self .fallback_source = kwargs .pop ("fallback_source" , None )
240+ self .force = kwargs .pop ("force" , True )
241+ self .from_script = kwargs .pop ("from_script" , None )
242+ self .log_file = kwargs .pop ("log_file" , None )
243+ self .refresh = kwargs .pop ("refresh" , False )
244+ self .repair = kwargs .pop ("repair" , False )
245+ self .shebang_can_run_anything = kwargs .pop ("shebang_can_run_anything" , False )
246+ self .shebang_can_run_anything_silently = kwargs .pop ("shebang_can_run_anything_silently" , False )
247+ self .source = kwargs .pop ("source" , "http://example.com/index.json" )
248+ self .target = kwargs .pop ("target" , None )
248249 if self .target :
249250 self .target = tmp_path / self .target
250- self .update = kwargs .get ("update" , False )
251- self .virtual_env = kwargs .get ("virtual_env" )
251+ self .update = kwargs .pop ("update" , False )
252+ self .virtual_env = kwargs .pop ("virtual_env" , None )
252253
253254 self .index_installs = [
255+ * kwargs .pop ("index_installs" , ()),
254256 {
255257 "schema" : 1 ,
256- "id" : "test-1.1- 32" ,
258+ "id" : "test-32" ,
257259 "sort-version" : "1.1" ,
258260 "company" : "Test" ,
259261 "tag" : "1.1-32" ,
260- "install-for" : ["1" , "1.1" , "1.1-32" ],
262+ "install-for" : ["1-32 " , "1.1-32 " , "1.1-32" ],
261263 "display-name" : "Test 1.1 (32)" ,
262264 "executable" : "test.exe" ,
263265 "url" : "about:blank" ,
264266 },
265267 {
266268 "schema" : 1 ,
267- "id" : "test-1.0- 32" ,
269+ "id" : "test-32" ,
268270 "sort-version" : "1.0" ,
269271 "company" : "Test" ,
270272 "tag" : "1.0-32" ,
271- "install-for" : ["1" , "1.0" , "1.0-32" ],
273+ "install-for" : ["1-32 " , "1.0-32 " , "1.0-32" ],
272274 "display-name" : "Test 1.0 (32)" ,
273275 "executable" : "test.exe" ,
274276 "url" : "about:blank" ,
@@ -280,8 +282,13 @@ def __init__(self, tmp_path, *args, **kwargs):
280282 self .installs = [{
281283 ** self .index_installs [- 1 ],
282284 "source" : self .source ,
283- "prefix" : tmp_path / "test-1.0- 32" ,
285+ "prefix" : tmp_path / "test-32" ,
284286 }]
287+ assert not kwargs
288+
289+ def ask_yn (self , prompt , * args ):
290+ LOGGER .info (prompt , * args )
291+ return True
285292
286293 def get_log_file (self ):
287294 return self .log_file
@@ -302,6 +309,7 @@ def test_install_simple(tmp_path, assert_log):
302309 IC .execute (cmd )
303310 assert_log (
304311 assert_log .skip_until ("Searching for Python matching %s" , ["1.1" ]),
312+ assert_log .skip_until (".*Your existing %s install.*" , ["Test 1.0 (32)" , "Test 1.1 (32)" ]),
305313 assert_log .skip_until ("Installing %s" , ["Test 1.1 (32)" ]),
306314 ("Tag: %s\\ \\ %s" , ["Test" , "1.1-32" ]),
307315 )
@@ -317,6 +325,58 @@ def test_install_already_installed(tmp_path, assert_log):
317325 )
318326
319327
328+
329+ def test_install_update (tmp_path , assert_log ):
330+ cmd = InstallCommandTestCmd (tmp_path , update = True , force = False ,
331+ index_installs = [
332+ {"schema" : 1 , "id" : "test-32" , "sort-version" : "1.2rc1" ,
333+ "display-name" : "Test 1.2rc1 (32)" ,
334+ "company" : "Test" , "tag" : "1.2rc-32" ,
335+ "install-for" : ["1-32" , "1.2-32" , "1.2rc1-32" ]}
336+ ],
337+ )
338+
339+ IC .execute (cmd )
340+ assert_log (
341+ assert_log .skip_until ("Searching for Python with ID %s" , ["test-32" ]),
342+ assert_log .skip_until ("Updating to %s" , ["Test 1.1 (32)" ]),
343+ )
344+
345+
346+ def test_install_update_explicit (tmp_path , assert_log ):
347+ cmd = InstallCommandTestCmd (tmp_path , "1" , update = True , force = False ,
348+ index_installs = [
349+ {"schema" : 1 , "id" : "test-32" , "sort-version" : "1.2rc1" ,
350+ "display-name" : "Test 1.2rc1 (32)" ,
351+ "company" : "Test" , "tag" : "1.2rc-32" ,
352+ "install-for" : ["1-32" , "1.2-32" , "1.2rc1-32" ]}
353+ ],
354+ )
355+
356+ IC .execute (cmd )
357+ assert_log (
358+ assert_log .skip_until ("Searching for Python matching %s" , ["1" ]),
359+ assert_log .skip_until ("Updating to %s" , ["Test 1.1 (32)" ]),
360+ )
361+
362+
363+ def test_install_update_explicit_pre (tmp_path , assert_log ):
364+ cmd = InstallCommandTestCmd (tmp_path , "1rc" , update = True , force = False ,
365+ index_installs = [
366+ {"schema" : 1 , "id" : "test-32" , "sort-version" : "1.2rc1" ,
367+ "display-name" : "Test 1.2rc1 (32)" ,
368+ "company" : "Test" , "tag" : "1.2rc-32" ,
369+ "install-for" : ["1-32" , "1.2-32" , "1.2rc1-32" ]}
370+ ],
371+ )
372+
373+ IC .execute (cmd )
374+ assert_log (
375+ assert_log .skip_until ("Searching for Python matching %s" , ["1rc" ]),
376+ assert_log .skip_until ("Updating to %s" , ["Test 1.2rc1 (32)" ]),
377+ )
378+
379+
320380def test_install_from_script (tmp_path , assert_log ):
321381 cmd = InstallCommandTestCmd (tmp_path , from_script = tmp_path / "t.py" )
322382
0 commit comments