Esempio n. 1
0
    def test_with_no_arguments(self, *api_clients):
        result = self.runner.invoke(delete)
        assert_exit_code(result, 0)

        # No calls to API clients, exit 0
        for client in api_clients:
            client.assert_not_called()
Esempio n. 2
0
    def test_with_invalid_config(self,
                          exists,
                          expt_client,
                          create_module,
                          set_config,
                          get_config,
                          get_auth_header,
                          get_access_token,
                          get_all_env,
                          assert_token_not_expired):
        """
        Simple experiment with no data attached
        """
        with open('floyd.yml', 'w') as fd:
            fd.write('#')

        # empty config file should not result in crash
        result = self.runner.invoke(run, ['command'], catch_exceptions=False)
        assert_exit_code(result, 0)

        with open('floyd.yml', 'w') as fd:
            fd.write('foo: [}')

        # invalid config file should result in error
        result = self.runner.invoke(run, ['command'], catch_exceptions=False)
        assert_exit_code(result, 1)

        os.remove('floyd.yml')
Esempio n. 3
0
    def test_delete_without_yes_option(self,
                                       delete_experiment,
                                       get_experiment,
                                       module_client,
                                       task_instance_client,
                                       get_auth_header,
                                       get_access_token):
        id_1 = 'mckay/projects/foo/1'
        id_2 = 'mckay/projects/foo/2'
        id_3 = 'mckay/projects/foo/3'

        # Tell prompt to skip id_1 and id_3
        result = self.runner.invoke(delete,
                                    [id_1, id_2, id_3],
                                    input='n\nY\nn\n')

        # Triggers a get for all ids
        calls = [call(id_1), call(id_2), call(id_3)]
        get_experiment.assert_has_calls(calls, any_order=True)

        # Calls delete for only id_2
        delete_experiment.assert_called_once_with(id_2)

        # Does not call TaskInstanceClient or ModuleClient
        task_instance_client.assert_not_called()
        module_client.assert_not_called()

        assert_exit_code(result, 0)
Esempio n. 4
0
    def test_with_no_arguments(self, data_client):
        result = self.runner.invoke(delete)

        # No calls to api, exit 0
        data_client.assert_not_called()

        assert_exit_code(result, 0)
Esempio n. 5
0
 def test_with_no_data(self, exists, expt_client, create_module, set_config,
                       get_config, get_auth_header, get_access_token,
                       get_all_env, assert_token_not_expired):
     """
     Simple experiment with no data attached
     """
     result = self.runner.invoke(run, ['command'], catch_exceptions=False)
     assert_exit_code(result, 0)
Esempio n. 6
0
 def test_with_multiple_data_ids(self, exists, expt_client, create_module,
                                 set_config, get_config, get_access_token,
                                 env_get_all, data_get, get_data_config):
     """
     Experiment with multiple data ids
     """
     data_get.return_value.id = 'data_id'
     result = self.runner.invoke(
         run, ['command', '--data', 'data-id1', '--data', 'data-id2'],
         catch_exceptions=False)
     assert_exit_code(result, 0)
Esempio n. 7
0
 def test_mount_dataset_without_version(self, exists, expt_client,
                                        create_module, set_config,
                                        get_config, get_auth_header,
                                        get_access_token, get_all_env,
                                        assert_token_not_expired,
                                        data_client_get):
     """
     CLI should fail if more than one --env is passed
     """
     result = self.runner.invoke(
         run, ['--env', 'foo', '--data', 'foo/datasets/bar:bar', 'ls'])
     assert_exit_code(result, 0)
Esempio n. 8
0
    def test_with_found_task_instance(self, experiment_client, access_token):
        experiment_client.return_value.get.return_value = Mock(id='999999')
        id_1 = 'mckay/projects/foo/1'
        result = self.runner.invoke(delete, ['-y', id_1])

        experiment_client.return_value.get.assert_called_once_with(id_1)
        # Get the module_id of the experiment's task instance and call delete
        # on it. '999999' is the module_id of the mocked TaskInstance
        experiment_client.return_value.delete.assert_called_once_with('999999')

        # Exit 0 for successful experiment delete
        assert_exit_code(result, 0)
Esempio n. 9
0
    def test_with_no_found_task_instance(self, experiment_client,
                                         access_token):
        experiment_client.return_value.get.return_value = None
        id_1 = 'mckay/projects/foo/1'
        result = self.runner.invoke(delete, ['-y', id_1])

        experiment_client.return_value.get.assert_called_once_with(id_1)
        # If a task instance is not found, delete is not called
        experiment_client.return_value.delete.assert_not_called()

        # Exit 1 for unsuccessful experiment delete
        assert_exit_code(result, 1)
Esempio n. 10
0
    def test_multiple_envs_fails(self, exists, expt_client, create_module,
                                 set_config, get_config, get_access_token,
                                 get_all_env, assert_token_not_expired):
        """
        CLI should fail if more than one --env is passed
        """
        result = self.runner.invoke(run,
                                    ['--env', 'foo', '--env', 'bar', 'ls'])
        assert_exit_code(result, 1)

        result = self.runner.invoke(run, ['--env', 'foo', 'ls'])
        assert_exit_code(result, 0)
Esempio n. 11
0
    def test_does_not_del_module_if_exp_del_fails(
            self, get_experiment, delete_experiment, delete_module,
            get_module_task_instance_id, get_task_instance, get_access_token):
        id_1 = 'mckay/projects/foo/1'
        result = self.runner.invoke(delete, ['-y', id_1])

        # Call delete on the experiment
        delete_experiment.assert_called_once()

        # Do not attempt to delete the module after a failed delete
        delete_module.assert_not_called()

        # Exit 1 for failed experiment delete
        assert_exit_code(result, 1)
