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
601
set_context
def set_context(self, key, value): with self._lock: self.ctx[key] = value
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
71
73
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
602
Session
def Session(self): return self
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
75
76
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
603
RequestException
def RequestException(self): return requests.RequestException
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
79
80
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
604
HTTPError
def HTTPError(self): return requests.HTTPError
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
83
84
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
605
models
def models(self): return self.mock
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
87
88
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
606
headers
def headers(self): return {}
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
91
92
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
607
__version__
def __version__(self): return requests.__version__
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
95
96
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
608
utils
def utils(self): return requests.utils
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
99
100
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
609
exceptions
def exceptions(self): return requests.exceptions
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
103
104
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
610
packages
def packages(self): return requests.packages
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
107
108
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
611
adapters
def adapters(self): return requests.adapters
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
111
112
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
612
mount
def mount(self, *args): pass
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
114
115
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
613
_clean_kwargs
def _clean_kwargs(self, kwargs): if "auth" in kwargs: del kwargs["auth"] if "timeout" in kwargs: del kwargs["timeout"] if "cookies" in kwargs: del kwargs["cookies"] if "params" in kwargs: del kwargs["params"] if "stream" in kwargs: del kwargs["stream"] if "verify" in kwargs: del kwargs["verify"] if "allow_redirects" in kwargs: del kwargs["allow_redirects"] if "files" in kwargs: del kwargs["files"] if "cert" in kwargs: del kwargs["cert"] if "hosts" in kwargs: del kwargs["hosts"] if "location_mode" in kwargs: del kwargs["location_mode"] if "headers" in kwargs: # We convert our headers to a dict to avoid requests mocking madness kwargs["headers"] = dict(kwargs["headers"]) return kwargs
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
117
143
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
614
_store_request
def _store_request(self, url, body): parts = url.split("?") key = parts[0].split("/")[-1] if len(parts) > 1: # To make assertions easier, we remove the run from storage requests key = key + "?" + parts[1].split("&run=")[0] with self._lock: # Azure tests use "storage" as the final path of their requests if key == "storage": key = "storage?file=azure" self.ctx[key] = self.ctx.get(key, []) self.ctx[key].append(body)
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
145
156
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
615
_inject
def _inject(self, method, url, kwargs): pre_request = dict(method=method, url=url, kwargs=kwargs) inject = InjectRequestsParse(self.ctx).find(pre_request=pre_request) if inject: if inject.requests_error: if inject.requests_error is True: raise requests.exceptions.RetryError() raise requests.exceptions.ConnectionError()
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
158
165
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
616
post
def post(self, url, **kwargs): self._inject("post", url, kwargs) self._store_request(url, kwargs.get("json")) return ResponseMock(self.client.post(url, **self._clean_kwargs(kwargs)))
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
167
170
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
617
put
def put(self, url, **kwargs): self._inject("put", url, kwargs) self._store_request(url, kwargs.get("json")) return ResponseMock(self.client.put(url, **self._clean_kwargs(kwargs)))
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
172
175
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
618
get
def get(self, url, **kwargs): self._inject("get", url, kwargs) self._store_request(url, kwargs.get("json")) return ResponseMock(self.client.get(url, **self._clean_kwargs(kwargs)))
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
177
180
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
619
request
def request(self, method, url, **kwargs): if method.lower() == "get": return self.get(url, **kwargs) elif method.lower() == "post": return self.post(url, **kwargs) elif method.lower() == "put": return self.put(url, **kwargs) else: message = "Request method not implemented: %s" % method raise requests.RequestException(message)
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
182
191
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
620
__repr__
def __repr__(self): return "<W&B Mocked Request class>"
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
193
194
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
621
__init__
def __init__(self, path_suffix=None, count=None, query_str=None): self._path_suffix = path_suffix self._count = count self._query_str = query_str
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
198
201
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
622
_as_dict
def _as_dict(self): r = {} if self._path_suffix: r["path_suffix"] = self._path_suffix if self._count: r["count"] = self._count if self._query_str: r["query_str"] = self._query_str return r
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
203
211
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
623
__init__
def __init__(self, response=None, http_status=None, requests_error=None): self.response = response self.http_status = http_status self.requests_error = requests_error
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
215
218
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
624
__str__
def __str__(self): return f"Action({vars(self)})"
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
220
221
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
625
__init__
def __init__(self, ctx): self._ctx = ctx
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
225
226
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
626
find
def find(self, request=None, pre_request=None): inject = self._ctx.get("inject") if not inject: return request_path = "" if request: request_path = request.path if pre_request: url = pre_request["url"] parsed = urllib.parse.urlparse(url) request_path = parsed.path rules = inject.get("rules", []) for r in rules: # print("INJECT_REQUEST: check rule =", r, request_path) match = r.get("match") if not match: continue # TODO: make matching better when we have more to do count = match.get("count") path_suffix = match.get("path_suffix") query_str = match.get("query_str") if query_str and request: req_url = request.url parsed = urllib.parse.urlparse(req_url) req_qs = parsed.query if query_str != req_qs: # print("NOMATCH", query_str, req_qs) continue if path_suffix: if request_path.endswith(path_suffix): requests_error = r.get("requests_error") response = r.get("response") http_status = r.get("http_status") # print("INJECT_REQUEST: match =", r, requests_error, response, http_status) # requests_error is for pre_request checks only if requests_error and not pre_request: continue if count is not None: if count == 0: continue match["count"] = count - 1 action = InjectRequestsAction() if response: action.response = response if http_status: action.http_status = http_status if requests_error: action.requests_error = requests_error # print("INJECT_REQUEST: action =", action) return action return None
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
228
281
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
627
__init__
def __init__(self, ctx): self._ctx = ctx self.Match = InjectRequestsMatch
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
287
289
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
628
add
def add(self, match, response=None, http_status=None, requests_error=None): ctx_inject = self._ctx.setdefault("inject", {}) ctx_rules = ctx_inject.setdefault("rules", []) rule = {} rule["match"] = match._as_dict() if response: rule["response"] = response if http_status: rule["http_status"] = http_status if requests_error: rule["requests_error"] = requests_error ctx_rules.append(rule)
python
tests/pytest_tests/unit_tests_old/utils/mock_requests.py
291
302
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
629
internal_result_q
def internal_result_q(): return Queue()
python
tests/pytest_tests/system_tests/conftest.py
66
67
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
630
internal_sender_q
def internal_sender_q(): return Queue()
python
tests/pytest_tests/system_tests/conftest.py
71
72
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
631
internal_writer_q
def internal_writer_q(): return Queue()
python
tests/pytest_tests/system_tests/conftest.py
76
77
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
632
internal_record_q
def internal_record_q(): return Queue()
python
tests/pytest_tests/system_tests/conftest.py
81
82
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
633
internal_process
def internal_process(): return MockProcess()
python
tests/pytest_tests/system_tests/conftest.py
86
87
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
634
__init__
def __init__(self): self._alive = True
python
tests/pytest_tests/system_tests/conftest.py
91
92
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
635
is_alive
def is_alive(self): return self._alive
python
tests/pytest_tests/system_tests/conftest.py
94
95
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
636
_internal_mailbox
def _internal_mailbox(): return Mailbox()
python
tests/pytest_tests/system_tests/conftest.py
99
100
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
637
_internal_sender
def _internal_sender( internal_record_q, internal_result_q, internal_process, _internal_mailbox ): return InterfaceQueue( record_q=internal_record_q, result_q=internal_result_q, process=internal_process, mailbox=_internal_mailbox, )
python
tests/pytest_tests/system_tests/conftest.py
104
112
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
638
_internal_context_keeper
def _internal_context_keeper(): context_keeper = context.ContextKeeper() yield context_keeper
python
tests/pytest_tests/system_tests/conftest.py
116
118
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
639
internal_sm
def internal_sm( runner, internal_sender_q, internal_result_q, _internal_sender, _internal_context_keeper, ): def helper(settings): with runner.isolated_filesystem(): sm = SendManager( settings=SettingsStatic(settings.make_static()), record_q=internal_sender_q, result_q=internal_result_q, interface=_internal_sender, context_keeper=_internal_context_keeper, ) return sm yield helper
python
tests/pytest_tests/system_tests/conftest.py
122
140
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
640
helper
def helper(settings): with runner.isolated_filesystem(): sm = SendManager( settings=SettingsStatic(settings.make_static()), record_q=internal_sender_q, result_q=internal_result_q, interface=_internal_sender, context_keeper=_internal_context_keeper, ) return sm
python
tests/pytest_tests/system_tests/conftest.py
129
138
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
641
stopped_event
def stopped_event(): stopped = threading.Event() yield stopped
python
tests/pytest_tests/system_tests/conftest.py
144
146
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
642
internal_hm
def internal_hm( runner, internal_record_q, internal_result_q, internal_writer_q, _internal_sender, stopped_event, _internal_context_keeper, ): def helper(settings): with runner.isolated_filesystem(): hm = HandleManager( settings=SettingsStatic(settings.make_static()), record_q=internal_record_q, result_q=internal_result_q, stopped=stopped_event, writer_q=internal_writer_q, interface=_internal_sender, context_keeper=_internal_context_keeper, ) return hm yield helper
python
tests/pytest_tests/system_tests/conftest.py
150
172
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
643
helper
def helper(settings): with runner.isolated_filesystem(): hm = HandleManager( settings=SettingsStatic(settings.make_static()), record_q=internal_record_q, result_q=internal_result_q, stopped=stopped_event, writer_q=internal_writer_q, interface=_internal_sender, context_keeper=_internal_context_keeper, ) return hm
python
tests/pytest_tests/system_tests/conftest.py
159
170
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
644
internal_wm
def internal_wm( runner, internal_writer_q, internal_result_q, internal_sender_q, _internal_sender, stopped_event, _internal_context_keeper, ): def helper(settings): with runner.isolated_filesystem(): wandb_file = settings.sync_file # this is hacky, but we dont have a clean rundir always # so lets at least make sure we can write to this dir run_dir = Path(wandb_file).parent os.makedirs(run_dir) wm = WriteManager( settings=SettingsStatic(settings.make_static()), record_q=internal_writer_q, result_q=internal_result_q, sender_q=internal_sender_q, interface=_internal_sender, context_keeper=_internal_context_keeper, ) return wm yield helper
python
tests/pytest_tests/system_tests/conftest.py
176
204
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
645
helper
def helper(settings): with runner.isolated_filesystem(): wandb_file = settings.sync_file # this is hacky, but we dont have a clean rundir always # so lets at least make sure we can write to this dir run_dir = Path(wandb_file).parent os.makedirs(run_dir) wm = WriteManager( settings=SettingsStatic(settings.make_static()), record_q=internal_writer_q, result_q=internal_result_q, sender_q=internal_sender_q, interface=_internal_sender, context_keeper=_internal_context_keeper, ) return wm
python
tests/pytest_tests/system_tests/conftest.py
185
202
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
646
internal_get_record
def internal_get_record(): def _get_record(input_q, timeout=None): try: i = input_q.get(timeout=timeout) except Empty: return None return i return _get_record
python
tests/pytest_tests/system_tests/conftest.py
208
216
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
647
_get_record
def _get_record(input_q, timeout=None): try: i = input_q.get(timeout=timeout) except Empty: return None return i
python
tests/pytest_tests/system_tests/conftest.py
209
214
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
648
start_send_thread
def start_send_thread( internal_sender_q, internal_get_record, stopped_event, internal_process ): def start_send(send_manager): def target(): try: while True: payload = internal_get_record( input_q=internal_sender_q, timeout=0.1 ) if payload: send_manager.send(payload) elif stopped_event.is_set(): break except Exception: stopped_event.set() internal_process._alive = False t = threading.Thread(target=target) t.name = "testing-sender" t.daemon = True t.start() return t yield start_send stopped_event.set()
python
tests/pytest_tests/system_tests/conftest.py
220
245
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
649
start_send
def start_send(send_manager): def target(): try: while True: payload = internal_get_record( input_q=internal_sender_q, timeout=0.1 ) if payload: send_manager.send(payload) elif stopped_event.is_set(): break except Exception: stopped_event.set() internal_process._alive = False t = threading.Thread(target=target) t.name = "testing-sender" t.daemon = True t.start() return t
python
tests/pytest_tests/system_tests/conftest.py
223
242
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
650
target
def target(): try: while True: payload = internal_get_record( input_q=internal_sender_q, timeout=0.1 ) if payload: send_manager.send(payload) elif stopped_event.is_set(): break except Exception: stopped_event.set() internal_process._alive = False
python
tests/pytest_tests/system_tests/conftest.py
224
236
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
651
start_write_thread
def start_write_thread( internal_writer_q, internal_get_record, stopped_event, internal_process ): def start_write(write_manager): def target(): try: while True: payload = internal_get_record( input_q=internal_writer_q, timeout=0.1 ) if payload: write_manager.write(payload) elif stopped_event.is_set(): break except Exception: stopped_event.set() internal_process._alive = False t = threading.Thread(target=target) t.name = "testing-writer" t.daemon = True t.start() return t yield start_write stopped_event.set()
python
tests/pytest_tests/system_tests/conftest.py
249
274
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
652
start_write
def start_write(write_manager): def target(): try: while True: payload = internal_get_record( input_q=internal_writer_q, timeout=0.1 ) if payload: write_manager.write(payload) elif stopped_event.is_set(): break except Exception: stopped_event.set() internal_process._alive = False t = threading.Thread(target=target) t.name = "testing-writer" t.daemon = True t.start() return t
python
tests/pytest_tests/system_tests/conftest.py
252
271
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
653
target
def target(): try: while True: payload = internal_get_record( input_q=internal_writer_q, timeout=0.1 ) if payload: write_manager.write(payload) elif stopped_event.is_set(): break except Exception: stopped_event.set() internal_process._alive = False
python
tests/pytest_tests/system_tests/conftest.py
253
265
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
654
start_handle_thread
def start_handle_thread(internal_record_q, internal_get_record, stopped_event): def start_handle(handle_manager): def target(): while True: payload = internal_get_record(input_q=internal_record_q, timeout=0.1) if payload: handle_manager.handle(payload) elif stopped_event.is_set(): break t = threading.Thread(target=target) t.name = "testing-handler" t.daemon = True t.start() return t yield start_handle stopped_event.set()
python
tests/pytest_tests/system_tests/conftest.py
278
295
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
655
start_handle
def start_handle(handle_manager): def target(): while True: payload = internal_get_record(input_q=internal_record_q, timeout=0.1) if payload: handle_manager.handle(payload) elif stopped_event.is_set(): break t = threading.Thread(target=target) t.name = "testing-handler" t.daemon = True t.start() return t
python
tests/pytest_tests/system_tests/conftest.py
279
292
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
656
target
def target(): while True: payload = internal_get_record(input_q=internal_record_q, timeout=0.1) if payload: handle_manager.handle(payload) elif stopped_event.is_set(): break
python
tests/pytest_tests/system_tests/conftest.py
280
286
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
657
_start_backend
def _start_backend( internal_hm, internal_sm, internal_wm, _internal_sender, start_handle_thread, start_write_thread, start_send_thread, ): def start_backend_func(run=None, initial_run=True, initial_start=True): ihm = internal_hm(run.settings) iwm = internal_wm(run.settings) ism = internal_sm(run.settings) ht = start_handle_thread(ihm) wt = start_write_thread(iwm) st = start_send_thread(ism) if initial_run: _run = _internal_sender.communicate_run(run) if initial_start: _internal_sender.communicate_run_start(_run.run) return ht, wt, st yield start_backend_func
python
tests/pytest_tests/system_tests/conftest.py
299
321
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
658
start_backend_func
def start_backend_func(run=None, initial_run=True, initial_start=True): ihm = internal_hm(run.settings) iwm = internal_wm(run.settings) ism = internal_sm(run.settings) ht = start_handle_thread(ihm) wt = start_write_thread(iwm) st = start_send_thread(ism) if initial_run: _run = _internal_sender.communicate_run(run) if initial_start: _internal_sender.communicate_run_start(_run.run) return ht, wt, st
python
tests/pytest_tests/system_tests/conftest.py
308
319
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
659
_stop_backend
def _stop_backend( _internal_sender, # collect_responses, ): def stop_backend_func(threads=None): threads = threads or () handle = _internal_sender.deliver_exit(0) record = handle.wait(timeout=30) assert record server_info_handle = _internal_sender.deliver_request_server_info() result = server_info_handle.wait(timeout=30) assert result # collect_responses.server_info_resp = result.response.server_info_response _internal_sender.join() for t in threads: t.join() yield stop_backend_func
python
tests/pytest_tests/system_tests/conftest.py
325
344
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
660
stop_backend_func
def stop_backend_func(threads=None): threads = threads or () handle = _internal_sender.deliver_exit(0) record = handle.wait(timeout=30) assert record server_info_handle = _internal_sender.deliver_request_server_info() result = server_info_handle.wait(timeout=30) assert result # collect_responses.server_info_resp = result.response.server_info_response _internal_sender.join() for t in threads: t.join()
python
tests/pytest_tests/system_tests/conftest.py
329
342
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
661
backend_interface
def backend_interface(_start_backend, _stop_backend, _internal_sender): @contextmanager def backend_context(run, initial_run=True, initial_start=True): threads = _start_backend( run=run, initial_run=initial_run, initial_start=initial_start, ) try: yield _internal_sender finally: _stop_backend(threads=threads) return backend_context
python
tests/pytest_tests/system_tests/conftest.py
348
361
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
662
backend_context
def backend_context(run, initial_run=True, initial_start=True): threads = _start_backend( run=run, initial_run=initial_run, initial_start=initial_start, ) try: yield _internal_sender finally: _stop_backend(threads=threads)
python
tests/pytest_tests/system_tests/conftest.py
350
359
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
663
publish_util
def publish_util(backend_interface): def publish_util_helper( run, metrics=None, history=None, artifacts=None, files=None, begin_cb=None, end_cb=None, initial_start=False, ): metrics = metrics or [] history = history or [] artifacts = artifacts or [] files = files or [] with backend_interface(run=run, initial_start=initial_start) as interface: if begin_cb: begin_cb(interface) for m in metrics: interface._publish_metric(m) for h in history: interface.publish_history(**h) for a in artifacts: interface.publish_artifact(**a) for f in files: interface.publish_files(**f) if end_cb: end_cb(interface) yield publish_util_helper
python
tests/pytest_tests/system_tests/conftest.py
365
395
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
664
publish_util_helper
def publish_util_helper( run, metrics=None, history=None, artifacts=None, files=None, begin_cb=None, end_cb=None, initial_start=False, ): metrics = metrics or [] history = history or [] artifacts = artifacts or [] files = files or [] with backend_interface(run=run, initial_start=initial_start) as interface: if begin_cb: begin_cb(interface) for m in metrics: interface._publish_metric(m) for h in history: interface.publish_history(**h) for a in artifacts: interface.publish_artifact(**a) for f in files: interface.publish_files(**f) if end_cb: end_cb(interface)
python
tests/pytest_tests/system_tests/conftest.py
366
393
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
665
pytest_addoption
def pytest_addoption(parser): # note: we default to "function" scope to ensure the environment is # set up properly when running the tests in parallel with pytest-xdist. parser.addoption( "--user-scope", default="function", # or "function" or "session" or "module" help='cli to set scope of fixture "user-scope"', ) parser.addoption( "--base-url", default=f"http://localhost:{LOCAL_BASE_PORT}", help='cli to set "base-url"', ) parser.addoption( "--wandb-server-tag", default="master", help="Image tag to use for the wandb server", ) parser.addoption( "--wandb-server-pull", action="store_true", default=False, help="Force pull the latest wandb server image", ) # debug option: creates an admin account that can be used to log in to the # app and inspect the test runs. parser.addoption( "--wandb-debug", action="store_true", default=False, help="Run tests in debug mode", )
python
tests/pytest_tests/system_tests/conftest.py
403
434
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
666
random_string
def random_string(length: int = 12) -> str: """Generate a random string of a given length. :param length: Length of the string to generate. :return: Random string. """ return "".join( secrets.choice(string.ascii_lowercase + string.digits) for _ in range(length) )
python
tests/pytest_tests/system_tests/conftest.py
437
445
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
667
determine_scope
def determine_scope(fixture_name, config): return config.getoption("--user-scope")
python
tests/pytest_tests/system_tests/conftest.py
448
449
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
668
base_url
def base_url(request): return request.config.getoption("--base-url")
python
tests/pytest_tests/system_tests/conftest.py
453
454
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
669
wandb_server_tag
def wandb_server_tag(request): return request.config.getoption("--wandb-server-tag")
python
tests/pytest_tests/system_tests/conftest.py
458
459
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
670
wandb_server_pull
def wandb_server_pull(request): if request.config.getoption("--wandb-server-pull"): return "always" return "missing"
python
tests/pytest_tests/system_tests/conftest.py
463
466
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
671
wandb_debug
def wandb_debug(request): return request.config.getoption("--wandb-debug", default=False)
python
tests/pytest_tests/system_tests/conftest.py
470
471
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
672
check_server_health
def check_server_health( base_url: str, endpoint: str, num_retries: int = 1, sleep_time: int = 1 ) -> bool: """Check if wandb server is healthy. :param base_url: :param num_retries: :param sleep_time: :return: """ for _ in range(num_retries): try: response = requests.get(urllib.parse.urljoin(base_url, endpoint)) if response.status_code == 200: return True time.sleep(sleep_time) except requests.exceptions.ConnectionError: time.sleep(sleep_time) return False
python
tests/pytest_tests/system_tests/conftest.py
474
492
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
673
check_mysql_health
def check_mysql_health(num_retries: int = 1, sleep_time: int = 1): for _ in range(num_retries): try: exit_code = subprocess.call( [ "docker", "exec", "-t", "wandb-local", "/bin/bash", "-c", "sudo mysqladmin ping", ] ) if exit_code == 0: return True time.sleep(sleep_time) except subprocess.CalledProcessError: time.sleep(sleep_time) return False
python
tests/pytest_tests/system_tests/conftest.py
495
514
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
674
check_server_up
def check_server_up( base_url: str, wandb_server_tag: str = "master", wandb_server_pull: Literal["missing", "always"] = "missing", ) -> bool: """Check if wandb server is up and running. If not on the CI and the server is not running, then start it first. :param base_url: :param wandb_server_tag: :param wandb_server_pull: :return: """ app_health_endpoint = "healthz" fixture_url = base_url.replace(LOCAL_BASE_PORT, FIXTURE_SERVICE_PORT) fixture_health_endpoint = "health" if os.environ.get("CI") == "true": return check_server_health(base_url=base_url, endpoint=app_health_endpoint) if not check_server_health(base_url=base_url, endpoint=app_health_endpoint): # start wandb server locally and expose necessary ports to the host command = [ "docker", "run", "--pull", wandb_server_pull, "--rm", "-v", "wandb:/vol", "-p", f"{LOCAL_BASE_PORT}:{LOCAL_BASE_PORT}", "-p", f"{SERVICES_API_PORT}:{SERVICES_API_PORT}", "-p", f"{FIXTURE_SERVICE_PORT}:{FIXTURE_SERVICE_PORT}", "-e", "WANDB_ENABLE_TEST_CONTAINER=true", "--name", "wandb-local", "--platform", "linux/amd64", f"gcr.io/wandb-production/local-testcontainer:{wandb_server_tag}", ] subprocess.Popen(command) # wait for the server to start server_is_up = check_server_health( base_url=base_url, endpoint=app_health_endpoint, num_retries=30 ) if not server_is_up: return False # check that MySQL and fixture service are accessible return check_mysql_health(num_retries=30) and check_server_health( base_url=fixture_url, endpoint=fixture_health_endpoint, num_retries=30 ) return check_mysql_health(num_retries=10) and check_server_health( base_url=fixture_url, endpoint=fixture_health_endpoint, num_retries=10 )
python
tests/pytest_tests/system_tests/conftest.py
517
576
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
675
fixture_fn
def fixture_fn(base_url, wandb_server_tag, wandb_server_pull): def fixture_util( cmd: Union[UserFixtureCommand, AddAdminAndEnsureNoDefaultUser] ) -> bool: endpoint = urllib.parse.urljoin( base_url.replace(LOCAL_BASE_PORT, cmd.port), cmd.endpoint, ) if isinstance(cmd, UserFixtureCommand): data = {"command": cmd.command} if cmd.username: data["username"] = cmd.username if cmd.password: data["password"] = cmd.password if cmd.admin is not None: data["admin"] = cmd.admin elif isinstance(cmd, AddAdminAndEnsureNoDefaultUser): data = [ {"email": f"{cmd.email}@wandb.com", "password": cmd.password}, ] else: raise NotImplementedError(f"{cmd} is not implemented") # trigger fixture print(f"Triggering fixture on {endpoint}: {data}") response = getattr(requests, cmd.method)(endpoint, json=data) if response.status_code != 200: print(response.json()) return False return True # todo: remove this once testcontainer is available on Win if platform.system() == "Windows": pytest.skip("testcontainer is not available on Win") if not check_server_up(base_url, wandb_server_tag, wandb_server_pull): pytest.fail("wandb server is not running") yield fixture_util
python
tests/pytest_tests/system_tests/conftest.py
600
638
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
676
fixture_util
def fixture_util( cmd: Union[UserFixtureCommand, AddAdminAndEnsureNoDefaultUser] ) -> bool: endpoint = urllib.parse.urljoin( base_url.replace(LOCAL_BASE_PORT, cmd.port), cmd.endpoint, ) if isinstance(cmd, UserFixtureCommand): data = {"command": cmd.command} if cmd.username: data["username"] = cmd.username if cmd.password: data["password"] = cmd.password if cmd.admin is not None: data["admin"] = cmd.admin elif isinstance(cmd, AddAdminAndEnsureNoDefaultUser): data = [ {"email": f"{cmd.email}@wandb.com", "password": cmd.password}, ] else: raise NotImplementedError(f"{cmd} is not implemented") # trigger fixture print(f"Triggering fixture on {endpoint}: {data}") response = getattr(requests, cmd.method)(endpoint, json=data) if response.status_code != 200: print(response.json()) return False return True
python
tests/pytest_tests/system_tests/conftest.py
601
629
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
677
user
def user(worker_id: str, fixture_fn, base_url, wandb_debug) -> str: username = f"user-{worker_id}-{random_string()}" command = UserFixtureCommand(command="up", username=username) fixture_fn(command) command = UserFixtureCommand( command="password", username=username, password=username ) fixture_fn(command) with unittest.mock.patch.dict( os.environ, { "WANDB_API_KEY": username, "WANDB_ENTITY": username, "WANDB_USERNAME": username, "WANDB_BASE_URL": base_url, }, ): yield username if not wandb_debug: command = UserFixtureCommand(command="down", username=username) fixture_fn(command)
python
tests/pytest_tests/system_tests/conftest.py
642
664
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
678
debug
def debug(wandb_debug, fixture_fn, base_url): if wandb_debug: admin_username = f"admin-{random_string()}" # disable default user and create an admin account that can be used to log in to the app # and inspect the test runs. command = UserFixtureCommand(command="down", username="local@wandb.com") fixture_fn(command) command = UserFixtureCommand( command="up", username=admin_username, admin=True, ) fixture_fn(command) command = UserFixtureCommand( command="password", username=admin_username, password=admin_username, admin=True, ) fixture_fn(command) command = AddAdminAndEnsureNoDefaultUser( email=admin_username, password=admin_username, ) fixture_fn(command) message = ( f"{ConsoleFormatter.GREEN}" "*****************************************************************\n" "Admin user created for debugging:\n" f"Proceed to {base_url} and log in with the following credentials:\n" f"username: {admin_username}@wandb.com\n" f"password: {admin_username}\n" "*****************************************************************" f"{ConsoleFormatter.END}" ) print(message) yield admin_username print(message) # input("\nPress any key to exit...") # command = UserFixtureCommand(command="down_all") # fixture_fn(command) else: yield None
python
tests/pytest_tests/system_tests/conftest.py
668
712
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
679
relay_server
def relay_server(base_url): """Create a new relay server.""" @contextmanager def relay_server_context(inject: Optional[List[InjectedResponse]] = None): _relay_server = RelayServer(base_url=base_url, inject=inject) try: _relay_server.start() print(f"Relay server started at {_relay_server.relay_url}") with unittest.mock.patch.dict( os.environ, {"WANDB_BASE_URL": _relay_server.relay_url}, ): yield _relay_server print(f"Stopping relay server at {_relay_server.relay_url}") finally: del _relay_server return relay_server_context
python
tests/pytest_tests/system_tests/conftest.py
716
734
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
680
relay_server_context
def relay_server_context(inject: Optional[List[InjectedResponse]] = None): _relay_server = RelayServer(base_url=base_url, inject=inject) try: _relay_server.start() print(f"Relay server started at {_relay_server.relay_url}") with unittest.mock.patch.dict( os.environ, {"WANDB_BASE_URL": _relay_server.relay_url}, ): yield _relay_server print(f"Stopping relay server at {_relay_server.relay_url}") finally: del _relay_server
python
tests/pytest_tests/system_tests/conftest.py
720
732
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
681
wandb_init
def wandb_init(user, test_settings, request): # mirror wandb.sdk.wandb_init.init args, overriding name and entity defaults def init( job_type: Optional[str] = None, dir: Optional[str] = None, config: Union[Dict, str, None] = None, project: Optional[str] = None, entity: Optional[str] = None, reinit: bool = None, tags: Optional[Sequence] = None, group: Optional[str] = None, name: Optional[str] = None, notes: Optional[str] = None, magic: Union[dict, str, bool] = None, config_exclude_keys: Optional[List[str]] = None, config_include_keys: Optional[List[str]] = None, anonymous: Optional[str] = None, mode: Optional[str] = None, allow_val_change: Optional[bool] = None, resume: Optional[Union[bool, str]] = None, force: Optional[bool] = None, tensorboard: Optional[bool] = None, sync_tensorboard: Optional[bool] = None, monitor_gym: Optional[bool] = None, save_code: Optional[bool] = None, id: Optional[str] = None, settings: Union[ "wandb.sdk.wandb_settings.Settings", Dict[str, Any], None ] = None, ): kwargs = dict(locals()) # drop fixtures from kwargs for key in ("user", "test_settings", "request"): kwargs.pop(key, None) # merge settings from request with test_settings request_settings = kwargs.pop("settings", dict()) kwargs["name"] = kwargs.pop("name", request.node.name) run = wandb.init( settings=test_settings(request_settings), **kwargs, ) return run wandb._IS_INTERNAL_PROCESS = False yield init # note: this "simulates" a wandb.init function, so you would have to do # something like: run = wandb_init(...); ...; run.finish()
python
tests/pytest_tests/system_tests/conftest.py
738
785
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
682
init
def init( job_type: Optional[str] = None, dir: Optional[str] = None, config: Union[Dict, str, None] = None, project: Optional[str] = None, entity: Optional[str] = None, reinit: bool = None, tags: Optional[Sequence] = None, group: Optional[str] = None, name: Optional[str] = None, notes: Optional[str] = None, magic: Union[dict, str, bool] = None, config_exclude_keys: Optional[List[str]] = None, config_include_keys: Optional[List[str]] = None, anonymous: Optional[str] = None, mode: Optional[str] = None, allow_val_change: Optional[bool] = None, resume: Optional[Union[bool, str]] = None, force: Optional[bool] = None, tensorboard: Optional[bool] = None, sync_tensorboard: Optional[bool] = None, monitor_gym: Optional[bool] = None, save_code: Optional[bool] = None, id: Optional[str] = None, settings: Union[ "wandb.sdk.wandb_settings.Settings", Dict[str, Any], None ] = None, ): kwargs = dict(locals()) # drop fixtures from kwargs for key in ("user", "test_settings", "request"): kwargs.pop(key, None) # merge settings from request with test_settings request_settings = kwargs.pop("settings", dict()) kwargs["name"] = kwargs.pop("name", request.node.name) run = wandb.init( settings=test_settings(request_settings), **kwargs, ) return run
python
tests/pytest_tests/system_tests/conftest.py
740
780
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
683
server_context
def server_context(base_url): class ServerContext: def __init__(self) -> None: self.api = wandb.Api(overrides={"base_url": base_url}) def get_run(self, run: "wandb.sdk.wandb_run.Run") -> "wandb.apis.public.Run": return self.api.run(run.path) yield ServerContext()
python
tests/pytest_tests/system_tests/conftest.py
789
797
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
684
__init__
def __init__(self) -> None: self.api = wandb.Api(overrides={"base_url": base_url})
python
tests/pytest_tests/system_tests/conftest.py
791
792
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
685
get_run
def get_run(self, run: "wandb.sdk.wandb_run.Run") -> "wandb.apis.public.Run": return self.api.run(run.path)
python
tests/pytest_tests/system_tests/conftest.py
794
795
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
686
inject_file_stream_response
def inject_file_stream_response(base_url, user): def helper( run, body: Union[str, Exception] = "{}", status: int = 200, application_pattern: str = "1", ) -> InjectedResponse: if status > 299: message = body if isinstance(body, str) else "::".join(body.args) body = DeliberateHTTPError(status_code=status, message=message) return InjectedResponse( method="POST", url=( urllib.parse.urljoin( base_url, f"/files/{user}/{run.project or 'uncategorized'}/{run.id}/file_stream", ) ), body=body, status=status, application_pattern=TokenizedCircularPattern(application_pattern), ) yield helper
python
tests/pytest_tests/system_tests/conftest.py
802
825
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
687
helper
def helper( run, body: Union[str, Exception] = "{}", status: int = 200, application_pattern: str = "1", ) -> InjectedResponse: if status > 299: message = body if isinstance(body, str) else "::".join(body.args) body = DeliberateHTTPError(status_code=status, message=message) return InjectedResponse( method="POST", url=( urllib.parse.urljoin( base_url, f"/files/{user}/{run.project or 'uncategorized'}/{run.id}/file_stream", ) ), body=body, status=status, application_pattern=TokenizedCircularPattern(application_pattern), )
python
tests/pytest_tests/system_tests/conftest.py
803
823
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
688
_make_run
def _make_run( tags: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, float]] = None, metrics: Optional[Iterable[Dict[str, float]]] = None, make_artifact_fns: Optional[Iterable[Callable[[], Path]]] = None, batch_size: Optional[int] = None, ): client = MlflowClient() with mlflow.start_run() as run: if tags: mlflow.set_tags(tags) if params: mlflow.log_params(params) if metrics: if batch_size: for batch in batch_metrics(metrics, batch_size): client.log_batch(run.info.run_id, metrics=batch) else: for m in metrics: mlflow.log_metrics(m) if make_artifact_fns: for f in make_artifact_fns: path = f() mlflow.log_artifact(path)
python
tests/pytest_tests/system_tests/test_importers/conftest.py
33
56
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
689
batched
def batched(n, iterable): i = iter(iterable) batch = list(islice(i, n)) while batch: yield batch batch = list(islice(i, n))
python
tests/pytest_tests/system_tests/test_importers/conftest.py
65
70
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
690
batch_metrics
def batch_metrics(metrics, bs: int) -> Iterable[List[Metric]]: step = 0 for i, batch in enumerate(batched(bs, metrics)): batched_metrics = [] for step, metric in enumerate(batch, start=i * bs): for k, v in metric.items(): batched_metrics.append( Metric(k, v, step=step, timestamp=SECONDS_FROM_2023_01_01) ) yield batched_metrics
python
tests/pytest_tests/system_tests/test_importers/conftest.py
73
82
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
691
make_tags
def make_tags(): return st.dictionaries( st.text( min_size=1, max_size=20, alphabet="abcdefghijklmnopqrstuvwxyz1234567890_- ", ), st.text(max_size=20), max_size=10, ).example()
python
tests/pytest_tests/system_tests/test_importers/conftest.py
85
94
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
692
make_params
def make_params(): return { "param_int": st.integers().example(), "param_float": st.floats().example(), "param_str": st.text(max_size=20).example(), "param_bool": st.booleans().example(), "param_list": st.lists(st.integers()).example(), "param_dict": st.dictionaries( st.text(max_size=20), st.integers(), max_size=10 ).example(), "param_tuple": st.tuples(st.integers(), st.integers()).example(), "param_set": st.sets(st.integers()).example(), "param_none": None, }
python
tests/pytest_tests/system_tests/test_importers/conftest.py
97
110
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
693
make_metrics
def make_metrics(n_steps): for _ in range(n_steps): yield { "metric_int": st.integers(min_value=0, max_value=100).example(), "metric_float": st.floats(min_value=0, max_value=100).example(), }
python
tests/pytest_tests/system_tests/test_importers/conftest.py
113
118
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
694
make_artifact_fns
def make_artifact_fns(temp_path: Path) -> Iterable[Callable[[], Path]]: def artifact_fn(): fname = str(uuid.uuid4()) file_path = f"{temp_path}/{fname}.txt" with open(file_path, "w") as f: f.write(f"text from {file_path}") return file_path for _ in range(N_ARTIFACTS_PER_RUN): yield artifact_fn
python
tests/pytest_tests/system_tests/test_importers/conftest.py
121
130
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
695
artifact_fn
def artifact_fn(): fname = str(uuid.uuid4()) file_path = f"{temp_path}/{fname}.txt" with open(file_path, "w") as f: f.write(f"text from {file_path}") return file_path
python
tests/pytest_tests/system_tests/test_importers/conftest.py
122
127
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
696
make_run
def make_run(n_steps, mlflow_batch_size): with tempfile.TemporaryDirectory() as temp_path: _make_run( tags=make_tags(), params=make_params(), metrics=make_metrics(n_steps), make_artifact_fns=make_artifact_fns(temp_path), batch_size=mlflow_batch_size, )
python
tests/pytest_tests/system_tests/test_importers/conftest.py
133
141
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
697
make_exp
def make_exp(n_runs, n_steps, mlflow_batch_size): name = "Experiment " + str(uuid.uuid4()) mlflow.set_experiment(name) # Can't use ProcessPoolExecutor -- it seems to always fail in tests! for _ in range(n_runs): make_run(n_steps, mlflow_batch_size)
python
tests/pytest_tests/system_tests/test_importers/conftest.py
144
150
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
698
log_to_mlflow
def log_to_mlflow( mlflow_tracking_uri: str, n_exps: int = 2, n_runs_per_exp: int = 3, n_steps: int = 1000, mlflow_batch_size: int = 50, ): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=NonInteractiveExampleWarning) mlflow.set_tracking_uri(mlflow_tracking_uri) # Can't use ProcessPoolExecutor -- it seems to always fail in tests! for _ in range(n_exps): make_exp(n_runs_per_exp, n_steps, mlflow_batch_size)
python
tests/pytest_tests/system_tests/test_importers/conftest.py
153
166
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
699
check_mlflow_server_health
def check_mlflow_server_health( base_url: str, endpoint: str, num_retries: int = 1, sleep_time: int = 1 ): for _ in range(num_retries): try: response = requests.get(urllib.parse.urljoin(base_url, endpoint)) if response.status_code == 200: return True time.sleep(sleep_time) except requests.exceptions.ConnectionError: time.sleep(sleep_time) return False
python
tests/pytest_tests/system_tests/test_importers/conftest.py
169
180
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
700
kill_child_processes
def kill_child_processes(parent_pid, sig=signal.SIGTERM): try: parent = psutil.Process(parent_pid) except psutil.NoSuchProcess: return children = parent.children(recursive=True) for process in children: process.send_signal(sig)
python
tests/pytest_tests/system_tests/test_importers/conftest.py
183
190
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }