1
1
"""Test cases for append_text_file_contents handler."""
2
2
3
3
import os
4
- from typing import Any , Dict
4
+ from typing import Any , Dict , Generator
5
5
6
6
import pytest
7
7
@@ -19,7 +19,7 @@ def test_dir(tmp_path: str) -> str:
19
19
20
20
21
21
@pytest .fixture
22
- def cleanup_files () -> None :
22
+ def cleanup_files () -> Generator [ None , None , None ] :
23
23
"""Clean up any test files after each test."""
24
24
yield
25
25
# Add cleanup code if needed
@@ -56,7 +56,7 @@ async def test_append_text_file_success(test_dir: str, cleanup_files: None) -> N
56
56
# Parse response to check success
57
57
assert len (response ) == 1
58
58
result = response [0 ].text
59
- assert " \" result\ " : \ " ok\" " in result
59
+ assert '" result": "ok"' in result
60
60
61
61
62
62
@pytest .mark .asyncio
@@ -78,7 +78,9 @@ async def test_append_text_file_not_exists(test_dir: str, cleanup_files: None) -
78
78
79
79
80
80
@pytest .mark .asyncio
81
- async def test_append_text_file_hash_mismatch (test_dir : str , cleanup_files : None ) -> None :
81
+ async def test_append_text_file_hash_mismatch (
82
+ test_dir : str , cleanup_files : None
83
+ ) -> None :
82
84
"""Test appending with incorrect file hash."""
83
85
test_file = os .path .join (test_dir , "hash_test.txt" )
84
86
initial_content = "Initial content\n "
@@ -101,7 +103,9 @@ async def test_append_text_file_hash_mismatch(test_dir: str, cleanup_files: None
101
103
102
104
103
105
@pytest .mark .asyncio
104
- async def test_append_text_file_relative_path (test_dir : str , cleanup_files : None ) -> None :
106
+ async def test_append_text_file_relative_path (
107
+ test_dir : str , cleanup_files : None
108
+ ) -> None :
105
109
"""Test attempting to append using a relative path."""
106
110
arguments : Dict [str , Any ] = {
107
111
"path" : "relative_path.txt" ,
@@ -125,17 +129,23 @@ async def test_append_text_file_missing_args() -> None:
125
129
126
130
# Test missing contents
127
131
with pytest .raises (RuntimeError ) as exc_info :
128
- await append_handler .run_tool ({"path" : "/absolute/path.txt" , "file_hash" : "hash" })
132
+ await append_handler .run_tool (
133
+ {"path" : "/absolute/path.txt" , "file_hash" : "hash" }
134
+ )
129
135
assert "Missing required argument: contents" in str (exc_info .value )
130
136
131
137
# Test missing file_hash
132
138
with pytest .raises (RuntimeError ) as exc_info :
133
- await append_handler .run_tool ({"path" : "/absolute/path.txt" , "contents" : "content\n " })
139
+ await append_handler .run_tool (
140
+ {"path" : "/absolute/path.txt" , "contents" : "content\n " }
141
+ )
134
142
assert "Missing required argument: file_hash" in str (exc_info .value )
135
143
136
144
137
145
@pytest .mark .asyncio
138
- async def test_append_text_file_custom_encoding (test_dir : str , cleanup_files : None ) -> None :
146
+ async def test_append_text_file_custom_encoding (
147
+ test_dir : str , cleanup_files : None
148
+ ) -> None :
139
149
"""Test appending with custom encoding."""
140
150
test_file = os .path .join (test_dir , "encode_test.txt" )
141
151
initial_content = "こんにちは\n "
@@ -147,7 +157,9 @@ async def test_append_text_file_custom_encoding(test_dir: str, cleanup_files: No
147
157
148
158
# Get file hash for append operation
149
159
editor = TextEditor ()
150
- _ , _ , _ , file_hash , _ , _ = await editor .read_file_contents (test_file , encoding = "utf-8" )
160
+ _ , _ , _ , file_hash , _ , _ = await editor .read_file_contents (
161
+ test_file , encoding = "utf-8"
162
+ )
151
163
152
164
# Append content using handler with specified encoding
153
165
arguments : Dict [str , Any ] = {
@@ -166,4 +178,4 @@ async def test_append_text_file_custom_encoding(test_dir: str, cleanup_files: No
166
178
# Parse response to check success
167
179
assert len (response ) == 1
168
180
result = response [0 ].text
169
- assert " \" result\ " : \ " ok\" " in result
181
+ assert '" result": "ok"' in result
0 commit comments