Skip to content

Commit 5248112

Browse files
fixing pylint issues
1 parent 9a2934c commit 5248112

File tree

10 files changed

+55
-6
lines changed

10 files changed

+55
-6
lines changed

src/datu/telemetry/product/events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Telemetry events for product usage."""
2+
13
from typing import Any, ClassVar, Dict
24

35
from datu.app_config import settings

src/datu/telemetry/product/posthog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""PostHog telemetry client for product usage tracking."""
2+
13
import importlib
24
import logging
35
import platform

tests/integrations/sql_server/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Common fixtures for tests in integrations sql_server module ."""
22

3-
# pylint: disable=redefined-outer-name
3+
# pylint: disable=redefined-outer-name disable=unused-argument disable=import-outside-toplevel
44
import pytest
55

66

tests/routers/test_chat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# tests/routers/test_chat.py
1+
"""Test suite for the chat router."""
2+
23
import pytest
34
from fastapi import FastAPI
45
from fastapi.testclient import TestClient
@@ -8,6 +9,7 @@
89

910

1011
def _client() -> TestClient:
12+
"""Create a test client for the chat router."""
1113
app = FastAPI()
1214
app.include_router(chat.router, prefix="/chat/sql")
1315
return TestClient(app)
@@ -18,6 +20,8 @@ def _client() -> TestClient:
1820

1921
@pytest.mark.asyncio
2022
async def test_happy_path_with_mcp(monkeypatch):
23+
"""Test that the happy path with MCP enabled works correctly."""
24+
2125
async def fake_generate_response(_msgs, _sys):
2226
return "Query name: Sales\n```sql\nSELECT 1;\n```"
2327

@@ -36,6 +40,8 @@ async def fake_generate_response(_msgs, _sys):
3640

3741
@pytest.mark.asyncio
3842
async def test_error_path_with_mcp(monkeypatch):
43+
"""Test that the error path with MCP enabled works correctly."""
44+
3945
async def boom(*_a, **_k):
4046
raise RuntimeError("LLM down")
4147

@@ -55,6 +61,8 @@ async def boom(*_a, **_k):
5561

5662
@pytest.mark.asyncio
5763
async def test_passthrough_to_generate_sql_core(monkeypatch):
64+
"""Test that the passthrough to generate_sql_core works correctly."""
65+
5866
async def fake_generate_sql_core(request: ChatRequest):
5967
return {"assistant_response": "core path", "queries": []}
6068

tests/services/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def cached_schema():
3838

3939
@staticmethod
4040
def raw_schema_dict():
41+
"""Return a raw schema dictionary."""
4142
return {
4243
"profile_name": "test_profile",
4344
"output_name": "test_output",
@@ -58,6 +59,8 @@ def raw_schema_dict():
5859

5960
@pytest.fixture
6061
def sample_schema():
62+
"""Return a function that can generate schemas with parameters."""
63+
6164
# Return a function that can generate schemas with parameters
6265
def _factory(timestamp: float = 1234567890.0):
6366
return SchemaTestFixtures.sample_schema(timestamp=timestamp)
@@ -67,4 +70,5 @@ def _factory(timestamp: float = 1234567890.0):
6770

6871
@pytest.fixture
6972
def raw_schema_dict():
73+
"""Return a raw schema dictionary."""
7074
return SchemaTestFixtures.raw_schema_dict()

tests/services/test_sql_generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from src.datu.services.sql_generator import core
2424
from src.datu.services.sql_generator.normalizer import normalize_for_preview
2525

26+
# pylint: disable=redefined-outer-name disable=unused-argument disable=import-outside-toplevel
27+
2628

2729
@pytest.fixture(autouse=True)
2830
def _reset_db_connector(monkeypatch):

tests/telemetry/product/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
"""Common fixtures for tests in telemetry product module."""
2+
13
import pytest
24

35
from datu.telemetry.product.events import ProductTelemetryEvent
46

57

8+
# pylint: disable=import-outside-toplevel
69
@pytest.fixture
710
def sample_event_data():
11+
"""Fixture for sample event data."""
812
return {
913
"event_name": "test_event",
1014
"user_id": "12345",
@@ -15,6 +19,7 @@ def sample_event_data():
1519

1620
@pytest.fixture
1721
def event(sample_event_data):
22+
"""Fixture for a ProductTelemetryEvent."""
1823
return ProductTelemetryEvent(
1924
event_name=sample_event_data["event_name"],
2025
user_id=sample_event_data["user_id"],
@@ -25,18 +30,21 @@ def event(sample_event_data):
2530

2631
@pytest.fixture
2732
def sample_event():
33+
"""Fixture for a sample ProductTelemetryEvent."""
2834
return ProductTelemetryEvent(foo="bar")
2935

3036

3137
@pytest.fixture
3238
def telemetry_settings():
39+
"""Fixture for telemetry settings."""
3340
from datu.telemetry.config import TelemetryConfig
3441

3542
return TelemetryConfig(api_key="dummy_key", package_name="datu-core")
3643

3744

3845
@pytest.fixture
3946
def posthog_client(telemetry_settings):
47+
"""Fixture for PostHog client."""
4048
from datu.telemetry.product.posthog import PostHogClient
4149

4250
return PostHogClient(telemetry_settings=telemetry_settings)

tests/telemetry/product/test_events.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1+
"""Tests for telemetry product events."""
2+
13
import pytest
24

35
from datu.telemetry.product.events import MCPClientEvent, OpenAIEvent, ProductTelemetryEvent
46

57

68
def test_event_initialization(event, sample_event_data):
9+
"""Test that event initializes correctly with given data."""
710
assert event.properties["event_name"] == sample_event_data["event_name"]
811
assert event.properties["user_id"] == sample_event_data["user_id"]
912
assert event.properties["timestamp"] == sample_event_data["timestamp"]
1013
assert event.properties["properties"] == sample_event_data["properties"]
1114

1215

1316
def test_event_name_and_batch_key(event):
17+
"""Test that event name and batch key are set correctly."""
1418
assert event.name == "ProductTelemetryEvent"
1519
assert event.batch_key == event.name
1620

1721

1822
def test_batching_same_type(event):
23+
"""Test that batching works for events of the same type."""
1924
other = ProductTelemetryEvent(event_name="other_event")
2025
batched = event.batch(other)
2126

@@ -25,6 +30,8 @@ def test_batching_same_type(event):
2530

2631

2732
def test_batching_different_type_raises():
33+
"""Test that batching raises an error for events of different types."""
34+
2835
class AnotherEvent(ProductTelemetryEvent):
2936
pass
3037

@@ -35,6 +42,7 @@ class AnotherEvent(ProductTelemetryEvent):
3542

3643

3744
def test_batch_size_increment(event):
45+
"""Test that batch size increments correctly."""
3846
# Initial batch_size
3947
assert event.batch_size == 1
4048
event.batch(ProductTelemetryEvent())
@@ -44,6 +52,7 @@ def test_batch_size_increment(event):
4452

4553

4654
def test_mcp_client_event_properties():
55+
"""Test that MCPClientEvent initializes correctly with given data."""
4756
servers = ["playwright", "puppeteer"]
4857
event = MCPClientEvent(server_names=servers)
4958

@@ -56,7 +65,8 @@ def test_mcp_client_event_properties():
5665

5766

5867
def test_openai_event_properties():
59-
from datu.app_config import get_app_settings
68+
"""Test that OpenAIEvent initializes correctly with given data."""
69+
from datu.app_config import get_app_settings # pylint: disable=import-outside-toplevel
6070

6171
app_settings = get_app_settings()
6272
data = {"user_id": "123", "action": "test"}

tests/telemetry/product/test_posthog.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
"""Tests for PostHog telemetry client."""
2+
3+
from pathlib import Path
14
from unittest.mock import patch
25

6+
# pylint: disable=import-outside-toplevel disable=redefined-outer-name disable=unused-argument
7+
38

49
def test_posthog_client_initialization(posthog_client, telemetry_settings):
10+
"""Test that PostHogClient initializes correctly."""
511
from datu.telemetry.product.posthog import PostHogClient
612

713
assert posthog_client.settings == telemetry_settings
@@ -12,6 +18,7 @@ def test_posthog_client_initialization(posthog_client, telemetry_settings):
1218

1319

1420
def test_user_id_creation(tmp_path):
21+
"""Test that user ID is created and read correctly."""
1522
from datu.telemetry.config import TelemetryConfig
1623
from datu.telemetry.product.posthog import PostHogClient
1724

@@ -30,8 +37,7 @@ def test_user_id_creation(tmp_path):
3037

3138

3239
def test_user_id_fallback_patch():
33-
from pathlib import Path
34-
40+
"""Test that user ID falls back to unknown when file access fails."""
3541
from datu.telemetry.config import TelemetryConfig
3642
from datu.telemetry.product.posthog import PostHogClient
3743

@@ -47,6 +53,7 @@ def test_user_id_fallback_patch():
4753

4854

4955
def test_base_context(monkeypatch):
56+
"""Test that base context is created correctly."""
5057
from datu.telemetry.config import TelemetryConfig
5158
from datu.telemetry.product.posthog import PostHogClient
5259

@@ -61,6 +68,7 @@ def test_base_context(monkeypatch):
6168

6269

6370
def test_capture_single_event(monkeypatch, posthog_client, sample_event):
71+
"""Test that a single event is captured correctly."""
6472
# Ensure _send is called
6573
called = {}
6674

@@ -74,6 +82,7 @@ def fake_send(event):
7482

7583

7684
def test_capture_batching(monkeypatch):
85+
"""Test that event batching works correctly."""
7786
from datu.telemetry.config import TelemetryConfig
7887
from datu.telemetry.product.events import ProductTelemetryEvent
7988
from datu.telemetry.product.posthog import PostHogClient

tests/telemetry/test_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
"""Tests for telemetry configuration."""
2+
3+
14
def test_config():
2-
from datu.telemetry.config import get_telemetry_settings
5+
"""Test that telemetry settings are loaded correctly."""
6+
from datu.telemetry.config import get_telemetry_settings # pylint: disable=import-outside-toplevel
37

48
settings = get_telemetry_settings()
59
assert settings.api_key == "phc_m74dfR9nLpm2nipvkL2swyFDtNuQNC9o2FL2CSbh6Je"

0 commit comments

Comments
 (0)