forked from callmesora/llmops-python-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_services.py
59 lines (53 loc) · 2.18 KB
/
test_services.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# %% IMPORTS
import _pytest.logging as pl
import mlflow
from llmops_project.io import services
# %% SERVICES
def test_logger_service(
logger_service: services.LoggerService, logger_caplog: pl.LogCaptureFixture
) -> None:
# given
service = logger_service
logger = service.logger()
# when
logger.debug("DEBUG")
logger.error("ERROR")
# then
assert "DEBUG" in logger_caplog.messages, "Debug message should be logged!"
assert "ERROR" in logger_caplog.messages, "Error message should be logged!"
def test_mlflow_service(mlflow_service: services.MlflowService) -> None:
# given
service = mlflow_service
run_config = mlflow_service.RunConfig(
name="testing",
tags={"service": "mlflow"},
description="a test run.",
log_system_metrics=True,
)
# when
client = service.client()
with service.run_context(run_config=run_config) as context:
pass
finished = client.get_run(run_id=context.info.run_id)
# then
# - run
assert run_config.tags is not None, "Run config tags should be set!"
# - mlflow
assert service.tracking_uri == mlflow.get_tracking_uri(), "Tracking URI should be the same!"
assert service.registry_uri == mlflow.get_registry_uri(), "Registry URI should be the same!"
assert mlflow.get_experiment_by_name(service.experiment_name), "Experiment should be setup!"
# - client
assert service.tracking_uri == client.tracking_uri, "Tracking URI should be the same!"
assert service.registry_uri == client._registry_uri, "Tracking URI should be the same!"
assert client.get_experiment_by_name(service.experiment_name), "Experiment should be setup!"
# - context
assert context.info.run_name == run_config.name, "Context name should be the same!"
assert (
run_config.description in context.data.tags.values()
), "Context desc. should be in tags values!"
assert (
context.data.tags.items() > run_config.tags.items()
), "Context tags should be a subset of the given tags!"
assert context.info.status == "RUNNING", "Context should be running!"
# - finished
assert finished.info.status == "FINISHED", "Finished should be finished!"