def test_load_workspace(): with NamedTemporaryFile(suffix="yaml", mode='w') as workspace: workspace.write("experiments:\n") workspace.write(" chaosiq:\n") workspace.write(" test:\n") workspace.write(" dummy.json:\n") workspace.write(" experiment_id: azerty123456\n") workspace.seek(0) load_workspace(workspace.name) data = get_loaded_workspace_data() assert data == { "experiments": { "chaosiq": { "test": { "dummy.json": { "experiment_id": "azerty123456" } } } } } # clean up reset_workspace()
def test_set_workspace_data(): data = {"dummy": "data"} set_workspace_data(data) assert get_loaded_workspace_data() == data # clean up reset_workspace()
def test_get_loaded_workspace_data_cannot_be_mutated(): set_workspace_data({"dummy": "data"}) data1 = get_loaded_workspace_data() data2 = get_loaded_workspace_data() assert data1 == data2 # mutate one of the data dict and check the other one is not # neither the global workspace variable data1["extra"] = "value" assert data1 != data2 assert data1 != workspace_metadata assert data1 != get_loaded_workspace_data() assert data2 == get_loaded_workspace_data() # clean up reset_workspace()
def test_register_experiment(mock_exists, organizations, default_org_id, default_team_id): mock_exists.return_value = True experiment = { "title": "hello", "extensions": [{ "name": "chaosiq", "experiment_id": "azerty123456", "experiment_path": "/tmp/experiment.json" }] } register_experiment_to_workspace(experiment, organizations) assert get_loaded_workspace_data() != {} data = get_loaded_workspace_data() assert "experiment.json" in \ data["experiments"][default_org_id][default_team_id] # clean up reset_workspace()
def test_load_workspace_invalid_path(): load_workspace('/tmp/invalid') assert get_loaded_workspace_data() in EMPTY_VALUES
def test_reset_workspace_data(): set_workspace_data({"dummy": "data"}) assert get_loaded_workspace_data() not in EMPTY_VALUES reset_workspace() assert get_loaded_workspace_data() in EMPTY_VALUES
def test_register_experiment_path_does_not_exist(): experiment = {"title": "hello"} register_experiment_to_workspace(experiment, [], '/tmp/experiment.json') assert get_loaded_workspace_data() == {}
def test_register_experiment_without_path(): experiment = {"title": "hello"} register_experiment_to_workspace(experiment, []) assert get_loaded_workspace_data() == {}