Exemplo n.º 1
0
def fake_run_manager(mocker,
                     run=None,
                     cloud=True,
                     rm_class=wandb.run_manager.RunManager):
    # NOTE: This will create a run directory so make sure it's called in an isolated file system
    # We have an optional rm_class object because we mock it above so we need it before it's mocked
    api = InternalApi(load_settings=False)
    api.set_setting('project', 'testing')

    if wandb.run is None:
        wandb.run = run or Run()
        wandb.config = wandb.run.config
    wandb.run._api = api
    wandb.run._mkdir()
    wandb.run.socket = wandb_socket.Server()
    api.set_current_run_id(wandb.run.id)
    mocker.patch('wandb.apis.internal.FileStreamApi')
    api._file_stream_api = mocker.MagicMock()
    run_manager = rm_class(wandb.run, cloud=cloud, port=wandb.run.socket.port)

    class FakeProc(object):
        def poll(self):
            return None

        def exit(self, code=0):
            return None

    run_manager.proc = FakeProc()
    run_manager._meta = mocker.MagicMock()
    run_manager._stdout_tee = mocker.MagicMock()
    run_manager._stderr_tee = mocker.MagicMock()
    run_manager._output_log = mocker.MagicMock()
    run_manager._stdout_stream = mocker.MagicMock()
    run_manager._stderr_stream = mocker.MagicMock()
    run_manager.mirror_stdout_stderr = mocker.MagicMock()
    run_manager.unmirror_stdout_stderr = mocker.MagicMock()
    socket_thread = threading.Thread(target=wandb.run.socket.listen)
    socket_thread.start()
    run_manager._socket.ready()
    thread = threading.Thread(target=run_manager._sync_etc)
    thread.daemon = True
    thread.start()

    def test_shutdown():
        if wandb.run and wandb.run.socket:
            wandb.run.socket.done()
            # TODO: is this needed?
            socket_thread.join()
            thread.join()

    run_manager.test_shutdown = test_shutdown
    run_manager._unblock_file_observer()
    run_manager._file_pusher._push_function = mocker.MagicMock()
    return run_manager
Exemplo n.º 2
0
def test_init_run_network_down(mocker, caplog):
    with CliRunner().isolated_filesystem():
        mocker.patch("wandb.apis.internal.Api.HTTP_TIMEOUT", 0.5)
        api = internal.Api(load_settings=False,
                           retry_timedelta=datetime.timedelta(0, 0, 50))
        api.set_current_run_id(123)
        run = Run()
        mocker.patch("wandb.run_manager.RunManager._upsert_run",
                     lambda *args: time.sleep(0.6))
        rm = wandb.run_manager.RunManager(run)
        step = rm.init_run()
        assert step == 0
        assert "Failed to connect" in caplog.text
Exemplo n.º 3
0
def test_code_path_in_config(mocker, git_repo):
    mocker.patch('wandb._get_python_type', lambda: "jupyter")
    os.environ[env.NOTEBOOK_NAME] = "test.ipynb"
    with open("test.ipynb", "w") as f:
        f.write("{}")
    run = Run()
    run.config.set_run_dir(run.dir)
    run_manager = wandb.run_manager.RunManager(run)
    config_path = os.path.join(run.dir, "config.yaml")
    assert run.config["_wandb"]['code_path'] == "code/test.ipynb"
    print(glob.glob(run.dir + "/*"))
    assert yaml.load(
        open(config_path))["_wandb"]["value"]["code_path"] == "code/test.ipynb"
Exemplo n.º 4
0
def _is_update_avail(request_mocker, capsys, current, latest):
    "Set up the run manager and detect if the upgrade message is printed."
    api = internal.Api(
        load_settings=False,
        retry_timedelta=datetime.timedelta(0, 0, 50))
    api.set_current_run_id(123)
    run = Run()
    run_manager = wandb.run_manager.RunManager(api, run)

    # Without this mocking, during other tests, the _check_update_available
    # function will throw a "mock not found" error, then silently fail without
    # output (just like it would in a normal network failure).
    response = b'{ "info": { "version": "%s" } }' % bytearray(latest, 'utf-8')
    request_mocker.register_uri('GET', 'https://pypi.org/pypi/wandb/json',
                                content=response, status_code=200)
    run_manager._check_update_available(current)

    captured_out, captured_err = capsys.readouterr()
    print(captured_out, captured_err)
    return "To upgrade, please run:" in captured_err
Exemplo n.º 5
0
def history():
    with CliRunner().isolated_filesystem():
        yield Run().history