Esempio n. 12
0
    def test_with_multiple_ids_and_yes_option(self, delete_data, get_data,
                                              assert_token_not_expired,
                                              get_access_token, get_project,
                                              get_expt_config,
                                              get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        assert_exit_code(result, 0)
        # Trigger a get and a delete for each id
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)
        delete_data.assert_has_calls(calls, any_order=True)
Esempio n. 13
0
    def test_with_multiple_ids_and_yes_option(self, delete_experiment,
                                              get_experiment, module_client,
                                              task_instance_client,
                                              get_access_token):
        id_1 = 'mckay/projects/foo/1'
        id_2 = 'mckay/projects/foo/2'
        id_3 = 'mckay/projects/foo/3'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        # Trigger a get and a delete for each id
        calls = [call(id_1), call(id_2), call(id_3)]
        get_experiment.assert_has_calls(calls, any_order=True)
        delete_experiment.assert_has_calls(calls, any_order=True)

        assert_exit_code(result, 0)
Esempio n. 14
0
    def test_failed_delete(self, delete_data, get_data,
                           assert_token_not_expired, get_access_token,
                           project_client, get_expt_config, get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        # Trigger a get and a delete for each id, even though each delete
        # fails. All deletes are attempted regardless of previous failures.
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)
        delete_data.assert_has_calls(calls, any_order=True)

        # Exit 1 for failed deletes
        assert_exit_code(result, 1)
Esempio n. 15
0
    def test_failed_get(self, delete_data, get_data, assert_token_not_expired,
                        get_access_token, get_expt_config, get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        # Trigger a get for each id, even though each fails. (No early exit)
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)

        # Deletes are not triggered for ids that are not found
        delete_data.assert_not_called()

        # Exit 1 for failed get requests
        assert_exit_code(result, 1)
Esempio n. 16
0
    def test_failed_delete(self, delete_experiment, get_experiment,
                           task_instance_client, module_client,
                           get_access_token):

        id_1 = 'mckay/projects/foo/1'
        id_2 = 'mckay/projects/foo/2'
        id_3 = 'mckay/projects/foo/3'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        # Trigger a get and a delete for each id, even though each delete
        # fails. All deletes are attempted regardless of previous failures.
        calls = [call(id_1), call(id_2), call(id_3)]
        get_experiment.assert_has_calls(calls, any_order=True)
        delete_experiment.assert_has_calls(calls, any_order=True)

        # Exit 1 for failed deletes
        assert_exit_code(result, 1)
Esempio n. 17
0
    def test_delete_without_yes_option(self, delete_data, get_data,
                                       assert_token_not_expired,
                                       get_access_token, project_client,
                                       get_expt_config, get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        # Tell prompt to skip id_1 and id_3
        result = self.runner.invoke(delete, [id_1, id_2, id_3],
                                    input='n\nY\nn\n')

        # Triggers a get for all ids
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)

        # Calls delete for only id_2
        delete_data.assert_called_once_with(id_2)

        assert_exit_code(result, 0)
Esempio n. 18
0
    def test_regex_for_data_arg(self, exists, expt_client, create_module,
                                set_config, get_config, get_auth_header,
                                get_access_token, env_get_all, data_get,
                                get_data_config):
        """
        Test regex patterns for data arg
        """
        # PATTERN: <dataset_name>:<mounting_point>
        result = self.runner.invoke(run,
                                    ['command', '--data', 'data-id1:/bar'],
                                    catch_exceptions=False)
        assert_exit_code(result, 0)

        # PATTERN: <namespace>/[projects|datasets]/<dataset_or_project_name>:<mounting_point>
        result = self.runner.invoke(
            run, ['command', '--data', 'mckay/datasets/data-id1/:bar'],
            catch_exceptions=False)
        assert_exit_code(result, 0)

        # PATTERN: <namespace>/projects/<project_name>/output:<mounting_point>
        result = self.runner.invoke(
            run, ['command', '--data', 'mckay/projects/test/1/output:/bar'],
            catch_exceptions=False)
        assert_exit_code(result, 0)

        # PATTERN: <namespace>/[projects|datasets]/<dataset_or_project_name>/<version>:<mounting_point>
        result = self.runner.invoke(
            run, ['command', '--data', 'mckay/datasets/data-id1/1:bar_2_foo'],
            catch_exceptions=False)
        assert_exit_code(result, 0)

        # PATTERN: Bad argument (missing mounting point)
        result = self.runner.invoke(run, ['command', '--data', 'data-id1:'],
                                    catch_exceptions=False)
        assert_exit_code(result, 1)

        # PATTERN: Bad argument (/)
        result = self.runner.invoke(run, ['command', '--data', '/'],
                                    catch_exceptions=False)
        assert_exit_code(result, 1)

        # PATTERN: Bad argument - URL
        result = self.runner.invoke(run, [
            'command', '--data', 'https://floydhub.com/mckay/datasets/data-id1'
        ],
                                    catch_exceptions=False)
        assert_exit_code(result, 1)

        # PATTERN: Bad argument - mounting point
        result = self.runner.invoke(
            run, ['command', '--data', 'mckay/datasets/data-id1:/input/code'],
            catch_exceptions=False)
        assert_exit_code(result, 1)
Esempio n. 19
0
 def test_login_help(self):
     result = self.runner.invoke(login, ['--help'])
     assert_exit_code(result, 0)