11import asyncio
22import hashlib
3- import json
43import os
54import socket
65import tempfile
1514from vectorcode .chunking import Chunk
1615from vectorcode .cli_utils import Config
1716from vectorcode .subcommands .vectorise import (
17+ VectoriseStats ,
1818 chunked_add ,
1919 exclude_paths_by_spec ,
2020 get_uuid ,
@@ -74,7 +74,7 @@ async def test_chunked_add():
7474 file_path = "test_file.py"
7575 collection = AsyncMock ()
7676 collection_lock = asyncio .Lock ()
77- stats = { "add" : 0 , "update" : 0 }
77+ stats = VectoriseStats ()
7878 stats_lock = asyncio .Lock ()
7979 configs = Config (chunk_size = 100 , overlap_ratio = 0.2 , project_root = "." )
8080 max_batch_size = 50
@@ -97,8 +97,8 @@ async def test_chunked_add():
9797 semaphore ,
9898 )
9999
100- assert stats [ " add" ] == 1
101- assert stats [ " update" ] == 0
100+ assert stats . add == 1
101+ assert stats . update == 0
102102 collection .add .assert_called ()
103103 assert collection .add .call_count == 1
104104
@@ -110,7 +110,7 @@ async def test_chunked_add_with_existing():
110110 collection .get = AsyncMock ()
111111 collection .get .return_value = {"ids" : ["id1" ], "metadatas" : [{"sha256" : "hash1" }]}
112112 collection_lock = asyncio .Lock ()
113- stats = { "add" : 0 , "update" : 0 }
113+ stats = VectoriseStats ()
114114 stats_lock = asyncio .Lock ()
115115 configs = Config (chunk_size = 100 , overlap_ratio = 0.2 , project_root = "." )
116116 max_batch_size = 50
@@ -133,8 +133,8 @@ async def test_chunked_add_with_existing():
133133 semaphore ,
134134 )
135135
136- assert stats [ " add" ] == 0
137- assert stats [ " update" ] == 0
136+ assert stats . add == 0
137+ assert stats . update == 0
138138 collection .add .assert_not_called ()
139139
140140
@@ -145,7 +145,7 @@ async def test_chunked_add_update_existing():
145145 collection .get = AsyncMock ()
146146 collection .get .return_value = {"ids" : ["id1" ], "metadatas" : [{"sha256" : "hash1" }]}
147147 collection_lock = asyncio .Lock ()
148- stats = { "add" : 0 , "update" : 0 }
148+ stats = VectoriseStats ()
149149 stats_lock = asyncio .Lock ()
150150 configs = Config (chunk_size = 100 , overlap_ratio = 0.2 , project_root = "." )
151151 max_batch_size = 50
@@ -168,8 +168,8 @@ async def test_chunked_add_update_existing():
168168 semaphore ,
169169 )
170170
171- assert stats [ " add" ] == 0
172- assert stats [ " update" ] == 1
171+ assert stats . add == 0
172+ assert stats . update == 1
173173 collection .add .assert_called ()
174174
175175
@@ -178,7 +178,7 @@ async def test_chunked_add_empty_file():
178178 file_path = "test_file.py"
179179 collection = AsyncMock ()
180180 collection_lock = asyncio .Lock ()
181- stats = {"add" : 0 , "update" : 0 }
181+ stats = VectoriseStats ( ** {"add" : 0 , "update" : 0 })
182182 stats_lock = asyncio .Lock ()
183183 configs = Config (chunk_size = 100 , overlap_ratio = 0.2 , project_root = "." )
184184 max_batch_size = 50
@@ -201,25 +201,25 @@ async def test_chunked_add_empty_file():
201201 semaphore ,
202202 )
203203
204- assert stats [ " add" ] == 0
205- assert stats [ " update" ] == 0
204+ assert stats . add == 0
205+ assert stats . update == 0
206206 assert collection .add .call_count == 0
207207
208208
209209@patch ("tabulate.tabulate" )
210210def test_show_stats_pipe_false (mock_tabulate , capsys ):
211211 configs = Config (pipe = False )
212- stats = {"add" : 1 , "update" : 2 , "removed" : 3 }
212+ stats = VectoriseStats ( ** {"add" : 1 , "update" : 2 , "removed" : 3 })
213213 show_stats (configs , stats )
214214 mock_tabulate .assert_called_once ()
215215
216216
217217def test_show_stats_pipe_true (capsys ):
218218 configs = Config (pipe = True )
219- stats = {"add" : 1 , "update" : 2 , "removed" : 3 }
219+ stats = VectoriseStats ( ** {"add" : 1 , "update" : 2 , "removed" : 3 })
220220 show_stats (configs , stats )
221221 captured = capsys .readouterr ()
222- assert captured .out == json . dumps (stats ) + " \n "
222+ assert captured .out . strip () == (stats . to_json ())
223223
224224
225225def test_exclude_paths_by_spec ():
0 commit comments