Example #1
0
File: list.py Project: xe1gyq/nauta
def list_inference_instances(state: State, all_users: bool, name: str,
                             status: RunStatus, uninitialized: bool,
                             count: int, brief: bool):
    """ List inference instances. """
    if brief:
        table_headers = [
            RUN_INFERENCE_NAME, RUN_SUBMISSION_DATE, RUN_SUBMITTER, RUN_STATUS
        ]
    else:
        table_headers = [
            RUN_INFERENCE_NAME, RUN_PARAMETERS, RUN_SUBMISSION_DATE,
            RUN_START_DATE, RUN_END_DATE, RUN_SUBMITTER, RUN_STATUS,
            RUN_TEMPLATE_NAME
        ]
    if uninitialized:
        list_unitialized_experiments_in_cli(
            verbosity_lvl=state.verbosity,
            all_users=all_users,
            name=name,
            headers=table_headers,
            listed_runs_kinds=LISTED_RUNS_KINDS,
            count=count,
            brief=brief)
    else:
        list_runs_in_cli(state.verbosity,
                         all_users,
                         name,
                         status,
                         LISTED_RUNS_KINDS,
                         table_headers,
                         with_metrics=False,
                         count=count,
                         brief=brief)
Example #2
0
File: list.py Project: zhcf/nauta
def list_experiments(state: State, all_users: bool, name: str,
                     status: RunStatus, uninitialized: bool, count: int,
                     brief: bool):
    """ List experiments. """
    if brief:
        list_headers = [
            RUN_NAME, RUN_SUBMISSION_DATE, RUN_SUBMITTER, RUN_STATUS
        ]
    else:
        list_headers = EXPERIMENTS_LIST_HEADERS
    if uninitialized:
        list_unitialized_experiments_in_cli(verbosity_lvl=state.verbosity,
                                            all_users=all_users,
                                            name=name,
                                            headers=list_headers,
                                            count=count,
                                            brief=brief)
    else:
        list_runs_in_cli(state.verbosity,
                         all_users,
                         name,
                         status,
                         LISTED_RUNS_KINDS,
                         list_headers,
                         with_metrics=True,
                         count=count,
                         brief=brief)
Example #3
0
def test_list_experiments_brief_success(mocker, capsys):
    api_list_runs_mock = mocker.patch("commands.common.Run.list")
    api_list_runs_mock.return_value = TEST_RUNS

    mocker.patch("commands.common.Experiment.get",
                 return_value=TEST_EXPERIMENT)

    get_namespace_mock = mocker.patch(
        "commands.common.get_kubectl_current_context_namespace")

    common.list_runs_in_cli(verbosity_lvl=0,
                            all_users=True,
                            name="",
                            status=None,
                            listed_runs_kinds=[],
                            runs_list_headers=TEST_LIST_HEADERS,
                            with_metrics=False,
                            brief=True)

    captured = capsys.readouterr()

    assert "a 1 b 2" not in captured.out
    assert "test-experiment-2" in captured.out
    assert get_namespace_mock.call_count == 0
    assert api_list_runs_mock.call_count == 1, "Runs were not retrieved"
Example #4
0
def test_list_experiments_one_user_success(mocker, capsys):
    api_list_runs_mock = mocker.patch("commands.common.Run.list")
    mocker.patch("dateutil.tz.tzlocal").return_value = dateutil.tz.UTC
    api_list_runs_mock.return_value = TEST_RUNS
    mocker.patch("commands.common.Experiment.get",
                 return_value=TEST_EXPERIMENT)

    get_namespace_mock = mocker.patch(
        "commands.common.get_kubectl_current_context_namespace")

    headers = ["Name", "Submission date", "Owner", "Status"]

    common.list_runs_in_cli(verbosity_lvl=0,
                            all_users=True,
                            name="",
                            status=None,
                            listed_runs_kinds=[],
                            runs_list_headers=headers,
                            with_metrics=False,
                            count=1,
                            brief=False)

    captured = capsys.readouterr()

    assert "2018-04-26 01:43:01 PM" not in captured.out
    assert "2018-05-08 01:05:04 PM" in captured.out
    assert "Parameters" not in captured.out
    assert "Owner" in captured.out
    assert get_namespace_mock.call_count == 0
    assert api_list_runs_mock.call_count == 1, "Runs were not retrieved"
Example #5
0
def test_list_experiments_all_users_success(mocker):
    api_list_runs_mock = mocker.patch("commands.common.Run.list")
    api_list_runs_mock.return_value = TEST_RUNS

    get_namespace_mock = mocker.patch("commands.common.get_kubectl_current_context_namespace")

    common.list_runs_in_cli(verbosity_lvl=0, all_users=True, name="", status=None, listed_runs_kinds=[],
                            runs_list_headers=TEST_LIST_HEADERS, with_metrics=False, brief=False)

    assert get_namespace_mock.call_count == 0
    assert api_list_runs_mock.call_count == 1, "Runs were not retrieved"
Example #6
0
def test_list_experiments_failure(mocker):
    api_list_runs_mock = mocker.patch("commands.common.Run.list")
    api_list_runs_mock.side_effect = RuntimeError

    get_namespace_mock = mocker.patch("commands.common.get_kubectl_current_context_namespace")
    sys_exit_mock = mocker.patch.object(common, "exit")

    common.list_runs_in_cli(verbosity_lvl=0, all_users=False, name="", status=None, listed_runs_kinds=[],
                            runs_list_headers=TEST_LIST_HEADERS, with_metrics=False, brief=False)

    assert get_namespace_mock.call_count == 1
    assert api_list_runs_mock.call_count == 1, "Runs retrieval was not called"
    assert sys_exit_mock.called_once_with(1)