Skip to content

Commit 2afc4a0

Browse files
committed
test: fix ruff issues
1 parent 6877dd4 commit 2afc4a0

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

tests/server/test_id_generator.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
"""Tests for IDGenerator abstract base class."""
22
import uuid
3+
34
from unittest.mock import patch
45

56
import pytest
67

7-
from a2a.server.id_generator import IDGeneratorContext, IDGenerator, UUIDGenerator
8+
from pydantic import ValidationError
9+
10+
from a2a.server.id_generator import (
11+
IDGenerator,
12+
IDGeneratorContext,
13+
UUIDGenerator,
14+
)
815

916

1017
class TestIDGeneratorContext:
1118
"""Tests for IDGeneratorContext."""
1219

1320
def test_context_creation_with_all_fields(self):
1421
"""Test creating context with all fields populated."""
15-
context = IDGeneratorContext(task_id="task_123", context_id="context_456")
16-
assert context.task_id == "task_123"
17-
assert context.context_id == "context_456"
22+
context = IDGeneratorContext(task_id='task_123', context_id='context_456')
23+
assert context.task_id == 'task_123'
24+
assert context.context_id == 'context_456'
1825

1926
def test_context_creation_with_defaults(self):
2027
"""Test creating context with default None values."""
@@ -24,20 +31,18 @@ def test_context_creation_with_defaults(self):
2431

2532
def test_context_creation_with_partial_fields(self):
2633
"""Test creating context with only some fields populated."""
27-
context = IDGeneratorContext(task_id="task_123")
28-
assert context.task_id == "task_123"
34+
context = IDGeneratorContext(task_id='task_123')
35+
assert context.task_id == 'task_123'
2936
assert context.context_id is None
3037

3138
def test_context_mutability(self):
3239
"""Test that context fields can be updated (Pydantic models are mutable by default)."""
33-
context = IDGeneratorContext(task_id="task_123")
34-
context.task_id = "task_456"
35-
assert context.task_id == "task_456"
40+
context = IDGeneratorContext(task_id='task_123')
41+
context.task_id = 'task_456'
42+
assert context.task_id == 'task_456'
3643

3744
def test_context_validation(self):
3845
"""Test that context raises validation error for invalid types."""
39-
from pydantic import ValidationError # pylint: disable=C0415
40-
4146
with pytest.raises(ValidationError):
4247
IDGeneratorContext(task_id={"not": "a string"}) # noqa
4348

@@ -48,26 +53,26 @@ class TestIDGenerator:
4853
def test_cannot_instantiate_abstract_class(self):
4954
"""Test that IDGenerator cannot be instantiated directly."""
5055
with pytest.raises(TypeError):
51-
IDGenerator() # noqa pylint: disable=E0110
56+
IDGenerator()
5257

5358
def test_subclass_must_implement_generate(self):
5459
"""Test that subclasses must implement the generate method."""
5560

56-
class IncompleteGenerator(IDGenerator): # noqa pylint: disable=C0115,R0903
61+
class IncompleteGenerator(IDGenerator):
5762
pass
5863

5964
with pytest.raises(TypeError):
60-
IncompleteGenerator() # noqa pylint: disable=E0110
65+
IncompleteGenerator()
6166

6267
def test_valid_subclass_implementation(self):
6368
"""Test that a valid subclass can be instantiated."""
6469

6570
class ValidGenerator(IDGenerator): # pylint: disable=C0115,R0903
6671
def generate(self, context: IDGeneratorContext) -> str:
67-
return "test_id"
72+
return 'test_id'
6873

6974
generator = ValidGenerator()
70-
assert generator.generate(IDGeneratorContext()) == "test_id"
75+
assert generator.generate(IDGeneratorContext()) == 'test_id'
7176

7277

7378
class TestUUIDGenerator:
@@ -98,8 +103,8 @@ def test_generate_returns_uuid_version_4(self):
98103
def test_generate_ignores_context(self):
99104
"""Test that generate ignores the context parameter."""
100105
generator = UUIDGenerator()
101-
context1 = IDGeneratorContext(task_id="task_1", context_id="context_1")
102-
context2 = IDGeneratorContext(task_id="task_2", context_id="context_2")
106+
context1 = IDGeneratorContext(task_id='task_1', context_id='context_1')
107+
context2 = IDGeneratorContext(task_id='task_2', context_id='context_2')
103108
result1 = generator.generate(context1)
104109
result2 = generator.generate(context2)
105110
uuid.UUID(result1)
@@ -125,7 +130,7 @@ def test_generate_with_empty_context(self):
125130
def test_generate_with_populated_context(self):
126131
"""Test that generate works with a populated context."""
127132
generator = UUIDGenerator()
128-
context = IDGeneratorContext(task_id="task_123", context_id="context_456")
133+
context = IDGeneratorContext(task_id='task_123', context_id='context_456')
129134
result = generator.generate(context)
130135
assert isinstance(result, str)
131136
uuid.UUID(result)

0 commit comments

Comments
 (0)