Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_branch_from_selected_version(clean_db, monkeypatch, database):
"""Test that branching from a version passed with `--version` works."""
monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__)))
orion.core.cli.main("init_only -n experiment ./black_box.py -x~normal(0,1)".split(" "))
orion.core.cli.main("init_only -n experiment ./black_box.py -x~normal(0,1) -y~+normal(0,1)"
.split(" "))
orion.core.cli.main("init_only -n experiment --version 1 -b experiment_2 ./black_box.py "
"-x~normal(0,1) -z~+normal(0,1)".split(" "))
parent = database.experiments.find({'name': 'experiment', 'version': 1})[0]
exp = database.experiments.find({'name': 'experiment_2'})[0]
assert exp['refers']['parent_id'] == parent['_id']
def test_experiment_w_child_w_name(clean_db, three_experiments_with_trials, capsys):
"""Test status with the name argument and one child."""
orion.core.cli.main(['status', '--name', 'test_double_exp'])
captured = capsys.readouterr().out
expected = """\
test_double_exp-v1
==================
status quantity
----------- ----------
broken 1
completed 1
interrupted 1
new 1
reserved 1
suspended 1
def test_no_args(capsys):
"""Test that help is printed when no args are given."""
with pytest.raises(SystemExit):
orion.core.cli.main(['init_only'])
captured = capsys.readouterr().out
assert 'usage:' in captured
assert 'Traceback' not in captured
def test_two_related_w_ac(clean_db, family_with_trials, capsys):
"""Test two related experiments with --collapse and --all."""
orion.core.cli.main(['status', '--collapse', '--all'])
captured = capsys.readouterr().out
expected = """\
test_double_exp-v1
==================
id status
-------------------------------- -----------
c2187f4954884c801e423d851aec9a0b broken
e42cc22a15188d72df315b9eac79c9c0 completed
b849f69cc3a77f39382d7435d0d41b14 interrupted
7fbbd152f7ca2c064bf00441e311609d new
d5f1c1cae188608b581ded20cd198679 new
667513aa2cb2244bee9c4f41c7ff1cea reserved
557b9fdb9f96569dff7eb2de10d3946f suspended
def test_experiment_same_name_wout_exv_w_c_w_child_w_name(
clean_db, three_experiments_family_same_name, capsys):
"""Test status name collapsed with two experiments having the same name and one with a child."""
orion.core.cli.main(['status', '--name', 'test_single_exp', '--collapse'])
captured = capsys.readouterr().out
expected = """\
test_single_exp-v2
==================
empty
"""
assert captured == expected
def test_experiment_same_name_w_exv_w_child(clean_db, three_experiments_family_same_name, capsys):
"""Test status with two experiments having the same name and one with a child."""
orion.core.cli.main(['status', '--expand-versions'])
captured = capsys.readouterr().out
expected = """\
test_single_exp-v1
==================
empty
test_single_exp-v2
==================
empty
test_single_exp_child-v1
========================
def test_creation_when_not_existing(monkeypatch, tmp_path):
"""Test if a configuration file is created when it does not exist."""
config_path = str(tmp_path) + "/tmp_config.yaml"
monkeypatch.setattr(orion.core, "DEF_CONFIG_FILES_PATHS", [config_path])
monkeypatch.setattr(builtins, "input", _mock_input(['type', 'name', 'host']))
try:
os.remove(config_path)
except FileNotFoundError:
pass
orion.core.cli.main(["db", "setup"])
assert os.path.exists(config_path)
with open(config_path, 'r') as output:
content = yaml.safe_load(output)
assert content == {"database": {"type": "type", "name": "name", "host": "host"}}
monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__)))
orion.core.cli.main(["init_only", "-n", "experiment",
"-c", "./orion_config_random.yaml", script_path, "-x~normal(0,1)"])
orion.core.cli.main(["init_only", "-n", "experiment",
"-c", "./orion_config_random.yaml", script_path, "-x~normal(0,1)",
"-y~+normal(0,1)"])
exp = list(get_storage().fetch_experiments({"name": "experiment", "version": 1}))
assert len(exp) == 1
exp = exp[0]
assert '_id' in exp
trials = list(get_storage().fetch_trials(uid=exp['_id']))
assert len(trials) == 0
orion.core.cli.main(["insert", "-n", "experiment", "--version", "1",
"-c", "./orion_config_random.yaml", script_path, "-x=1"])
trials = list(get_storage().fetch_trials(uid=exp['_id']))
assert len(trials) == 1
def test_insert_two_hyperparameters(database, monkeypatch):
"""Try to insert a single trial with two hyperparameters"""
monkeypatch.chdir(os.path.dirname(os.path.abspath(__file__)))
monkeypatch.setattr("getpass.getuser", get_user_corneau)
orion.core.cli.main(["insert", "-n", "test_insert_two_hyperparameters",
"-c", "./orion_config_random.yaml", "./black_box.py", "-x=1", "-y=2"])
exp = list(database.experiments.find({"name": "test_insert_two_hyperparameters"}))
assert len(exp) == 1
exp = exp[0]
assert '_id' in exp
trials = list(database.trials.find({"experiment": exp['_id']}))
assert len(trials) == 1
trial = trials[0]
assert trial['status'] == 'new'
assert trial['params'][0]['value'] == 1
assert trial['params'][1]['value'] == 2
def test_two_exp(capsys, clean_db, two_experiments):
"""Test that experiment and child are printed."""
orion.core.cli.main(['list'])
captured = capsys.readouterr().out
assert captured == """\
test_double_exp-v1┐