def get_run_impl_(run_id: str): if run_id in ( str(registered_offline_exp.id), get_qualified_name(registered_offline_exp), ): return registered_offline_exp else: return get_run_impl(run_id)
def test_sync_all_runs(tmp_path, mocker, capsys): # given unsync_proj, sync_proj, _ = prepare_projects(tmp_path) unsync_exp, sync_exp, _ = prepare_runs(tmp_path) get_run_impl = generate_get_run_impl( (unsync_proj, sync_proj, unsync_exp, sync_exp)) offline_exp_uuid = prepare_offline_run(tmp_path) registered_offline_run = a_run() # and mocker.patch.object(neptune.new.sync, "get_run", get_run_impl) mocker.patch.object(neptune.new.sync, "backend") mocker.patch.object(neptune.new.sync.backend, "execute_operations") mocker.patch.object( neptune.new.sync.backend, "get_project", lambda _: Project(str(uuid.uuid4()), "project", "workspace"), ) mocker.patch.object( neptune.new.sync, "register_offline_run", lambda project, container_type: (registered_offline_run, True), ) mocker.patch.object(Operation, "from_dict", lambda x: x) neptune.new.sync.backend.execute_operations.return_value = (1, []) # when sync_all_runs(tmp_path, "foo") # then captured = capsys.readouterr() assert captured.err == "" assert ("Offline run {} registered as {}".format( offline_exp_uuid, get_qualified_name(registered_offline_run))) in captured.out assert "Synchronising {}".format( get_qualified_name(unsync_exp)) in captured.out assert "Synchronising {}".format( get_qualified_name(unsync_proj)) in captured.out assert ("Synchronization of run {} completed.".format( get_qualified_name(unsync_exp)) in captured.out) assert ("Synchronization of project {} completed.".format( get_qualified_name(unsync_proj)) in captured.out) assert "Synchronising {}".format( get_qualified_name(sync_exp)) not in captured.out assert "Synchronising {}".format( get_qualified_name(sync_proj)) not in captured.out # and # pylint: disable=no-member neptune.new.sync.backend.execute_operations.has_calls( [ mocker.call(unsync_exp.id, ContainerType.RUN, ["op-1"]), mocker.call(registered_offline_run.id, ContainerType.RUN, ["op-1"]), mocker.call(unsync_proj.id, ContainerType.PROJECT, ["op-proj-1"]), ], any_order=True, )
def test_sync_selected_runs(tmp_path, mocker, capsys): # given unsync_exp, sync_exp, get_run_impl = prepare_runs(tmp_path) offline_exp_uuid = prepare_offline_run(tmp_path) registered_offline_exp = a_run() def get_run_impl_(run_id: str): if run_id in ( str(registered_offline_exp.id), get_qualified_name(registered_offline_exp), ): return registered_offline_exp else: return get_run_impl(run_id) # and mocker.patch.object(neptune.new.sync, "get_run", get_run_impl_) mocker.patch.object(neptune.new.sync, "backend") mocker.patch.object(neptune.new.sync.backend, "execute_operations") mocker.patch.object( neptune.new.sync.backend, "get_project", lambda _: Project(str(uuid.uuid4()), "project", "workspace"), ) mocker.patch.object( neptune.new.sync, "register_offline_run", lambda project, container_type: (registered_offline_exp, True), ) mocker.patch.object(Operation, "from_dict", lambda x: x) neptune.new.sync.backend.execute_operations.return_value = (2, []) # when sync_selected_runs( tmp_path, "some-name", [get_qualified_name(sync_exp), "offline/" + offline_exp_uuid], ) # then captured = capsys.readouterr() assert captured.err == "" assert "Synchronising {}".format( get_qualified_name(sync_exp)) in captured.out assert ("Synchronization of run {} completed.".format( get_qualified_name(sync_exp)) in captured.out) assert ("Synchronising {}".format( get_qualified_name(registered_offline_exp)) in captured.out) assert ("Synchronization of run {} completed.".format( get_qualified_name(registered_offline_exp)) in captured.out) assert "Synchronising {}".format( get_qualified_name(unsync_exp)) not in captured.out # and # pylint: disable=no-member neptune.new.sync.backend.execute_operations.assert_called_with( registered_offline_exp.id, ContainerType.RUN, operations=["op-0", "op-1"])
def test_list_runs(tmp_path, mocker, capsys): # given unsync_exp, sync_exp, get_run_impl = prepare_runs(tmp_path) offline_exp_uuid = prepare_offline_run(tmp_path) # and mocker.patch.object(neptune.new.sync, "get_run", get_run_impl) mocker.patch.object(Operation, "from_dict") # when synchronization_status(tmp_path) # then captured = capsys.readouterr() assert captured.err == "" assert ("Synchronized runs:\n- {}".format(get_qualified_name(sync_exp)) in captured.out) assert ("Unsynchronized runs:\n- {}".format(get_qualified_name(unsync_exp)) in captured.out) assert ( "Unsynchronized offline runs:\n- offline/{}".format(offline_exp_uuid) in captured.out)
def test_list_projects(tmp_path, mocker, capsys): """TODO: we're mentioning projects as runs, will be improved with ModelRegistry""" # given unsync_proj, sync_proj, get_exp_impl = prepare_projects(tmp_path) offline_exp_uuid = prepare_offline_run(tmp_path) # and mocker.patch.object(neptune.new.sync, "get_run", get_exp_impl) mocker.patch.object(Operation, "from_dict") # when synchronization_status(tmp_path) # then captured = capsys.readouterr() assert captured.err == "" assert ("Synchronized runs:\n- {}".format(get_qualified_name(sync_proj)) in captured.out) assert ("Unsynchronized runs:\n- {}".format( get_qualified_name(unsync_proj)) in captured.out) assert ( "Unsynchronized offline runs:\n- offline/{}".format(offline_exp_uuid) in captured.out)
def get_run_impl(run_id): """This function will return run as well as projects. Will be cleaned in ModelRegistry""" for exp in registered_experiments: if run_id in (str(exp.id), get_qualified_name(exp)): return exp