Exemple #1
0
def test_push_success(request_mocker, upload_url, query_project, upsert_run):
    query_project(request_mocker)
    upload_url(request_mocker)
    update_mock = upsert_run(request_mocker)
    with CliRunner().isolated_filesystem():
        res = os.mkdir("wandb")
        # TODO: need this for my mock to work
        api = internal.Api(load_settings=False)
        with open("wandb/latest.yaml", "w") as f:
            f.write(
                yaml.dump({
                    'wandb_version': 1,
                    'test': {
                        'value': 'success',
                        'desc': 'My life'
                    }
                }))
        with open("weights.h5", "w") as f:
            f.write("weight")
        with open("model.json", "w") as f:
            f.write("model")
        res = api.push(["weights.h5", "model.json"],
                       entity='test',
                       project='test')
    assert res[0].status_code == 200
Exemple #2
0
def test_push_no_project(request_mocker, upload_url, query_project):
    query_project(request_mocker)
    upload_url(request_mocker)
    if os.getenv("WANDB_PROJECT"):
        del os.environ["WANDB_PROJECT"]
    with pytest.raises(wandb.Error):
        api = internal.Api(load_settings=False)
        print("WTF", api.settings("project"))
        res = api.push(["weights.json"], entity='test')
Exemple #3
0
    def use_artifact(self, artifact_or_name, type=None, aliases=None):
        """ Declare an artifact as an input to a run, call `download` or `file` on \
        the returned object to get the contents locally.

        Args:
            artifact_or_name (str or Artifact): An artifact name.
            May be prefixed with entity/project. Valid names
                can be in the following forms:
                    name:version
                    name:alias
                    digest
                You can also pass an Artifact object created by calling `wandb.Artifact`
            type (str, optional): The type of artifact to use.
            aliases (list, optional): Aliases to apply to this artifact
        Returns:
            A :obj:`Artifact` object.
        """
        r = self._run_obj
        api = internal.Api(default_settings={"entity": r.entity, "project": r.project})
        api.set_current_run_id(self.id)

        if isinstance(artifact_or_name, str):
            name = artifact_or_name
            if type is None:
                raise ValueError("type required")
            public_api = public.Api(
                {"entity": r.entity, "project": r.project, "run": self.id}
            )
            artifact = public_api.artifact(type=type, name=name)
            if type is not None and type != artifact.type:
                raise ValueError(
                    "Supplied type {} does not match type {} of artifact {}".format(
                        type, artifact.type, artifact.name
                    )
                )
            api.use_artifact(artifact.id)
            return artifact
        else:
            artifact = artifact_or_name
            if type is not None:
                raise ValueError("cannot specify type when passing Artifact object")
            if isinstance(aliases, str):
                aliases = [aliases]
            if isinstance(artifact_or_name, wandb.Artifact):
                artifact.finalize()
                self._backend.interface.send_artifact(
                    self, artifact, aliases, is_user_created=True, use_after_commit=True
                )
                return artifact
            elif isinstance(artifact, public.Artifact):
                api.use_artifact(artifact.id)
                return artifact
            else:
                raise ValueError(
                    'You must pass an artifact name (e.g. "pedestrian-dataset:v1"), an instance of wandb.Artifact, or wandb.Api().artifact() to use_artifact'  # noqa: E501
                )
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
def test_default_settings():
    os.environ.pop('WANDB_ENTITY', None)
    os.environ.pop('WANDB_PROJECT', None)
    assert internal.Api({'base_url': 'http://localhost'}, load_settings=False).settings() == {
        'base_url': 'http://localhost',
        'entity': None,
        'section': 'default',
        'run': 'latest',
        # TODO(adrian): it looks like this test interacts with test_settings. sometimes we get 'ignore_globs': ['*.patch']
        'ignore_globs': [],
        'git_remote': 'origin',
        'project': None,
    }
Exemple #6
0
def test_default_settings():
    os.environ.pop('WANDB_ENTITY', None)
    os.environ.pop('WANDB_PROJECT', None)
    assert internal.Api({
        'base_url': 'http://localhost'
    }, load_settings=False).settings() == {
        'base_url': 'http://localhost',
        'entity': None,
        'section': 'default',
        'run': 'latest',
        'ignore_globs': [],
        'git_remote': 'origin',
        'project': None,
    }
def test_default_settings():
    os.environ.pop(env.ENTITY, None)
    os.environ.pop(env.PROJECT, None)
    os.environ.pop(env.IGNORE, None)
    os.environ.pop(env.BASE_URL, None)

    assert internal.Api({
        'base_url': 'http://localhost'
    }, load_settings=False).settings() == {
        'base_url': 'http://localhost',
        'entity': None,
        'section': Settings.DEFAULT_SECTION,
        # TODO(adrian): it looks like this test interacts with test_settings. sometimes we get 'ignore_globs': ['*.patch']
        'ignore_globs': [],
        'git_remote': 'origin',
        'project': None,
    }
Exemple #8
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
Exemple #9
0
def test_dynamic_settings():
    assert internal.Api({}).dynamic_settings == {
        'heartbeat_seconds': 30,
        'system_sample_seconds': 2,
        'system_samples': 15
    }
Exemple #10
0
"""
import datetime
import pytest
import os
import yaml
from .api_mocks import *
from click.testing import CliRunner
import git
from .utils import git_repo

import requests
import wandb
from wandb.apis import internal
from six import StringIO

api = internal.Api(load_settings=False,
                   retry_timedelta=datetime.timedelta(0, 0, 50))


def test_projects_success(request_mocker, query_projects):
    query_projects(request_mocker)
    res = api.list_projects()
    assert len(res) == 3


def test_projects_failure(request_mocker, query_projects):
    query_projects(request_mocker,
                   status_code=400,
                   error=[{
                       'message': "Bummer"
                   }])
    with pytest.raises(wandb.Error):
Exemple #11
0
def internal_api():
    global api
    api = internal.Api(load_settings=False,
                       retry_timedelta=datetime.timedelta(0, 0, 50))
Exemple #12
0
def test_agent_heartbeat_with_no_agent_id_fails(test_settings):
    a = internal.Api()
    with pytest.raises(ValueError):
        a.agent_heartbeat(None, {}, {})