11"""Tests for import_chatgpt command."""
22
33import json
4+
45import pytest
56from typer .testing import CliRunner
67
7- from basic_memory .cli .app import import_app , app
8+ from basic_memory .cli .app import app , import_app
89from basic_memory .cli .commands import import_chatgpt
910from basic_memory .config import config
1011from basic_memory .markdown import EntityParser , MarkdownProcessor
@@ -144,7 +145,7 @@ def sample_conversation_with_hidden():
144145def sample_chatgpt_json (tmp_path , sample_conversation ):
145146 """Create a sample ChatGPT JSON file."""
146147 json_file = tmp_path / "conversations.json"
147- with open (json_file , "w" ) as f :
148+ with open (json_file , "w" , encoding = "utf-8" ) as f :
148149 json .dump ([sample_conversation ], f )
149150 return json_file
150151
@@ -167,7 +168,7 @@ async def test_process_chatgpt_json(tmp_path, sample_chatgpt_json):
167168 assert conv_path .exists ()
168169
169170 # Check content formatting
170- content = conv_path .read_text ()
171+ content = conv_path .read_text (encoding = "utf-8" )
171172 assert "# Test Conversation" in content
172173 assert "### User" in content
173174 assert "Hello, this is a test message" in content
@@ -183,14 +184,14 @@ async def test_process_code_blocks(tmp_path, sample_conversation_with_code):
183184
184185 # Create test file
185186 json_file = tmp_path / "code_test.json"
186- with open (json_file , "w" ) as f :
187+ with open (json_file , "w" , encoding = "utf-8" ) as f :
187188 json .dump ([sample_conversation_with_code ], f )
188189
189190 await import_chatgpt .process_chatgpt_json (json_file , tmp_path , processor )
190191
191192 # Check content
192193 conv_path = tmp_path / "20250111-code-test.md"
193- content = conv_path .read_text ()
194+ content = conv_path .read_text (encoding = "utf-8" )
194195 assert "```python" in content
195196 assert "def hello():" in content
196197 assert "```" in content
@@ -204,7 +205,7 @@ async def test_hidden_messages(tmp_path, sample_conversation_with_hidden):
204205
205206 # Create test file
206207 json_file = tmp_path / "hidden_test.json"
207- with open (json_file , "w" ) as f :
208+ with open (json_file , "w" , encoding = "utf-8" ) as f :
208209 json .dump ([sample_conversation_with_hidden ], f )
209210
210211 results = await import_chatgpt .process_chatgpt_json (json_file , tmp_path , processor )
@@ -214,7 +215,7 @@ async def test_hidden_messages(tmp_path, sample_conversation_with_hidden):
214215
215216 # Check content
216217 conv_path = tmp_path / "20250111-hidden-test.md"
217- content = conv_path .read_text ()
218+ content = conv_path .read_text (encoding = "utf-8" )
218219 assert "Visible message" in content
219220 assert "Hidden message" not in content
220221
0 commit comments