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
501
k8s_pod
def k8s_pod(): ctx = get_ctx() image_id = b"docker-pullable://test@sha256:1234" ms = b'{"status":{"containerStatuses":[{"imageID":"%s"}]}}' % image_id if ctx.get("k8s"): return ms, 200 else: return b"", 500
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,168
2,175
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
502
jupyter_sessions
def jupyter_sessions(): return json.dumps( [ { "kernel": {"id": "12345"}, "notebook": {"path": "test.ipynb", "name": "test.ipynb"}, } ] )
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,178
2,186
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
503
spell_url
def spell_url(): ctx = get_ctx() ctx["spell_data"] = request.get_json() return json.dumps({"success": True})
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,189
2,192
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
504
pypi
def pypi(library): version = getattr(wandb, "__hack_pypi_latest_version__", wandb.__version__) return json.dumps( { "info": {"version": version}, "releases": { "88.1.2rc2": [], "88.1.2rc12": [], "88.1.2rc3": [], "88.1.2rc4": [], "0.11.0": [], "0.10.32": [], "0.10.31": [], "0.10.30": [], "0.0.8rc6": [], "0.0.8rc2": [], "0.0.8rc3": [], "0.0.8rc8": [], "0.0.2": [{"yanked": True}], "0.0.3": [{"yanked": True, "yanked_reason": "just cuz"}], "0.0.7": [], "0.0.5": [], "0.0.6": [], }, } )
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,195
2,220
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
505
sentry_put
def sentry_put(): ctx = get_ctx() data = request.get_data() data = gzip.decompress(data) data = str(data, "utf-8") data = json.loads(data) ctx["sentry_events"].append(data) return ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,223
2,230
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
506
sentry_session_put
def sentry_session_put(): ctx = get_ctx() data = request.get_data() data = gzip.decompress(data) data = str(data, "utf-8") envelope = [] for line in data.splitlines(): if not line: continue line = json.loads(line) envelope.append(line) ctx["sentry_sessions"].append(envelope) return ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,233
2,245
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
507
page_not_found
def page_not_found(e): print(f"Got request to: {request.url} ({request.method})") return "Not Found", 404
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,248
2,250
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
508
strip_datetime
def strip_datetime(s): # 2021-09-18T17:28:07.059270 m = RE_DATETIME.match(s) if m: return m.group("rest") return s
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,258
2,263
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
509
__init__
def __init__(self, ctx, run_id=None): self._ctx = ctx["runs"][run_id] if run_id else ctx self._run_id = run_id
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,267
2,269
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
510
get_filestream_file_updates
def get_filestream_file_updates(self): data = {} file_stream_updates = self._ctx.get("file_stream", []) for update in file_stream_updates: files = update.get("files") if not files: continue for k, v in files.items(): data.setdefault(k, []).append(v) return data
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,271
2,280
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
511
get_filestream_file_items
def get_filestream_file_items(self): data = {} fs_file_updates = self.get_filestream_file_updates() for k, v in fs_file_updates.items(): l = [] for d in v: offset = d.get("offset") content = d.get("content") assert offset is not None assert content is not None if k == "output.log": lines = content pad = "" else: lines = list(map(json.loads, content)) pad = {} # pad list if our offset is too large (is this what bt would do?) # TODO: is this pad the right thing or should we assert if offset is past len l += [pad] * (offset - len(l)) l[offset : offset + len(lines)] = lines data[k] = l return data
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,282
2,305
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
512
run_ids
def run_ids(self): return self._ctx.get("run_ids", [])
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,308
2,309
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
513
file_names
def file_names(self): return self._ctx.get("file_names", [])
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,312
2,313
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
514
files
def files(self): files_sizes = self._ctx.get("file_bytes", {}) files_dict = {} for fname, size in files_sizes.items(): files_dict.setdefault(fname, {}) files_dict[fname]["size"] = size return files_dict
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,316
2,322
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
515
dropped_chunks
def dropped_chunks(self): return self._ctx.get("file_stream", [{"dropped": 0}])[-1]["dropped"]
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,325
2,326
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
516
summary_raw
def summary_raw(self): fs_files = self.get_filestream_file_items() summary = fs_files.get("wandb-summary.json", [{}])[-1] return summary
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,329
2,332
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
517
summary_user
def summary_user(self): return {k: v for k, v in self.summary_raw.items() if not k.startswith("_")}
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,335
2,336
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
518
summary
def summary(self): # TODO: move this to config_user eventually return {k: v for k, v in self.summary_raw.items() if k != "_wandb"}
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,339
2,341
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
519
summary_wandb
def summary_wandb(self): return self.summary_raw.get("_wandb", {})
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,344
2,345
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
520
history
def history(self): fs_files = self.get_filestream_file_items() history = fs_files.get("wandb-history.jsonl") return history
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,348
2,351
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
521
stats
def stats(self): fs_files = self.get_filestream_file_items() stats = fs_files.get("wandb-events.jsonl") return stats
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,354
2,357
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
522
output
def output(self): fs_files = self.get_filestream_file_items() output_items = fs_files.get("output.log", []) err_prefix = "ERROR " stdout_items = [] stderr_items = [] for item in output_items: if item.startswith(err_prefix): err_item = item[len(err_prefix) :] stderr_items.append(err_item) else: stdout_items.append(item) stdout = "".join(stdout_items) stderr = "".join(stderr_items) stdout_lines = stdout.splitlines() stderr_lines = stderr.splitlines() stdout = list(map(strip_datetime, stdout_lines)) stderr = list(map(strip_datetime, stderr_lines)) return dict(stdout=stdout, stderr=stderr)
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,360
2,378
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
523
exit_code
def exit_code(self): exit_code = None fs_list = self._ctx.get("file_stream") if fs_list: exit_code = fs_list[-1].get("exitcode") return exit_code
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,381
2,386
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
524
run_id
def run_id(self): return self._run_id
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,389
2,390
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
525
git
def git(self): git_info = self._ctx.get("git") return git_info or dict(commit=None, remote=None)
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,393
2,395
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
526
config_raw
def config_raw(self): return (self._ctx.get("config") or [{}])[-1]
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,398
2,399
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
527
config_user
def config_user(self): return { k: v["value"] for k, v in self.config_raw.items() if not k.startswith("_") }
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,402
2,405
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
528
config
def config(self): # TODO: move this to config_user eventually return self.config_raw
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,408
2,410
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
529
config_wandb
def config_wandb(self): return self.config.get("_wandb", {}).get("value", {})
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,413
2,414
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
530
telemetry
def telemetry(self): return self.config.get("_wandb", {}).get("value", {}).get("t", {})
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,417
2,418
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
531
metrics
def metrics(self): return self.config.get("_wandb", {}).get("value", {}).get("m", {})
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,421
2,422
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
532
manifests_created
def manifests_created(self): return self._ctx.get("manifests_created") or []
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,425
2,426
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
533
manifests_created_ids
def manifests_created_ids(self): return [m["id"] for m in self.manifests_created]
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,429
2,430
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
534
artifacts
def artifacts(self): return self._ctx.get("artifacts_created") or {}
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,433
2,434
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
535
portfolio_links
def portfolio_links(self): return self._ctx.get("portfolio_links") or {}
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,437
2,438
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
536
tags
def tags(self): return self._ctx.get("tags") or []
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,441
2,442
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
537
notes
def notes(self): return self._ctx.get("notes") or ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,445
2,446
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
538
group
def group(self): return self._ctx.get("group") or ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,449
2,450
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
539
job_type
def job_type(self): return self._ctx.get("job_type") or ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,453
2,454
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
540
name
def name(self): return self._ctx.get("name") or ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,457
2,458
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
541
program
def program(self): return self._ctx.get("program") or ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,461
2,462
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
542
host
def host(self): return self._ctx.get("host") or ""
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,465
2,466
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
543
alerts
def alerts(self): return self._ctx.get("alerts") or []
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,469
2,470
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
544
sentry_events
def sentry_events(self): return self._ctx.get("sentry_events") or []
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,473
2,474
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
545
sentry_sessions
def sentry_sessions(self): return self._ctx.get("sentry_sessions") or []
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,477
2,478
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
546
_debug
def _debug(self): if not self._run_id: items = {"run_ids": "run_ids", "artifacts": "artifacts"} else: items = { "config": "config_user", "summary": "summary_user", "exit_code": "exit_code", "telemetry": "telemetry", } d = {} for k, v in items.items(): d[k] = getattr(self, v) return d
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,480
2,493
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
547
mock_socket_socket
def mock_socket_socket(*args, **kwargs): class MockSocket: def __init__(self, sock): self._sock = sock def __getattr__(self, item): return getattr(self._sock, item) def __enter__(self): return self._sock.__enter__() def __exit__(self, *args): self._sock.__exit__(*args) def bind(self, *args, **kwargs): ret = self._sock.bind(*args, **kwargs) port_file = os.environ.get("PORT_FILE") if port_file: _host, port = self._sock.getsockname() with open(port_file, "w") as f: f.write(f"{port}\n") return ret sock = orig_socket_socket(*args, **kwargs) return MockSocket(sock)
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,499
2,523
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
548
__init__
def __init__(self, sock): self._sock = sock
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,501
2,502
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
549
__getattr__
def __getattr__(self, item): return getattr(self._sock, item)
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,504
2,505
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
550
__enter__
def __enter__(self): return self._sock.__enter__()
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,507
2,508
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
551
__exit__
def __exit__(self, *args): self._sock.__exit__(*args)
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,510
2,511
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
552
bind
def bind(self, *args, **kwargs): ret = self._sock.bind(*args, **kwargs) port_file = os.environ.get("PORT_FILE") if port_file: _host, port = self._sock.getsockname() with open(port_file, "w") as f: f.write(f"{port}\n") return ret
python
tests/pytest_tests/unit_tests_old/utils/mock_server.py
2,513
2,520
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
553
__init__
def __init__(self, q): self._q = q self._data = [] self._read_all()
python
tests/pytest_tests/unit_tests_old/utils/records.py
2
5
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
554
_read_all
def _read_all(self): while not self._q.empty(): self._data.append(self._q.get())
python
tests/pytest_tests/unit_tests_old/utils/records.py
7
9
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
555
_get_all
def _get_all(self, record_type=None): for r in self._data: r_type = r.WhichOneof("record_type") if not record_type or r_type == record_type: if r_type: r = getattr(r, r_type) yield r
python
tests/pytest_tests/unit_tests_old/utils/records.py
11
17
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
556
records
def records(self): return list(self._get_all())
python
tests/pytest_tests/unit_tests_old/utils/records.py
20
21
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
557
configs
def configs(self): return list(self._get_all("config"))
python
tests/pytest_tests/unit_tests_old/utils/records.py
24
25
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
558
summary
def summary(self): return list(self._get_all("summary"))
python
tests/pytest_tests/unit_tests_old/utils/records.py
28
29
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
559
history
def history(self): return list(self._get_all("history"))
python
tests/pytest_tests/unit_tests_old/utils/records.py
32
33
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
560
files
def files(self): return list(self._get_all("files"))
python
tests/pytest_tests/unit_tests_old/utils/records.py
36
37
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
561
metric
def metric(self): return list(self._get_all("metric"))
python
tests/pytest_tests/unit_tests_old/utils/records.py
40
41
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
562
partial_history
def partial_history(self): return [ request.partial_history for request in self._get_all("request") if request.WhichOneof("request_type") == "partial_history" ]
python
tests/pytest_tests/unit_tests_old/utils/records.py
44
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
563
__init__
def __init__(self, random_str, ctx, base_url): self._random_str = random_str self._ctx = ctx self._artifacts = {} self._artifacts_by_id = {} self._files = {} self._base_url = base_url self._portfolio_links = {}
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
5
12
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
564
create
def create(self, variables): collection_name = variables["artifactCollectionNames"][0] state = "PENDING" aliases = [] latest = None art_id = variables.get("digest", "") # Find most recent artifact versions = self._artifacts.get(collection_name) if versions: last_version = versions[-1] latest = {"id": last_version["digest"], "versionIndex": len(versions) - 1} art_seq = {"id": art_id, "latestArtifact": latest} aliases.append(dict(artifactCollectionName=collection_name, alias="latest")) base_url = self._base_url direct_url = f"{base_url}/storage?file=wandb_manifest.json" art_data = { "id": art_id, "digest": "abc123", "state": state, "labels": [], "aliases": aliases, "artifactSequence": art_seq, "versionIndex": 0, "currentManifest": dict(file=dict(directUrl=direct_url)), } response = {"data": {"createArtifact": {"artifact": copy.deepcopy(art_data)}}} # save in artifact emu object art_seq["name"] = collection_name art_data["artifactSequence"] = art_seq art_data["state"] = "COMMITTED" art_type = variables.get("artifactTypeName") if art_type: art_data["artifactType"] = {"id": 1, "name": art_type} art_save = copy.deepcopy(art_data) self._artifacts.setdefault(collection_name, []).append(art_save) self._artifacts_by_id[art_id] = art_save # save in context self._ctx["artifacts_created"].setdefault(collection_name, {}) self._ctx["artifacts_created"][collection_name].setdefault("num", 0) self._ctx["artifacts_created"][collection_name]["num"] += 1 if art_type: self._ctx["artifacts_created"][collection_name]["type"] = art_type return response
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
14
63
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
565
link
def link(self, variables): pfolio_name = variables.get("artifactPortfolioName") artifact_id = variables.get("artifactID") or variables.get("clientID") if not pfolio_name or not artifact_id: raise ValueError( "query variables must contain artifactPortfolioName and either artifactID or clientID" ) aliases = variables.get("aliases") # We automatically create a portfolio for the user if we can't find the one given. links = self._portfolio_links.setdefault(pfolio_name, []) if not any(map(lambda x: x["id"] == artifact_id, links)): art = {"id": artifact_id, "aliases": [a["alias"] for a in aliases]} links.append(art) self._ctx["portfolio_links"].setdefault(pfolio_name, {}) num = len(links) self._ctx["portfolio_links"][pfolio_name]["num"] = num response = {"data": {"linkArtifact": {"versionIndex": num - 1}}} return response
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
65
83
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
566
create_files
def create_files(self, variables): base_url = self._base_url response = { "data": { "createArtifactFiles": { "files": { "edges": [ { "node": { "id": idx, "name": af["name"], "displayName": af["name"], "uploadUrl": f"{base_url}/storage?file={af['name']}&id={af['artifactID']}", "uploadHeaders": [], "artifact": {"id": af["artifactID"]}, }, } for idx, af in enumerate(variables["artifactFiles"]) ], }, }, }, } return response
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
85
108
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
567
query
def query(self, variables, query=None): public_api_query_str = "query Artifact($id: ID!) {" public_api_query_str2 = "query ArtifactWithCurrentManifest($id: ID!) {" public_api_query_str3 = "query ArtifactManifest(" art_id = variables.get("id") art_name = variables.get("name") assert art_id or art_name is_public_api_query = query and ( query.startswith(public_api_query_str) or query.startswith(public_api_query_str2) or query.startswith(public_api_query_str3) ) if art_name: collection_name, version = art_name.split(":", 1) artifact = None artifacts = self._artifacts.get(collection_name) if artifacts: if version == "latest": version_num = len(artifacts) else: assert version.startswith("v") version_num = int(version[1:]) artifact = artifacts[version_num - 1] # TODO: add alias info? elif art_id: artifact = self._artifacts_by_id[art_id] if is_public_api_query: response = {"data": {"artifact": artifact}} else: response = {"data": {"project": {"artifact": artifact}}} return response
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
110
143
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
568
file
def file(self, entity, digest): # TODO? return "ARTIFACT %s" % digest, 200
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
145
147
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
569
storage
def storage(self, request, arti_id=None): fname = request.args.get("file") if arti_id is None: arti_id = "unknown_id" if request.method == "PUT": data = request.get_data(as_text=True) if self._files.get(arti_id) is None: self._files[arti_id] = {} self._files[arti_id][fname] = data data = "" if request.method == "GET": data = self._files[arti_id][fname] return data, 200
python
tests/pytest_tests/unit_tests_old/utils/artifact_emu.py
149
161
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
570
get_mock_module
def get_mock_module(config): """ Import and return the actual "mock" module. By default, this is "unittest.mock", but the user can force to always use "mock" using the mock_use_standalone_module ini option. """ global _mock_module if _mock_module is None: try: use_standalone_module = parse_ini_boolean( config.getini("mock_use_standalone_module") ) except ValueError: use_standalone_module = False if use_standalone_module: import mock _mock_module = mock else: import unittest.mock _mock_module = unittest.mock return _mock_module
python
tests/pytest_tests/unit_tests_old/utils/utils.py
10
33
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
571
parse_ini_boolean
def parse_ini_boolean(value: Union[bool, str]) -> bool: if isinstance(value, bool): return value if value.lower() == "true": return True if value.lower() == "false": return False raise ValueError("unknown string for bool: %r" % value)
python
tests/pytest_tests/unit_tests_old/utils/utils.py
36
43
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
572
assets_path
def assets_path(path): return os.path.join( os.path.dirname(os.path.abspath(__file__)), os.pardir, "assets", path )
python
tests/pytest_tests/unit_tests_old/utils/utils.py
46
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
573
subdict
def subdict(d, expected_dict): """Return a new dict with only the items from `d` whose keys occur in `expected_dict`.""" return {k: v for k, v in d.items() if k in expected_dict}
python
tests/pytest_tests/unit_tests_old/utils/utils.py
52
54
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
574
fixture_path
def fixture_path(path): return os.path.join( os.path.dirname(os.path.abspath(__file__)), os.pardir, "assets", "fixtures", path, )
python
tests/pytest_tests/unit_tests_old/utils/utils.py
57
64
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
575
first_filestream
def first_filestream(ctx): """In xdist tests sometimes rogue file_streams make it to the server, we grab the first request with `files`""" return next(m for m in ctx["file_stream"] if m.get("files"))
python
tests/pytest_tests/unit_tests_old/utils/utils.py
67
70
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
576
fixture_open
def fixture_open(path, mode="r"): """Return an opened fixture file""" return open(fixture_path(path), mode)
python
tests/pytest_tests/unit_tests_old/utils/utils.py
73
75
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
577
fixture_copy
def fixture_copy(path, dst=None): if os.path.isfile(fixture_path(path)): return shutil.copy(fixture_path(path), dst or path) else: return shutil.copytree(fixture_path(path), dst or path)
python
tests/pytest_tests/unit_tests_old/utils/utils.py
78
82
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
578
notebook_path
def notebook_path(path): """Returns the path to a notebook""" return os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, "assets", "notebooks", path) )
python
tests/pytest_tests/unit_tests_old/utils/utils.py
85
89
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
579
free_port
def free_port(): sock = socket.socket() sock.bind(("", 0)) _, port = sock.getsockname() return port
python
tests/pytest_tests/unit_tests_old/utils/utils.py
92
97
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
580
assert_deep_lists_equal
def assert_deep_lists_equal(a, b, indices=None): try: assert a == b except ValueError: assert len(a) == len(b) # pytest's list diffing breaks at 4d, so we track them ourselves if indices is None: indices = [] top = True else: top = False for i, (x, y) in enumerate(zip(a, b)): try: assert_deep_lists_equal(x, y, indices) except AssertionError: indices.append(i) raise finally: if top and indices: print("Diff at index: %s" % list(reversed(indices)))
python
tests/pytest_tests/unit_tests_old/utils/utils.py
100
121
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
581
mock_sagemaker
def mock_sagemaker(mocker): env = {} config_path = "/opt/ml/input/config/hyperparameters.json" resource_path = "/opt/ml/input/config/resourceconfig.json" secrets_path = "secrets.env" env["TRAINING_JOB_NAME"] = "sage" env["CURRENT_HOST"] = "maker" orig_exist = os.path.exists def exists(path): if path in (config_path, secrets_path, resource_path): return True else: return orig_exist(path) mocker.patch("wandb.util.os.path.exists", exists) def magic_factory(original): def magic(path, *args, **kwargs): if path == config_path: return io.StringIO('{"foo": "bar"}') elif path == resource_path: return io.StringIO('{"hosts":["a", "b"]}') elif path == secrets_path: return io.StringIO("WANDB_TEST_SECRET=TRUE") else: return original(path, *args, **kwargs) return magic mocker.patch("builtins.open", magic_factory(open), create=True) return env
python
tests/pytest_tests/unit_tests_old/utils/utils.py
124
156
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
582
exists
def exists(path): if path in (config_path, secrets_path, resource_path): return True else: return orig_exist(path)
python
tests/pytest_tests/unit_tests_old/utils/utils.py
134
138
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
583
magic_factory
def magic_factory(original): def magic(path, *args, **kwargs): if path == config_path: return io.StringIO('{"foo": "bar"}') elif path == resource_path: return io.StringIO('{"hosts":["a", "b"]}') elif path == secrets_path: return io.StringIO("WANDB_TEST_SECRET=TRUE") else: return original(path, *args, **kwargs) return magic
python
tests/pytest_tests/unit_tests_old/utils/utils.py
142
153
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
584
magic
def magic(path, *args, **kwargs): if path == config_path: return io.StringIO('{"foo": "bar"}') elif path == resource_path: return io.StringIO('{"hosts":["a", "b"]}') elif path == secrets_path: return io.StringIO("WANDB_TEST_SECRET=TRUE") else: return original(path, *args, **kwargs)
python
tests/pytest_tests/unit_tests_old/utils/utils.py
143
151
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
585
mock_k8s
def mock_k8s(mocker): env = {} token_path = "/var/run/secrets/kubernetes.io/serviceaccount/token" # crt_path = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" orig_exist = os.path.exists def exists(path): return True if path in token_path else orig_exist(path) def magic(path, *args, **kwargs): if path == token_path: return io.StringIO("token") mocker.patch("wandb.util.open", magic, create=True) mocker.patch("wandb.util.os.path.exists", exists) env["KUBERNETES_SERVICE_HOST"] = "k8s" env["KUBERNETES_PORT_443_TCP_PORT"] = "123" env["HOSTNAME"] = "test" return env
python
tests/pytest_tests/unit_tests_old/utils/utils.py
159
177
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
586
exists
def exists(path): return True if path in token_path else orig_exist(path)
python
tests/pytest_tests/unit_tests_old/utils/utils.py
165
166
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
587
magic
def magic(path, *args, **kwargs): if path == token_path: return io.StringIO("token")
python
tests/pytest_tests/unit_tests_old/utils/utils.py
168
170
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
588
__init__
def __init__(self, response): self.response = response self.mock = MagicMock()
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
10
12
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
589
__enter__
def __enter__(self): return self
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
14
15
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
590
__exit__
def __exit__(self, *args): pass
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
17
18
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
591
raise_for_status
def raise_for_status(self): # convert flask Response to requests Response response = requests.Response() response.status_code = self.response.status_code if self.response.status_code == 429: response._content = b'{"error": "rate limit exceeded"}' raise requests.exceptions.HTTPError(response=response) elif self.response.status_code >= 400: response._content = b"Bad Request" raise requests.exceptions.HTTPError(response=response)
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
20
29
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
592
status_code
def status_code(self): return self.response.status_code
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
32
33
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
593
content
def content(self): return self.response.data
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
36
37
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
594
text
def text(self): return self.response.data.decode("utf-8")
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
40
41
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
595
headers
def headers(self): return self.response.headers
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
44
45
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
596
raw
def raw(self): return self.mock
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
48
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
597
reason
def reason(self): return "tests"
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
52
53
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
598
iter_content
def iter_content(self, chunk_size=1024): yield self.response.data
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
55
56
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
599
json
def json(self): str_data = self.response.data.decode("utf-8") return json.loads(str_data) if str_data else {}
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
58
60
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
600
__init__
def __init__(self, app, ctx): self.app = app self.client = app.test_client() self.ctx = ctx self.mock = MagicMock() self._lock = threading.Lock()
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
64
69
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }