def test_call_create(self): """The method should correctly call only the create method and pass the given arguments to it.""" args_list = ['create', 'File*Set'] determine_and_perform_action(args_list) _assert_only_this_mock_called(mock_create, [args_list])
def test_call_move(self): """The method should correctly call only the move method and pass the given arguments to it.""" args_list = ['1-3', '>', '4/5'] determine_and_perform_action(args_list) _assert_only_this_mock_called(mock_move, [self.active_file_set_dummy, args_list])
def test_call_add(self): """The method should correctly call only the add method and pass the given arguments to it.""" args_list = ['+', 'new_file', '1/2'] determine_and_perform_action(args_list) _assert_only_this_mock_called(mock_add, [self.active_file_set_dummy, args_list])
def test_call_print_help(self): """The method should correctly call only the print_help method and pass the given arguments to it.""" args_list = ['help', 'me'] determine_and_perform_action(args_list) _assert_only_this_mock_called(mock_help, [self.active_file_set_dummy, args_list])
def test_no_action_applies(self): """The method should print an according message if no correct action could be determined by the given arguments.""" args_list = ['gib', 'ber', 'ish'] determine_and_perform_action(args_list) _assert_only_this_mock_called( mock_print, ['The given command or operation could not be resolved.'])
def test_no_arguments_given(self): """The method should do nothing if an empty list of arguments was given.""" args_list = [] determine_and_perform_action(args_list) ## Make a new mock that is unregistered in the global list. That way, it will never be ## checked whether it was actually ever called. It will only be checked whether ## all of the registered ones have NOT been called. _assert_only_this_mock_called(mock.MagicMock(), [])
def test_terminate(self): """The methode should raise a TerminateProgram exception when the user enters the command 'terminate'""" args_list = ['terminate'] with self.assertRaises( TerminateProgram, msg= "The method fails to terminate the program by raising an exception if the user wishes to." ): determine_and_perform_action(args_list) ## Make a new mock that is unregistered in the global list. That way, it will never be ## checked whether it was actually ever called. It will only be checked whether ## all of the registered ones have NOT been called. _assert_only_this_mock_called(mock.MagicMock(), [])
def test_exit_file_set(self): """The method should exit the currently active file set if the user enters 'exit'""" args_list = ['exit'] CLI.active_file_set = FileSet(('test', ''), []) # active file set is not None determine_and_perform_action(args_list) self.assertEqual( CLI.active_file_set, None, "The method failed to leave the currently active_file_set.") ## Make a new mock that is unregistered in the global list. That way, it will never be ## checked whether it was actually ever called. It will only be checked whether ## all of the registered ones have NOT been called. _assert_only_this_mock_called(mock.MagicMock(), [])
def test_exit_program(self): """The method should terminate the program if the user enters 'exit' without having an active file set.""" args_list = ['exit'] CLI.active_file_set = None # no active file set with self.assertRaises( TerminateProgram, msg= "The method fails to terminate the program by raising an exception if the user exits when no file set is active." ): determine_and_perform_action(args_list) ## Make a new mock that is unregistered in the global list. That way, it will never be ## checked whether it was actually ever called. It will only be checked whether ## all of the registered ones have NOT been called. _assert_only_this_mock_called(mock.MagicMock(), [])