@@ -310,125 +310,3 @@ def test_check_supported(installer: KubernetesInstaller | SlurmInstaller, monkey
310310
311311 res = installer .mark_as_installed_one (item )
312312 assert res .success , f"Failed to mark as installed { item } for { installer .__class__ .__name__ = } { res .message = } "
313-
314-
315- class MyInstallable (Installable ):
316- def __eq__ (self , other : object ) -> bool :
317- return True
318-
319- def __hash__ (self ) -> int :
320- return hash ("MyInstallable" )
321-
322-
323- class CustomInstallable (Installable ):
324- def __init__ (self ):
325- self .calls : list [tuple [str , BaseInstaller ]] = []
326-
327- def __eq__ (self , other : object ) -> bool :
328- return isinstance (other , CustomInstallable )
329-
330- def __hash__ (self ) -> int :
331- return hash ("CustomInstallable" )
332-
333- def install (self , installer : BaseInstaller ) -> InstallStatusResult :
334- self .calls .append (("install" , installer ))
335- return InstallStatusResult (True , "custom installed" )
336-
337- def uninstall (self , installer : BaseInstaller ) -> InstallStatusResult :
338- self .calls .append (("uninstall" , installer ))
339- return InstallStatusResult (True , "custom uninstalled" )
340-
341- def is_installed (self , installer : BaseInstaller ) -> InstallStatusResult :
342- self .calls .append (("is_installed" , installer ))
343- return InstallStatusResult (True , "custom is installed" )
344-
345- def mark_as_installed (self , installer : BaseInstaller ) -> InstallStatusResult :
346- self .calls .append (("mark_as_installed" , installer ))
347- return InstallStatusResult (True , "custom marked as installed" )
348-
349-
350- class CustomDockerImage (DockerImage ):
351- def __init__ (self , url : str ):
352- super ().__init__ (url )
353- self .calls : list [tuple [str , BaseInstaller ]] = []
354-
355- def __eq__ (self , other : object ) -> bool :
356- return isinstance (other , CustomDockerImage ) and self .url == other .url
357-
358- def __hash__ (self ) -> int :
359- return hash ((CustomDockerImage , self .url ))
360-
361- def install (self , installer : BaseInstaller ) -> InstallStatusResult :
362- self .calls .append (("install" , installer ))
363- return InstallStatusResult (True , "custom docker installed" )
364-
365- def uninstall (self , installer : BaseInstaller ) -> InstallStatusResult :
366- self .calls .append (("uninstall" , installer ))
367- return InstallStatusResult (True , "custom docker uninstalled" )
368-
369- def is_installed (self , installer : BaseInstaller ) -> InstallStatusResult :
370- self .calls .append (("is_installed" , installer ))
371- return InstallStatusResult (True , "custom docker is installed" )
372-
373- def mark_as_installed (self , installer : BaseInstaller ) -> InstallStatusResult :
374- self .calls .append (("mark_as_installed" , installer ))
375- return InstallStatusResult (True , "custom docker marked as installed" )
376-
377-
378- def test_check_unsupported (installer : KubernetesInstaller | SlurmInstaller ):
379- unsupported = MyInstallable ()
380- for func in [
381- installer .install_one ,
382- installer .uninstall_one ,
383- installer .is_installed_one ,
384- installer .mark_as_installed_one ,
385- ]:
386- res = func (unsupported )
387- assert not res .success
388- assert "Unsupported installable operation" in res .message
389- assert type (unsupported ).__name__ in res .message
390-
391-
392- def test_custom_installable_operations_are_dispatched (slurm_system : SlurmSystem ):
393- installer = BaseInstaller (slurm_system )
394- item = CustomInstallable ()
395-
396- install_result = installer .install_one (item )
397- is_installed_result = installer .is_installed_one (item )
398- uninstall_result = installer .uninstall_one (item )
399- mark_result = installer .mark_as_installed_one (item )
400-
401- assert install_result .success
402- assert is_installed_result .success
403- assert uninstall_result .success
404- assert mark_result .success
405- assert ("install" , installer ) in item .calls
406- assert ("is_installed" , installer ) in item .calls
407- assert ("uninstall" , installer ) in item .calls
408- assert ("mark_as_installed" , installer ) in item .calls
409-
410-
411- def test_builtin_installable_subclass_operations_are_dispatched (slurm_system : SlurmSystem ):
412- installer = SlurmInstaller (slurm_system )
413- item = CustomDockerImage ("fake_url/img" )
414-
415- results = [
416- installer .install_one (item ),
417- installer .uninstall_one (item ),
418- installer .is_installed_one (item ),
419- installer .mark_as_installed_one (item ),
420- ]
421-
422- assert all (result .success for result in results )
423- assert [result .message for result in results ] == [
424- "custom docker installed" ,
425- "custom docker uninstalled" ,
426- "custom docker is installed" ,
427- "custom docker marked as installed" ,
428- ]
429- assert item .calls == [
430- ("install" , installer ),
431- ("uninstall" , installer ),
432- ("is_installed" , installer ),
433- ("mark_as_installed" , installer ),
434- ]
0 commit comments