Skip to content

Commit

Permalink
Integration test progress
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-rogers committed Mar 16, 2024
1 parent 2b1c1a7 commit 6820fc9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions python/tests/api/writer/test_whylabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def teardown_method(self) -> None:
def results(self, pandas_dataframe):
return why.log(pandas=pandas_dataframe)

# TODO: This test fails if you run `poetry run pytest tests/api/writer`
# It passes if you run `make test`.
def test_writer_throws_for_anon_sessions(self, results) -> None:
old_key = os.environ.get(EnvVariableName.WHYLABS_API_KEY.value, None)
if EnvVariableName.WHYLABS_API_KEY.value in os.environ:
Expand Down
16 changes: 8 additions & 8 deletions python/tests/api/writer/test_whylabs_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_whylabs_writer():
success, _ = writer.write(result.profile())
assert success
time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
response: ProfileTracesResponse = dataset_api.get_profile_traces(
org_id=ORG_ID,
dataset_id=MODEL_ID,
Expand All @@ -72,7 +72,7 @@ def test_whylabs_writer_segmented():
writer = WhyLabsWriter()
writer.write(result)
time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
response: ProfileTracesResponse = dataset_api.get_profile_traces(
org_id=ORG_ID,
dataset_id=MODEL_ID,
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_whylabs_writer_reference(segmented: bool, zipped: bool):
success, ref_id = writer.write(result, use_v0=not segmented, zip=zipped)
assert success
time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
response: ReferenceProfileItemResponse = dataset_api.get_reference_profile(
ORG_ID,
MODEL_ID,
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_performance_column():
writer = WhyLabsWriter()
status, _ = writer.tag_custom_performance_column("col1", "perf column", "mean")
assert status
model_api = ModelsApi(writer._whylabs_client._api_client)
model_api = ModelsApi(writer._api_client)
response: EntitySchema = model_api.get_entity_schema(ORG_ID, MODEL_ID)
assert (
response["metrics"]["perf column"]["column"] == "col1"
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_transactions():
writer.commit_transaction()
assert writer._transaction_id is None
time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
response: ProfileTracesResponse = dataset_api.get_profile_traces(
org_id=ORG_ID,
dataset_id=MODEL_ID,
Expand Down Expand Up @@ -246,7 +246,7 @@ def test_transaction_context():
logger.exception("Logging transaction failed")

time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
for trace_id in tids:
response: ProfileTracesResponse = dataset_api.get_profile_traces(
org_id=ORG_ID,
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_transaction_segmented():

writer.commit_transaction()
time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
response: ProfileTracesResponse = dataset_api.get_profile_traces(
org_id=ORG_ID,
dataset_id=MODEL_ID,
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_transaction_distributed():
logger.exception("Logging transaction failed")

time.sleep(SLEEP_TIME) # platform needs time to become aware of the profile
dataset_api = DatasetProfileApi(writer._whylabs_client._api_client)
dataset_api = DatasetProfileApi(writer._api_client)
for trace_id in tids:
response: ProfileTracesResponse = dataset_api.get_profile_traces(
org_id=ORG_ID,
Expand Down
14 changes: 14 additions & 0 deletions python/whylogs/api/writer/whylabs_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ def __init__(
self._reference_profile_name = config.get_whylabs_refernce_profile_name()
self._transaction_id = None

@property
def _api_client(self) -> ApiClient:
if self._whylabs_client._api_client is None:
self._whylabs_client._refresh_client()
return self._whylabs_client._api_client

@property
def _s3_pool(self):
return self._whylabs_client._s3_pool

@property
def _timeout_seconds(self) -> float:
return self._whylabs_client._timeout_seconds

@property
def key_id(self) -> str:
return self._whylabs_client.key_id
Expand Down

0 comments on commit 6820fc9

Please sign in to comment.