@@ -168,28 +168,65 @@ def check_test_functionality():
168168 else :
169169 print ("✅ SQLite repository works" )
170170
171- # Test JsonFile repository
171+ # Test JsonFile repository with existing file (the failing test case)
172172 result = run_command ("""python3 -c "
173173import sys, tempfile, os, json
174174sys.path.append('src')
175175from patterns.repository import JsonFileUserRepository
176176with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as f:
177- json.dump({'users': [], 'next_id': 1}, f)
177+ test_data = {
178+ 'users': [
179+ {
180+ 'id': 1,
181+ 'name': 'Alice',
182+ 'email': 'alice@example.com',
183+ 'created_at': '2023-01-01T12:00:00',
184+ }
185+ ],
186+ 'next_id': 2,
187+ }
188+ json.dump(test_data, f)
189+ temp_path = f.name
190+ try:
191+ repo = JsonFileUserRepository(temp_path)
192+ assert len(repo._users) == 1
193+ assert repo._next_id == 2
194+ assert repo._users[0].name == 'Alice'
195+ print('JsonFile repository existing file test works')
196+ finally:
197+ os.unlink(temp_path)
198+ " """ , check = False )
199+
200+ if result .returncode != 0 :
201+ print ("❌ JsonFile repository existing file test failed" )
202+ print (result .stderr )
203+ return False
204+ else :
205+ print ("✅ JsonFile repository existing file test works" )
206+
207+ # Test corrupted file handling
208+ result = run_command ("""python3 -c "
209+ import sys, tempfile, os
210+ sys.path.append('src')
211+ from patterns.repository import JsonFileUserRepository
212+ with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as f:
213+ f.write('invalid json content')
178214 temp_path = f.name
179215try:
180216 repo = JsonFileUserRepository(temp_path)
181217 assert len(repo._users) == 0
182- print('JsonFile repository works')
218+ assert repo._next_id == 1
219+ print('Corrupted file handling works')
183220finally:
184221 os.unlink(temp_path)
185222" """ , check = False )
186223
187224 if result .returncode != 0 :
188- print ("❌ JsonFile repository test failed" )
225+ print ("❌ Corrupted file handling test failed" )
189226 print (result .stderr )
190227 return False
191228 else :
192- print ("✅ JsonFile repository works" )
229+ print ("✅ Corrupted file handling works" )
193230
194231 return True
195232
0 commit comments