diff --git a/.gitignore b/.gitignore index db370f1aa..e50eff2c3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ *.pkl *.lock +# OS generated files +.DS_Store + # StarUML documentation *.mdj diff --git a/src/orion/core/cli/list.py b/src/orion/core/cli/list.py index 448a1ae89..7684fe3b8 100644 --- a/src/orion/core/cli/list.py +++ b/src/orion/core/cli/list.py @@ -46,6 +46,10 @@ def main(args): root_experiments = [exp for exp in experiments if exp['refers'].get('root_id', exp['_id']) == exp['_id']] + if not root_experiments: + print("No experiment found") + return + for root_experiment in root_experiments: root = experiment_builder.build_view(name=root_experiment['name'], version=root_experiment.get('version')).node diff --git a/src/orion/core/cli/status.py b/src/orion/core/cli/status.py index 89aa6d82b..ff8c6a04e 100644 --- a/src/orion/core/cli/status.py +++ b/src/orion/core/cli/status.py @@ -68,7 +68,7 @@ def main(args): raise RuntimeError("Cannot fetch specific version of experiments with --collapse " "or --expand-versions.") - print_evc(filter(lambda e: e.refers.get('parent_id') is None, experiments), **args) + print_evc(experiments, **args) # pylint: disable=unused-argument @@ -104,13 +104,19 @@ def get_experiments(args): Commandline arguments. """ - projection = {'name': 1, 'version': 1} + projection = {'name': 1, 'version': 1, 'refers': 1} query = {'name': args['name']} if args.get('name') else {} experiments = get_storage().fetch_experiments(query, projection) + if args['name']: + root_experiments = experiments + else: + root_experiments = [exp for exp in experiments + if exp['refers'].get('root_id', exp['_id']) == exp['_id']] + return [experiment_builder.build_view(name=exp['name'], version=exp.get('version', 1)) - for exp in experiments] + for exp in root_experiments] def _has_named_children(exp): diff --git a/tests/functional/commands/test_list_command.py b/tests/functional/commands/test_list_command.py index 5b9442410..ed4bff4cc 100644 --- a/tests/functional/commands/test_list_command.py +++ b/tests/functional/commands/test_list_command.py @@ -13,7 +13,7 @@ def test_no_exp(monkeypatch, clean_db, capsys): captured = capsys.readouterr().out - assert captured == "" + assert captured == "No experiment found\n" def test_single_exp(clean_db, one_experiment, capsys): @@ -84,7 +84,7 @@ def test_no_exp_name(clean_db, three_experiments, monkeypatch, capsys): captured = capsys.readouterr().out - assert captured == "" + assert captured == "No experiment found\n" def test_exp_name(clean_db, three_experiments, monkeypatch, capsys): diff --git a/tests/functional/commands/test_status_command.py b/tests/functional/commands/test_status_command.py index 0fb460ad8..f38ffb44a 100644 --- a/tests/functional/commands/test_status_command.py +++ b/tests/functional/commands/test_status_command.py @@ -93,6 +93,35 @@ def test_experiment_wout_success_wout_ac(clean_db, single_without_success, capsy assert captured == expected +def test_experiment_number_same_list_status(clean_db, + single_without_success, capsys): + """Test status and list command output the consistent number of experiments""" + orion.core.cli.main(['status']) + + captured = capsys.readouterr().out + + expected = """\ +test_single_exp-v1 +================== +status quantity +----------- ---------- +broken 1 +interrupted 1 +new 1 +reserved 1 +suspended 1 + + +""" + assert captured == expected + + orion.core.cli.main(['list']) + + captured = capsys.readouterr().out + + assert captured == " test_single_exp-v1\n" + + def test_experiment_w_trials_wout_ac(clean_db, single_with_trials, capsys): """Test status with only one experiment and all trials.""" orion.core.cli.main(['status'])