Skip to content

Commit ccf5e21

Browse files
committed
basic linting
1 parent 045db3f commit ccf5e21

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/loki_test.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
pytestmark = pytest.mark.anyio
2626

27+
2728
@pytest.fixture
2829
def mcp_url():
2930
return os.environ.get("MCP_GRAFANA_URL", DEFAULT_MCP_URL)
@@ -46,7 +47,6 @@ async def mcp_client(mcp_url, grafana_headers):
4647
write,
4748
):
4849
async with ClientSession(read, write) as session:
49-
# Initialize the connection
5050
await session.initialize()
5151
yield session
5252

@@ -81,7 +81,9 @@ async def test_loki(model: str, mcp_client: ClientSession):
8181
# Verify Loki datasource exists
8282
loki_datasources = [ds for ds in datasources_data if ds.get("type") == "loki"]
8383
assert len(loki_datasources) > 0, "No Loki datasource found"
84-
print(f"\nFound Loki datasource: {loki_datasources[0]['name']} (uid: {loki_datasources[0]['uid']})")
84+
print(
85+
f"\nFound Loki datasource: {loki_datasources[0]['name']} (uid: {loki_datasources[0]['uid']})"
86+
)
8587

8688
# Call the LLM including the tool call result.
8789
response = await acompletion(
@@ -109,7 +111,7 @@ async def test_loki(model: str, mcp_client: ClientSession):
109111
)
110112

111113
# Check that the response has some log lines.
112-
content = response.choices[0].message.content # type: ignore
114+
content = response.choices[0].message.content
113115
log_lines_checker = CustomLLMBooleanEvaluator(
114116
settings=CustomLLMBooleanSettings(
115117
prompt="Does the response contain specific information that could only come from a Loki datasource? This could be actual log lines with timestamps, container names, or a summary that references specific log data. The response should show evidence of real data rather than generic statements.",
@@ -149,7 +151,9 @@ async def test_loki_container_labels(model: str, mcp_client: ClientSession):
149151
# Verify Loki datasource exists
150152
loki_datasources = [ds for ds in datasources_data if ds.get("type") == "loki"]
151153
assert len(loki_datasources) > 0, "No Loki datasource found"
152-
print(f"\nFound Loki datasource: {loki_datasources[0]['name']} (uid: {loki_datasources[0]['uid']})")
154+
print(
155+
f"\nFound Loki datasource: {loki_datasources[0]['name']} (uid: {loki_datasources[0]['uid']})"
156+
)
153157

154158
# Call the LLM including the tool call result.
155159
response = await acompletion(
@@ -165,10 +169,7 @@ async def test_loki_container_labels(model: str, mcp_client: ClientSession):
165169
response,
166170
mcp_client,
167171
"list_loki_label_values",
168-
{
169-
"datasourceUid": "loki",
170-
"labelName": "container"
171-
},
172+
{"datasourceUid": "loki", "labelName": "container"},
172173
)
173174
)
174175

@@ -180,7 +181,7 @@ async def test_loki_container_labels(model: str, mcp_client: ClientSession):
180181
)
181182

182183
# Check that the response provides a meaningful summary of container labels
183-
content = response.choices[0].message.content # type: ignore
184+
content = response.choices[0].message.content
184185
label_checker = CustomLLMBooleanEvaluator(
185186
settings=CustomLLMBooleanSettings(
186187
prompt="Does the response provide a clear and organized list of container names found in the logs? It should present the container names in a readable format and may include additional context about their usage.",
@@ -219,8 +220,12 @@ async def assert_and_handle_tool_call(
219220

220221
if expected_args:
221222
for key, value in expected_args.items():
222-
assert key in arguments, f"Missing required argument '{key}' in tool call"
223-
assert arguments[key] == value, f"Argument '{key}' has wrong value. Expected: {value}, Got: {arguments[key]}"
223+
assert key in arguments, (
224+
f"Missing required argument '{key}' in tool call"
225+
)
226+
assert arguments[key] == value, (
227+
f"Argument '{key}' has wrong value. Expected: {value}, Got: {arguments[key]}"
228+
)
224229
result = await mcp_client.call_tool(tool_call.function.name, arguments)
225230
# Assume each tool returns a single text content for now
226231
assert len(result.content) == 1

0 commit comments

Comments
 (0)