@@ -773,77 +773,113 @@ def test_computer_relabel(self):
773773 # The new label should be available
774774 orm .Computer .collection .get (label = 'comp_cli_test_computer' )
775775
776- def test_computer_delete_with_nodes (self ):
777- """check if 'verdi computer delete' works when there are associated nodes"""
776+ # Ensures that 'yes' works for backwards compatibility, see issue #6422
777+ @pytest .mark .parametrize ('user_input' , ['y' , 'yes' ])
778+ def test_computer_delete_existing_computer_successful (self , user_input ):
779+ """Test if `verdi computer delete` successfully deletes when applied on an existing computer."""
778780 from aiida .common .exceptions import NotExistent
779781
780- label = 'computer_69 '
781- compute_temp = orm .Computer (
782+ label = 'computer_temp '
783+ computer_temp = orm .Computer (
782784 label = label ,
783785 hostname = 'localhost' ,
784786 transport_type = 'core.local' ,
785787 scheduler_type = 'core.direct' ,
786788 workdir = '/tmp/aiida' ,
787789 )
788- compute_temp .store ()
789- compute_temp .configure (safe_interval = 0 )
790+ computer_temp .store ()
791+ computer_temp .configure (safe_interval = 0 )
790792
791- c_label = 'code_69 '
793+ code_label = 'code_temp '
792794 orm .InstalledCode (
793- label = c_label ,
795+ label = code_label ,
794796 default_calc_job_plugin = 'core.arithmetic.add' ,
795- computer = compute_temp ,
797+ computer = computer_temp ,
796798 filepath_executable = '/remote/abs/path' ,
797799 ).store ()
798800
799- false_user_input = 'y' # most common mistake
800- user_input = 'yes'
801-
802- # Abort in case of wrong input
803- self .cli_runner (computer_delete , [label ], user_input = false_user_input , raises = True )
804- orm .load_code (c_label )
805-
806- # Safety check in case of --dry-run
807- options = [label , '--dry-run' ]
808- self .cli_runner (computer_delete , options )
809- orm .load_code (c_label )
810-
811801 # A successul delete, including all associated nodes
812802 self .cli_runner (computer_delete , [label ], user_input = user_input )
813803
814804 with pytest .raises (NotExistent ):
815805 orm .Computer .collection .get (label = label )
816806
817807 with pytest .raises (NotExistent ):
818- orm .load_code (c_label )
808+ orm .load_computer (label )
809+
810+ with pytest .raises (NotExistent ):
811+ orm .load_code (code_label )
812+
813+ # Ensures that 'yes' works for backwards compatibility, see issue #6422
814+ @pytest .mark .parametrize ('user_input' , ['y' , 'yes' ])
815+ def test_computer_delete_existing_computer_successful_no_assciated_nodes (self , user_input ):
816+ """Test if `verdi computer delete` successfully deletes when applied on a computer without associated nodes.
819817
820- def test_computer_delete (self ):
821- """Test if 'verdi computer delete' command works"""
818+ In this case no prompt should appear."""
822819 from aiida .common .exceptions import NotExistent
823820
824- # Setup a computer to delete during the test
825- label = 'computer_for_test_label'
826- orm .Computer (
821+ label = 'computer_temp'
822+ computer_temp = orm .Computer (
827823 label = label ,
828824 hostname = 'localhost' ,
829825 transport_type = 'core.local' ,
830826 scheduler_type = 'core.direct' ,
831827 workdir = '/tmp/aiida' ,
832- ).store ()
833- # and configure it
834- options = ['core.local' , label , '--non-interactive' , '--safe-interval' , '0' ]
835- self .cli_runner (computer_configure , options )
828+ )
829+ computer_temp .store ()
836830
837- # See if the command complains about not getting an invalid computer
838- user_input = 'yes'
839- self .cli_runner (computer_delete , ['computer_that_does_not_exist' ], raises = True , user_input = user_input )
831+ # A successul delete, including all associated nodes
832+ self .cli_runner (computer_delete , [label ])
840833
841- # Delete a computer name successully.
842- self .cli_runner (computer_delete , [label ], user_input = user_input )
843- # Check that the computer really was deleted
844834 with pytest .raises (NotExistent ):
845835 orm .Computer .collection .get (label = label )
846836
837+ with pytest .raises (NotExistent ):
838+ orm .load_computer (label )
839+
840+ def test_computer_delete_existing_computer_not_deleted (self ):
841+ """Test if `verdi computer delete` behaves correctly when applied on an existing computer without deletion.
842+
843+ This case includes when the user enters a wrong input on the prompt and the usage of the dry-run option."""
844+ label = 'computer_temp'
845+ computer_temp = orm .Computer (
846+ label = label ,
847+ hostname = 'localhost' ,
848+ transport_type = 'core.local' ,
849+ scheduler_type = 'core.direct' ,
850+ workdir = '/tmp/aiida' ,
851+ )
852+ computer_temp .store ()
853+ computer_temp .configure (safe_interval = 0 )
854+
855+ code_label = 'code_temp'
856+ orm .InstalledCode (
857+ label = code_label ,
858+ default_calc_job_plugin = 'core.arithmetic.add' ,
859+ computer = computer_temp ,
860+ filepath_executable = '/remote/abs/path' ,
861+ ).store ()
862+
863+ # Tests that Abort in case of wrong input
864+ false_user_input = '' # most common input that could happen by accident
865+ self .cli_runner (computer_delete , [label ], user_input = false_user_input , raises = True )
866+ # raises an error if not existing
867+ assert orm .load_code (code_label ).label == code_label
868+ assert orm .Computer .collection .get (label = label ).label == label
869+
870+ # Safety check in case of --dry-run
871+ options = [label , '--dry-run' ]
872+ self .cli_runner (computer_delete , options , user_input = 'y' )
873+ # raises an error if not existing
874+ assert orm .load_code (code_label ).label == code_label
875+ assert orm .Computer .collection .get (label = label ).label == label
876+
877+ def test_computer_delete_nonexisting_computer (self ):
878+ """Test if `verdi computer delete` command behaves correctly when deleting a nonexisting computer"""
879+ # See if the command complains about not getting an existing computer
880+ result = self .cli_runner (computer_delete , ['computer_that_does_not_exist' ], user_input = 'y' , raises = True )
881+ assert 'no Computer found with LABEL<computer_that_does_not_exist>' in result .stderr
882+
847883
848884@pytest .mark .parametrize ('non_interactive_editor' , ('vim -cwq' ,), indirect = True )
849885def test_computer_duplicate_interactive (run_cli_command , aiida_localhost , non_interactive_editor ):
0 commit comments