id int64 1 6.07M | name stringlengths 1 295 | code stringlengths 12 426k | language stringclasses 1
value | source_file stringlengths 5 202 | start_line int64 1 158k | end_line int64 1 158k | repo dict |
|---|---|---|---|---|---|---|---|
301 | write_file | def write_file(fname):
with open(fname, "w") as fp:
fp.write("data") | python | tests/functional_tests/t0_main/save/save-glob.py | 33 | 35 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
302 | test_save_glob | def test_save_glob():
with tempfile.TemporaryDirectory() as tmpdir:
dirname = os.path.join(tmpdir, "newdir")
glob = os.path.join(dirname, "*.txt")
os.mkdir(dirname)
write_file(os.path.join(tmpdir, "newdir", "newfile1.txt"))
write_file(os.path.join(tmpdir, "newdir", "newfile2.csv"))
write_file(os.path.join(tmpdir, "newdir", "newfile3.txt"))
with wandb.init() as run:
run.config.id = "save_glob"
run.save(glob, base_path=tmpdir) | python | tests/functional_tests/t0_main/save/save-glob.py | 38 | 48 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
303 | test_save_glob_later | def test_save_glob_later():
"""If you add files later, wandb.save() does not pick them up."""
with tempfile.TemporaryDirectory() as tmpdir:
dirname = os.path.join(tmpdir, "newdir")
glob = os.path.join(dirname, "*.txt")
os.mkdir(dirname)
write_file(os.path.join(tmpdir, "newdir", "newfile1.txt"))
with wandb.init() as run:
run.config.id = "save_glob_later"
run.save(glob, base_path=tmpdir)
write_file(os.path.join(tmpdir, "newdir", "newfile2.csv"))
write_file(os.path.join(tmpdir, "newdir", "newfile3.txt")) | python | tests/functional_tests/t0_main/save/save-glob.py | 51 | 62 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
304 | main | def main():
test_save_glob()
test_save_glob_later() | python | tests/functional_tests/t0_main/save/save-glob.py | 65 | 67 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
305 | write_file | def write_file(fname):
with open(fname, "w") as fp:
fp.write("data") | python | tests/functional_tests/t0_main/save/save-dir.py | 22 | 24 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
306 | test_save_dir | def test_save_dir():
"""NOTE: this is demonstrating broken functionality."""
with tempfile.TemporaryDirectory() as tmpdir:
dirname = os.path.join(tmpdir, "newdir")
fname = os.path.join(tmpdir, "newdir", "newfile.txt")
os.mkdir(dirname)
write_file(fname)
with wandb.init() as run:
run.config.id = "save_dir"
run.save(dirname, base_path=tmpdir) | python | tests/functional_tests/t0_main/save/save-dir.py | 27 | 36 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
307 | main | def main():
test_save_dir() | python | tests/functional_tests/t0_main/save/save-dir.py | 39 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
308 | write_file | def write_file(fname):
with open(fname, "w") as fp:
fp.write("data") | python | tests/functional_tests/t0_main/save/save-files.py | 23 | 25 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
309 | test_save_file | def test_save_file():
with tempfile.TemporaryDirectory() as tmpdir:
fname = os.path.join(tmpdir, "newfile.txt")
write_file(fname)
with wandb.init() as run:
run.config.id = "save_file"
run.save(fname, base_path=tmpdir) | python | tests/functional_tests/t0_main/save/save-files.py | 28 | 34 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
310 | test_save_file_in_dir | def test_save_file_in_dir():
with tempfile.TemporaryDirectory() as tmpdir:
dirname = os.path.join(tmpdir, "newdir")
fname = os.path.join(tmpdir, "newdir", "newfile.txt")
os.mkdir(dirname)
write_file(fname)
with wandb.init() as run:
run.config.id = "save_file_in_dir"
run.save(fname, base_path=tmpdir) | python | tests/functional_tests/t0_main/save/save-files.py | 37 | 45 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
311 | main | def main():
test_save_file()
test_save_file_in_dir() | python | tests/functional_tests/t0_main/save/save-files.py | 48 | 50 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
312 | main | def main():
# import here so we can profile how long it takes
import wandb
run = wandb.init()
for _ in range(1000):
wandb.log(dict(this=2))
run.finish() | python | tests/functional_tests/t0_main/perf/t1_basic.py | 5 | 12 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
313 | main | def main():
parser = argparse.ArgumentParser()
parser.add_argument("--output-total", type=int, default=10)
parser.add_argument("--output-chunk", type=int, default=10)
args = parser.parse_args()
run = wandb.init()
for i in range(args.output_total):
for _ in range(args.output_chunk):
sys.stdout.write(".")
sys.stdout.write(f"{i}\r")
sys.stdout.write("\n")
run.finish() | python | tests/functional_tests/t0_main/perf/console_output.py | 9 | 21 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
314 | main | def main():
parser = argparse.ArgumentParser()
parser.add_argument("--num-epochs", type=int, default=10)
parser.add_argument("--num-scalers", type=int, default=10)
args = parser.parse_args()
run = wandb.init()
for i in range(args.num_epochs):
data = {}
for j in range(args.num_scalers):
data[f"m-{j}"] = j * i
wandb.log(data)
run.finish() | python | tests/functional_tests/t0_main/perf/log_data.py | 8 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
315 | main | def main():
third_party_sentry_events = []
# store events in a list instead of sending them to Sentry
def capture_event(event: Dict[str, Any]) -> None:
if "exception" in event:
third_party_sentry_events.append(event)
# this should not interfere with our Sentry integration
sentry_sdk.init(transport=capture_event)
import wandb
import wandb.env
# assert that importing wandb does not set Sentry's global hub/client
assert sentry_sdk.Hub.current.client.dsn != wandb._sentry.dsn
# but an internal Sentry client for wandb is created ok if WANDB_ERROR_REPORTING != False
if wandb.env.error_reporting_enabled():
assert isinstance(wandb._sentry.hub, sentry_sdk.hub.Hub)
run = wandb.init()
# raise two exceptions and capture them with the third-party sentry client
for i in range(2):
try:
print(
f"Raising exception #{i + 1} to be captured by third-party sentry client"
)
raise ValueError("Catch me if you can!")
except ValueError:
sentry_sdk.capture_exception()
num_third_party_sentry_events = len(third_party_sentry_events)
run.log({"num_third_party_sentry_events": num_third_party_sentry_events})
time.sleep(2)
# Triggers a FileNotFoundError from the internal process
# because the internal process reads/writes to the current run directory.
shutil.rmtree(run.dir)
try:
run.log({"data": 5})
except FileNotFoundError:
pass
# no new events should be captured
assert num_third_party_sentry_events == len(third_party_sentry_events) | python | tests/functional_tests/t0_main/debug/sentry_third_party.py | 9 | 55 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
316 | capture_event | def capture_event(event: Dict[str, Any]) -> None:
if "exception" in event:
third_party_sentry_events.append(event) | python | tests/functional_tests/t0_main/debug/sentry_third_party.py | 13 | 15 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
317 | assets_path | def assets_path() -> Generator[Callable, None, None]:
def assets_path_fn(path: Path) -> Path:
return Path(__file__).resolve().parent / "assets" / path
yield assets_path_fn | python | tests/pytest_tests/conftest.py | 28 | 32 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
318 | assets_path_fn | def assets_path_fn(path: Path) -> Path:
return Path(__file__).resolve().parent / "assets" / path | python | tests/pytest_tests/conftest.py | 29 | 30 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
319 | copy_asset | def copy_asset(assets_path) -> Generator[Callable, None, None]:
def copy_asset_fn(
path: Union[str, Path], dst: Union[str, Path, None] = None
) -> Path:
src = assets_path(path)
if src.is_file():
return shutil.copy(src, dst or path)
return shutil.copytree(src, dst or path)
yield copy_asset_fn | python | tests/pytest_tests/conftest.py | 36 | 45 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
320 | copy_asset_fn | def copy_asset_fn(
path: Union[str, Path], dst: Union[str, Path, None] = None
) -> Path:
src = assets_path(path)
if src.is_file():
return shutil.copy(src, dst or path)
return shutil.copytree(src, dst or path) | python | tests/pytest_tests/conftest.py | 37 | 43 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
321 | filesystem_isolate | def filesystem_isolate(tmp_path):
# Click>=8 implements temp_dir argument which depends on python>=3.7
kwargs = dict(temp_dir=tmp_path) if sys.version_info >= (3, 7) else {}
with CliRunner().isolated_filesystem(**kwargs):
yield | python | tests/pytest_tests/conftest.py | 54 | 58 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
322 | local_settings | def local_settings(filesystem_isolate):
"""Place global settings in an isolated dir."""
config_path = os.path.join(os.getcwd(), ".config", "wandb", "settings")
filesystem.mkdir_exists_ok(os.path.join(".config", "wandb"))
# todo: this breaks things in unexpected places
# todo: get rid of wandb.old
with unittest.mock.patch.object(
wandb.old.settings.Settings,
"_global_path",
return_value=config_path,
):
yield | python | tests/pytest_tests/conftest.py | 63 | 75 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
323 | local_netrc | def local_netrc(filesystem_isolate):
"""Never use our real credentials, put them in their own isolated dir."""
original_expanduser = os.path.expanduser # TODO: this seems overkill...
open(".netrc", "wb").close() # Touch that netrc file
def expand(path):
if "netrc" in path:
try:
full_path = os.path.realpath("netrc")
except OSError:
full_path = original_expanduser(path)
else:
full_path = original_expanduser(path)
return full_path
# monkeypatch.setattr(os.path, "expanduser", expand)
with unittest.mock.patch.object(os.path, "expanduser", expand):
yield | python | tests/pytest_tests/conftest.py | 79 | 97 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
324 | expand | def expand(path):
if "netrc" in path:
try:
full_path = os.path.realpath("netrc")
except OSError:
full_path = original_expanduser(path)
else:
full_path = original_expanduser(path)
return full_path | python | tests/pytest_tests/conftest.py | 85 | 93 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
325 | dummy_api_key | def dummy_api_key():
return "1824812581259009ca9981580f8f8a9012409eee" | python | tests/pytest_tests/conftest.py | 101 | 102 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
326 | patch_apikey | def patch_apikey(dummy_api_key, mocker):
mocker.patch("wandb.wandb_lib.apikey.isatty", lambda stream: True)
mocker.patch("wandb.wandb_lib.apikey.input", lambda x: 1)
mocker.patch("wandb.wandb_lib.apikey.getpass", lambda x: dummy_api_key)
yield | python | tests/pytest_tests/conftest.py | 106 | 110 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
327 | patch_prompt | def patch_prompt(monkeypatch):
monkeypatch.setattr(
wandb.util, "prompt_choices", lambda x, input_timeout=None, jupyter=False: x[0]
)
monkeypatch.setattr(
wandb.wandb_lib.apikey,
"prompt_choices",
lambda x, input_timeout=None, jupyter=False: x[0],
) | python | tests/pytest_tests/conftest.py | 114 | 122 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
328 | runner | def runner(patch_apikey, patch_prompt):
return CliRunner() | python | tests/pytest_tests/conftest.py | 126 | 127 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
329 | git_repo | def git_repo(runner):
with runner.isolated_filesystem(), git.Repo.init(".") as repo:
filesystem.mkdir_exists_ok("wandb")
# Because the forked process doesn't use my monkey patch above
with open(os.path.join("wandb", "settings"), "w") as f:
f.write("[default]\nproject: test")
open("README", "wb").close()
repo.index.add(["README"])
repo.index.commit("Initial commit")
yield GitRepo(lazy=False) | python | tests/pytest_tests/conftest.py | 131 | 140 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
330 | unset_global_objects | def unset_global_objects():
from wandb.sdk.lib.module import unset_globals
yield
unset_globals() | python | tests/pytest_tests/conftest.py | 144 | 148 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
331 | env_teardown | def env_teardown():
wandb.teardown()
yield
wandb.teardown()
if not os.environ.get("CI") == "true":
# TODO: uncomment this for prod? better make controllable with an env var
# subprocess.run(["wandb", "server", "stop"])
pass | python | tests/pytest_tests/conftest.py | 152 | 159 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
332 | clean_up | def clean_up():
yield
wandb.teardown() | python | tests/pytest_tests/conftest.py | 163 | 165 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
333 | api | def api():
return Api() | python | tests/pytest_tests/conftest.py | 169 | 170 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
334 | record_q | def record_q() -> "Queue":
return Queue() | python | tests/pytest_tests/conftest.py | 179 | 180 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
335 | mocked_interface | def mocked_interface(record_q: "Queue") -> InterfaceQueue:
return InterfaceQueue(record_q=record_q) | python | tests/pytest_tests/conftest.py | 184 | 185 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
336 | mocked_backend | def mocked_backend(mocked_interface: InterfaceQueue) -> Generator[object, None, None]:
class MockedBackend:
def __init__(self) -> None:
self.interface = mocked_interface
yield MockedBackend() | python | tests/pytest_tests/conftest.py | 189 | 194 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
337 | __init__ | def __init__(self) -> None:
self.interface = mocked_interface | python | tests/pytest_tests/conftest.py | 191 | 192 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
338 | dict_factory | def dict_factory():
def helper():
return dict()
return helper | python | tests/pytest_tests/conftest.py | 197 | 201 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
339 | helper | def helper():
return dict() | python | tests/pytest_tests/conftest.py | 198 | 199 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
340 | test_settings | def test_settings():
def update_test_settings(
extra_settings: Union[
dict, wandb.sdk.wandb_settings.Settings
] = dict_factory() # noqa: B008
):
settings = wandb.Settings(
console="off",
save_code=False,
)
if isinstance(extra_settings, dict):
settings.update(extra_settings, source=wandb.sdk.wandb_settings.Source.BASE)
elif isinstance(extra_settings, wandb.sdk.wandb_settings.Settings):
settings.update(extra_settings)
settings._set_run_start_time()
return settings
yield update_test_settings | python | tests/pytest_tests/conftest.py | 205 | 222 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
341 | update_test_settings | def update_test_settings(
extra_settings: Union[
dict, wandb.sdk.wandb_settings.Settings
] = dict_factory() # noqa: B008
):
settings = wandb.Settings(
console="off",
save_code=False,
)
if isinstance(extra_settings, dict):
settings.update(extra_settings, source=wandb.sdk.wandb_settings.Source.BASE)
elif isinstance(extra_settings, wandb.sdk.wandb_settings.Settings):
settings.update(extra_settings)
settings._set_run_start_time()
return settings | python | tests/pytest_tests/conftest.py | 206 | 220 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
342 | mock_run | def mock_run(test_settings, mocked_backend) -> Generator[Callable, None, None]:
from wandb.sdk.lib.module import unset_globals
def mock_run_fn(use_magic_mock=False, **kwargs: Any) -> "wandb.sdk.wandb_run.Run":
kwargs_settings = kwargs.pop("settings", dict())
kwargs_settings = {
**{
"run_id": runid.generate_id(),
},
**kwargs_settings,
}
run = wandb.wandb_sdk.wandb_run.Run(
settings=test_settings(kwargs_settings), **kwargs
)
run._set_backend(
unittest.mock.MagicMock() if use_magic_mock else mocked_backend
)
run._set_globals()
return run
yield mock_run_fn
unset_globals() | python | tests/pytest_tests/conftest.py | 226 | 247 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
343 | mock_run_fn | def mock_run_fn(use_magic_mock=False, **kwargs: Any) -> "wandb.sdk.wandb_run.Run":
kwargs_settings = kwargs.pop("settings", dict())
kwargs_settings = {
**{
"run_id": runid.generate_id(),
},
**kwargs_settings,
}
run = wandb.wandb_sdk.wandb_run.Run(
settings=test_settings(kwargs_settings), **kwargs
)
run._set_backend(
unittest.mock.MagicMock() if use_magic_mock else mocked_backend
)
run._set_globals()
return run | python | tests/pytest_tests/conftest.py | 229 | 244 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
344 | __init__ | def __init__(self, queue: "Queue") -> None:
self.records = []
while not queue.empty():
self.records.append(queue.get()) | python | tests/pytest_tests/unit_tests/conftest.py | 12 | 15 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
345 | __len__ | def __len__(self) -> int:
return len(self.records) | python | tests/pytest_tests/unit_tests/conftest.py | 17 | 18 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
346 | __getitem__ | def __getitem__(self, name: str) -> Generator:
for record in self.records:
yield from self.resolve_item(record, name) | python | tests/pytest_tests/unit_tests/conftest.py | 20 | 22 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
347 | resolve_item | def resolve_item(obj, attr: str, sep: str = ".") -> List:
for name in attr.split(sep):
if not obj.HasField(name):
return []
obj = getattr(obj, name)
return [obj] | python | tests/pytest_tests/unit_tests/conftest.py | 25 | 30 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
348 | dictify | def dictify(obj, key: str = "key", value: str = "value_json") -> Dict:
return {getattr(item, key): getattr(item, value) for item in obj} | python | tests/pytest_tests/unit_tests/conftest.py | 33 | 34 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
349 | config | def config(self) -> List:
return [self.dictify(_c.update) for _c in self["config"]] | python | tests/pytest_tests/unit_tests/conftest.py | 37 | 38 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
350 | history | def history(self) -> List:
return [self.dictify(_h.item) for _h in self["history"]] | python | tests/pytest_tests/unit_tests/conftest.py | 41 | 42 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
351 | partial_history | def partial_history(self) -> List:
return [self.dictify(_h.item) for _h in self["request.partial_history"]] | python | tests/pytest_tests/unit_tests/conftest.py | 45 | 46 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
352 | preempting | def preempting(self) -> List:
return list(self["preempting"]) | python | tests/pytest_tests/unit_tests/conftest.py | 49 | 50 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
353 | summary | def summary(self) -> List:
return list(self["summary"]) | python | tests/pytest_tests/unit_tests/conftest.py | 53 | 54 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
354 | files | def files(self) -> List:
return list(self["files"]) | python | tests/pytest_tests/unit_tests/conftest.py | 57 | 58 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
355 | metric | def metric(self):
return list(self["metric"]) | python | tests/pytest_tests/unit_tests/conftest.py | 61 | 62 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
356 | parse_records | def parse_records() -> Generator[Callable, None, None]:
def records_parser_fn(q: "Queue") -> RecordsUtil:
return RecordsUtil(q)
yield records_parser_fn | python | tests/pytest_tests/unit_tests/conftest.py | 66 | 70 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
357 | records_parser_fn | def records_parser_fn(q: "Queue") -> RecordsUtil:
return RecordsUtil(q) | python | tests/pytest_tests/unit_tests/conftest.py | 67 | 68 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
358 | sklearn_model | def sklearn_model():
return svm.SVC() | python | tests/pytest_tests/unit_tests/saved_model_constructors.py | 12 | 13 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
359 | pytorch_model | def pytorch_model():
class PytorchModel(torch.nn.Module):
def __init__(self):
super().__init__()
self.hidden_layer = torch.nn.Linear(1, 1)
self.hidden_layer.weight = torch.nn.Parameter(torch.tensor([[1.58]]))
self.hidden_layer.bias = torch.nn.Parameter(torch.tensor([-0.14]))
self.output_layer = torch.nn.Linear(1, 1)
self.output_layer.weight = torch.nn.Parameter(torch.tensor([[2.45]]))
self.output_layer.bias = torch.nn.Parameter(torch.tensor([-0.11]))
def forward(self, x):
x = torch.sigmoid(self.hidden_layer(x))
x = torch.sigmoid(self.output_layer(x))
return x
return PytorchModel() | python | tests/pytest_tests/unit_tests/saved_model_constructors.py | 16 | 33 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
360 | __init__ | def __init__(self):
super().__init__()
self.hidden_layer = torch.nn.Linear(1, 1)
self.hidden_layer.weight = torch.nn.Parameter(torch.tensor([[1.58]]))
self.hidden_layer.bias = torch.nn.Parameter(torch.tensor([-0.14]))
self.output_layer = torch.nn.Linear(1, 1)
self.output_layer.weight = torch.nn.Parameter(torch.tensor([[2.45]]))
self.output_layer.bias = torch.nn.Parameter(torch.tensor([-0.11])) | python | tests/pytest_tests/unit_tests/saved_model_constructors.py | 18 | 26 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
361 | forward | def forward(self, x):
x = torch.sigmoid(self.hidden_layer(x))
x = torch.sigmoid(self.output_layer(x))
return x | python | tests/pytest_tests/unit_tests/saved_model_constructors.py | 28 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
362 | keras_model | def keras_model():
def get_model():
# Create a simple model.
inputs = keras.Input(shape=(32,))
outputs = keras.layers.Dense(1)(inputs)
model = keras.Model(inputs, outputs)
model.compile(optimizer="adam", loss="mean_squared_error")
return model
model = get_model()
# Train the model.
test_input = np.random.random((128, 32))
test_target = np.random.random((128, 1))
model.fit(test_input, test_target)
return model | python | tests/pytest_tests/unit_tests/saved_model_constructors.py | 36 | 52 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
363 | get_model | def get_model():
# Create a simple model.
inputs = keras.Input(shape=(32,))
outputs = keras.layers.Dense(1)(inputs)
model = keras.Model(inputs, outputs)
model.compile(optimizer="adam", loss="mean_squared_error")
return model | python | tests/pytest_tests/unit_tests/saved_model_constructors.py | 37 | 43 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
364 | cache | def cache(tmp_path):
return wandb_sdk.wandb_artifacts.ArtifactsCache(tmp_path) | python | tests/pytest_tests/unit_tests/test_artifacts/conftest.py | 6 | 7 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
365 | __init__ | def __init__(self):
self._map = {} | python | tests/pytest_tests/unit_tests_old/conftest.py | 48 | 49 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
366 | items | def items(self):
return self._map.items() | python | tests/pytest_tests/unit_tests_old/conftest.py | 51 | 52 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
367 | __getitem__ | def __getitem__(self, worker_id):
if self._map.get(worker_id) is None:
self._map[worker_id] = start_mock_server(worker_id)
return self._map[worker_id] | python | tests/pytest_tests/unit_tests_old/conftest.py | 54 | 57 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
368 | get_temp_dir_kwargs | def get_temp_dir_kwargs(tmp_path):
# Click>=8 implements temp_dir argument which depends on python>=3.7
return dict(temp_dir=tmp_path) if sys.version_info >= (3, 7) else {} | python | tests/pytest_tests/unit_tests_old/conftest.py | 63 | 65 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
369 | test_cleanup | def test_cleanup(*args, **kwargs):
print("Shutting down mock servers")
for wid, server in servers.items():
print(f"Shutting down {wid}")
server.terminate()
print("Open files during tests: ")
proc = psutil.Process()
print(proc.open_files()) | python | tests/pytest_tests/unit_tests_old/conftest.py | 68 | 75 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
370 | wait_for_port_file | def wait_for_port_file(port_file):
port = 0
start_time = time.time()
while not port:
try:
port = int(open(port_file).read().strip())
if port:
break
except Exception as e:
print(f"Problem parsing port file: {e}")
now = time.time()
if now > start_time + 30:
raise Exception(f"Could not start server {now} {start_time}")
time.sleep(0.5)
return port | python | tests/pytest_tests/unit_tests_old/conftest.py | 78 | 92 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
371 | start_mock_server | def start_mock_server(worker_id):
"""We start a flask server process for each pytest-xdist worker_id"""
this_folder = os.path.dirname(__file__)
path = os.path.join(this_folder, "utils", "mock_server.py")
command = [sys.executable, "-u", path]
env = os.environ
env["PORT"] = "0" # Let the server find its own port
env["PYTHONPATH"] = os.path.abspath(os.path.join(this_folder, os.pardir))
logfname = os.path.join(this_folder, "logs", f"live_mock_server-{worker_id}.log")
pid = os.getpid()
rand = random.randint(0, 2**32)
port_file = os.path.join(
this_folder, "logs", f"live_mock_server-{worker_id}-{pid}-{rand}.port"
)
env["PORT_FILE"] = port_file
logfile = open(logfname, "w")
server = subprocess.Popen(
command,
stdout=logfile,
env=env,
stderr=subprocess.STDOUT,
bufsize=1,
close_fds=True,
)
port = wait_for_port_file(port_file)
server._port = port
server.base_url = f"http://localhost:{server._port}"
def get_ctx():
return requests.get(server.base_url + "/ctx").json()
def set_ctx(payload):
return requests.put(server.base_url + "/ctx", json=payload).json()
def reset_ctx():
return requests.delete(server.base_url + "/ctx").json()
server.get_ctx = get_ctx
server.set_ctx = set_ctx
server.reset_ctx = reset_ctx
started = False
for i in range(10):
try:
res = requests.get("%s/ctx" % server.base_url, timeout=5)
if res.status_code == 200:
started = True
break
print(f"Attempting to connect but got: {res}")
except requests.exceptions.RequestException:
print(
"Timed out waiting for server to start...", server.base_url, time.time()
)
if server.poll() is None:
time.sleep(1)
else:
raise ValueError("Server failed to start.")
if started:
print(f"Mock server listing on {server._port} see {logfname}")
else:
server.terminate()
print(f"Server failed to launch, see {logfname}")
try:
print("=" * 40)
with open(logfname) as f:
for logline in f.readlines():
print(logline.strip())
print("=" * 40)
except Exception as e:
print("EXCEPTION:", e)
raise ValueError("Failed to start server! Exit code %s" % server.returncode)
return server | python | tests/pytest_tests/unit_tests_old/conftest.py | 95 | 167 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
372 | get_ctx | def get_ctx():
return requests.get(server.base_url + "/ctx").json() | python | tests/pytest_tests/unit_tests_old/conftest.py | 124 | 125 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
373 | set_ctx | def set_ctx(payload):
return requests.put(server.base_url + "/ctx", json=payload).json() | python | tests/pytest_tests/unit_tests_old/conftest.py | 127 | 128 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
374 | reset_ctx | def reset_ctx():
return requests.delete(server.base_url + "/ctx").json() | python | tests/pytest_tests/unit_tests_old/conftest.py | 130 | 131 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
375 | test_name | def test_name(request):
# change "test[1]" to "test__1__"
name = urllib.parse.quote(request.node.name.replace("[", "__").replace("]", "__"))
return name | python | tests/pytest_tests/unit_tests_old/conftest.py | 174 | 177 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
376 | test_dir | def test_dir(test_name):
orig_dir = os.getcwd()
root = os.path.abspath(os.path.dirname(__file__))
test_dir = os.path.join(root, "logs", test_name)
if os.path.exists(test_dir):
shutil.rmtree(test_dir)
filesystem.mkdir_exists_ok(test_dir)
os.chdir(test_dir)
yield test_dir
os.chdir(orig_dir) | python | tests/pytest_tests/unit_tests_old/conftest.py | 181 | 190 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
377 | disable_git_save | def disable_git_save():
with mock.patch.dict("os.environ", WANDB_DISABLE_GIT="true"):
yield | python | tests/pytest_tests/unit_tests_old/conftest.py | 194 | 196 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
378 | git_repo | def git_repo(runner):
with runner.isolated_filesystem():
with git.Repo.init(".") as repo:
filesystem.mkdir_exists_ok("wandb")
# Because the forked process doesn't use my monkey patch above
with open(os.path.join("wandb", "settings"), "w") as f:
f.write("[default]\nproject: test")
open("README", "wb").close()
repo.index.add(["README"])
repo.index.commit("Initial commit")
yield GitRepo(lazy=False) | python | tests/pytest_tests/unit_tests_old/conftest.py | 200 | 210 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
379 | git_repo_fn | def git_repo_fn(runner):
def git_repo_fn_helper(
path: str = ".",
remote_name: str = "origin",
remote_url: Optional[str] = "https://foo:bar@github.com/FooTest/Foo.git",
commit_msg: Optional[str] = None,
):
with git.Repo.init(path) as repo:
filesystem.mkdir_exists_ok("wandb")
if remote_url is not None:
repo.create_remote(remote_name, remote_url)
if commit_msg is not None:
repo.index.commit(commit_msg)
return GitRepo(lazy=False)
with runner.isolated_filesystem():
yield git_repo_fn_helper | python | tests/pytest_tests/unit_tests_old/conftest.py | 214 | 230 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
380 | git_repo_fn_helper | def git_repo_fn_helper(
path: str = ".",
remote_name: str = "origin",
remote_url: Optional[str] = "https://foo:bar@github.com/FooTest/Foo.git",
commit_msg: Optional[str] = None,
):
with git.Repo.init(path) as repo:
filesystem.mkdir_exists_ok("wandb")
if remote_url is not None:
repo.create_remote(remote_name, remote_url)
if commit_msg is not None:
repo.index.commit(commit_msg)
return GitRepo(lazy=False) | python | tests/pytest_tests/unit_tests_old/conftest.py | 215 | 227 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
381 | dummy_api_key | def dummy_api_key():
return DUMMY_API_KEY | python | tests/pytest_tests/unit_tests_old/conftest.py | 234 | 235 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
382 | reinit_internal_api | def reinit_internal_api():
with mock.patch("wandb.api", InternalApi()):
yield | python | tests/pytest_tests/unit_tests_old/conftest.py | 239 | 241 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
383 | test_settings | def test_settings(test_dir, mocker, live_mock_server):
"""Settings object for tests"""
# TODO: likely not the right thing to do, we shouldn't be setting this
wandb._IS_INTERNAL_PROCESS = False
wandb.wandb_sdk.wandb_run.EXIT_TIMEOUT = 15
wandb.wandb_sdk.wandb_setup._WandbSetup.instance = None
wandb_dir = os.path.join(test_dir, "wandb")
filesystem.mkdir_exists_ok(wandb_dir)
settings = wandb.Settings(
api_key=DUMMY_API_KEY,
base_url=live_mock_server.base_url,
console="off",
host="test",
project="test",
root_dir=test_dir,
run_id=runid.generate_id(),
save_code=False,
)
settings._set_run_start_time()
yield settings
# Just in case someone forgets to join in tests. ...well, please don't!
if wandb.run is not None:
wandb.run.finish() | python | tests/pytest_tests/unit_tests_old/conftest.py | 245 | 267 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
384 | mocked_run | def mocked_run(runner, test_settings):
"""A managed run object for tests with a mock backend"""
run = wandb.wandb_sdk.wandb_run.Run(settings=test_settings)
run._set_backend(MagicMock())
yield run | python | tests/pytest_tests/unit_tests_old/conftest.py | 271 | 275 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
385 | runner | def runner(monkeypatch, mocker):
# monkeypatch.setattr('wandb.cli.api', InternalApi(
# default_settings={'project': 'test', 'git_tag': True}, load_settings=False))
monkeypatch.setattr(
wandb.util, "prompt_choices", lambda x, input_timeout=None, jupyter=False: x[0]
)
monkeypatch.setattr(
wandb.wandb_lib.apikey,
"prompt_choices",
lambda x, input_timeout=None, jupyter=False: x[0],
)
monkeypatch.setattr(click, "launch", lambda x: 1)
monkeypatch.setattr(webbrowser, "open_new_tab", lambda x: True)
mocker.patch("wandb.wandb_lib.apikey.isatty", lambda stream: True)
mocker.patch("wandb.wandb_lib.apikey.input", lambda x: 1)
mocker.patch("wandb.wandb_lib.apikey.getpass", lambda x: DUMMY_API_KEY)
return CliRunner() | python | tests/pytest_tests/unit_tests_old/conftest.py | 279 | 295 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
386 | reset_setup | def reset_setup():
def teardown():
wandb.wandb_sdk.wandb_setup._WandbSetup._instance = None
getattr(wandb, "teardown", teardown)()
yield
getattr(wandb, "teardown", lambda: None)() | python | tests/pytest_tests/unit_tests_old/conftest.py | 299 | 305 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
387 | teardown | def teardown():
wandb.wandb_sdk.wandb_setup._WandbSetup._instance = None | python | tests/pytest_tests/unit_tests_old/conftest.py | 300 | 301 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
388 | local_netrc | def local_netrc(monkeypatch):
"""Never use our real credentials, put them in their own isolated dir"""
with CliRunner().isolated_filesystem():
# TODO: this seems overkill...
origexpand = os.path.expanduser
# Touch that netrc
open(".netrc", "wb").close()
def expand(path):
if "netrc" in path:
try:
ret = os.path.realpath("netrc")
except OSError:
ret = origexpand(path)
else:
ret = origexpand(path)
return ret
monkeypatch.setattr(os.path, "expanduser", expand)
yield | python | tests/pytest_tests/unit_tests_old/conftest.py | 309 | 328 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
389 | expand | def expand(path):
if "netrc" in path:
try:
ret = os.path.realpath("netrc")
except OSError:
ret = origexpand(path)
else:
ret = origexpand(path)
return ret | python | tests/pytest_tests/unit_tests_old/conftest.py | 317 | 325 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
390 | local_settings | def local_settings(mocker, tmp_path):
"""Place global settings in an isolated dir"""
with CliRunner().isolated_filesystem():
cfg_path = os.path.join(os.getcwd(), ".config", "wandb", "settings")
filesystem.mkdir_exists_ok(os.path.join(".config", "wandb"))
mocker.patch("wandb.old.settings.Settings._global_path", return_value=cfg_path)
yield | python | tests/pytest_tests/unit_tests_old/conftest.py | 332 | 338 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
391 | mock_server | def mock_server(mocker):
return utils.mock_server(mocker) | python | tests/pytest_tests/unit_tests_old/conftest.py | 342 | 343 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
392 | live_mock_server | def live_mock_server(request, worker_id):
global servers
server = servers[worker_id]
name = urllib.parse.quote(request.node.name)
# We set the username so the mock backend can namespace state
with mock.patch.dict(
os.environ,
{
"WANDB_USERNAME": name,
"WANDB_BASE_URL": server.base_url,
"WANDB_ERROR_REPORTING": "false",
"WANDB_API_KEY": DUMMY_API_KEY,
},
):
# clear mock server ctx
server.reset_ctx()
yield server | python | tests/pytest_tests/unit_tests_old/conftest.py | 348 | 364 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
393 | notebook | def notebook(live_mock_server, test_dir):
"""This launches a live server, configures a notebook to use it, and enables
devs to execute arbitrary cells. See tests/test_notebooks.py
"""
@contextmanager
def notebook_loader(nb_path, kernel_name="wandb_python", save_code=True, **kwargs):
with open(utils.notebook_path("setup.ipynb")) as f:
setupnb = nbformat.read(f, as_version=4)
setupcell = setupnb["cells"][0]
# Ensure the notebooks talks to our mock server
new_source = setupcell["source"].replace(
"__WANDB_BASE_URL__",
live_mock_server.base_url,
)
if save_code:
new_source = new_source.replace("__WANDB_NOTEBOOK_NAME__", nb_path)
else:
new_source = new_source.replace("__WANDB_NOTEBOOK_NAME__", "")
setupcell["source"] = new_source
nb_path = utils.notebook_path(nb_path)
shutil.copy(nb_path, os.path.join(os.getcwd(), os.path.basename(nb_path)))
with open(nb_path) as f:
nb = nbformat.read(f, as_version=4)
nb["cells"].insert(0, setupcell)
try:
client = utils.WandbNotebookClient(nb, kernel_name=kernel_name)
with client.setup_kernel(**kwargs):
# Run setup commands for mocks
client.execute_cells(-1, store_history=False)
yield client
finally:
with open(os.path.join(os.getcwd(), "notebook.log"), "w") as f:
f.write(client.all_output_text())
wandb.termlog("Find debug logs at: %s" % os.getcwd())
wandb.termlog(client.all_output_text())
notebook_loader.base_url = live_mock_server.base_url
return notebook_loader | python | tests/pytest_tests/unit_tests_old/conftest.py | 368 | 409 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
394 | notebook_loader | def notebook_loader(nb_path, kernel_name="wandb_python", save_code=True, **kwargs):
with open(utils.notebook_path("setup.ipynb")) as f:
setupnb = nbformat.read(f, as_version=4)
setupcell = setupnb["cells"][0]
# Ensure the notebooks talks to our mock server
new_source = setupcell["source"].replace(
"__WANDB_BASE_URL__",
live_mock_server.base_url,
)
if save_code:
new_source = new_source.replace("__WANDB_NOTEBOOK_NAME__", nb_path)
else:
new_source = new_source.replace("__WANDB_NOTEBOOK_NAME__", "")
setupcell["source"] = new_source
nb_path = utils.notebook_path(nb_path)
shutil.copy(nb_path, os.path.join(os.getcwd(), os.path.basename(nb_path)))
with open(nb_path) as f:
nb = nbformat.read(f, as_version=4)
nb["cells"].insert(0, setupcell)
try:
client = utils.WandbNotebookClient(nb, kernel_name=kernel_name)
with client.setup_kernel(**kwargs):
# Run setup commands for mocks
client.execute_cells(-1, store_history=False)
yield client
finally:
with open(os.path.join(os.getcwd(), "notebook.log"), "w") as f:
f.write(client.all_output_text())
wandb.termlog("Find debug logs at: %s" % os.getcwd())
wandb.termlog(client.all_output_text()) | python | tests/pytest_tests/unit_tests_old/conftest.py | 374 | 405 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
395 | mocked_module | def mocked_module(monkeypatch):
"""This allows us to mock modules loaded via wandb.util.get_module"""
def mock_get_module(module):
orig_get_module = wandb.util.get_module
mocked_module = MagicMock()
def get_module(mod):
if mod == module:
return mocked_module
else:
return orig_get_module(mod)
monkeypatch.setattr(wandb.util, "get_module", get_module)
return mocked_module
return mock_get_module | python | tests/pytest_tests/unit_tests_old/conftest.py | 413 | 429 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
396 | mock_get_module | def mock_get_module(module):
orig_get_module = wandb.util.get_module
mocked_module = MagicMock()
def get_module(mod):
if mod == module:
return mocked_module
else:
return orig_get_module(mod)
monkeypatch.setattr(wandb.util, "get_module", get_module)
return mocked_module | python | tests/pytest_tests/unit_tests_old/conftest.py | 416 | 427 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
397 | get_module | def get_module(mod):
if mod == module:
return mocked_module
else:
return orig_get_module(mod) | python | tests/pytest_tests/unit_tests_old/conftest.py | 420 | 424 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
398 | mocked_ipython | def mocked_ipython(mocker):
mocker.patch("wandb.sdk.lib.ipython._get_python_type", lambda: "jupyter")
mocker.patch("wandb.sdk.wandb_settings._get_python_type", lambda: "jupyter")
html_mock = mocker.MagicMock()
mocker.patch("wandb.sdk.lib.ipython.display_html", html_mock)
ipython = MagicMock()
ipython.html = html_mock
def run_cell(cell):
print("Running cell: ", cell)
exec(cell)
ipython.run_cell = run_cell
# TODO: this is really unfortunate, for reasons not clear to me, monkeypatch doesn't work
orig_get_ipython = wandb.jupyter.get_ipython
orig_display = wandb.jupyter.display
wandb.jupyter.get_ipython = lambda: ipython
wandb.jupyter.display = lambda obj: html_mock(obj._repr_html_())
yield ipython
wandb.jupyter.get_ipython = orig_get_ipython
wandb.jupyter.display = orig_display | python | tests/pytest_tests/unit_tests_old/conftest.py | 433 | 453 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
399 | run_cell | def run_cell(cell):
print("Running cell: ", cell)
exec(cell) | python | tests/pytest_tests/unit_tests_old/conftest.py | 441 | 443 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
400 | default_wandb_args | def default_wandb_args():
"""This allows us to parameterize the wandb_init_run fixture
The most general arg is "env", you can call:
@pytest.mark.wandb_args(env={"WANDB_API_KEY": "XXX"})
To set env vars and have them unset when the test completes.
"""
return {
"error": None,
"k8s": None,
"sagemaker": False,
"tensorboard": False,
"resume": False,
"env": {},
"wandb_init": {},
} | python | tests/pytest_tests/unit_tests_old/conftest.py | 456 | 472 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.