Skip to content

Commit cecf4df

Browse files
committed
path expansion and test covergae
1 parent 5e8db37 commit cecf4df

2 files changed

Lines changed: 32 additions & 21 deletions

File tree

src/vectorcode/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ async def wait_for_server(host, port, timeout=10):
6969
async def start_server(configs: Config):
7070
assert configs.db_path is not None
7171
db_path = os.path.expanduser(configs.db_path)
72+
configs.db_log_path = os.path.expanduser(configs.db_log_path)
73+
if not os.path.isdir(configs.db_log_path):
74+
os.makedirs(configs.db_log_path)
7275
if not os.path.isdir(db_path):
7376
print(
7477
f"Using local database at {os.path.expanduser('~/.local/share/vectorcode/chromadb/')}.",

tests/test_common.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -346,25 +346,34 @@ async def test_get_collection_hnsw():
346346

347347
@pytest.mark.asyncio
348348
async def test_start_server():
349-
# Mock subprocess.Popen
350-
with (
351-
patch("asyncio.create_subprocess_exec") as MockCreateProcess,
352-
patch("asyncio.sleep"),
353-
patch("socket.socket") as MockSocket,
354-
patch("vectorcode.common.wait_for_server") as MockWaitForServer,
355-
):
356-
# Mock socket to return a specific port
357-
mock_socket = MagicMock()
358-
mock_socket.getsockname.return_value = ("localhost", 12345) # Mock port
359-
MockSocket.return_value.__enter__.return_value = mock_socket
360-
361-
# Mock the process object
362-
mock_process = MagicMock()
363-
mock_process.returncode = 0 # Simulate successful execution
364-
MockCreateProcess.return_value = mock_process
365-
366-
# Create a config object
367-
with tempfile.TemporaryDirectory() as temp_dir:
349+
with tempfile.TemporaryDirectory() as temp_dir:
350+
351+
def _new_isdir(path):
352+
if str(temp_dir) in str(path):
353+
return True
354+
return False
355+
356+
# Mock subprocess.Popen
357+
with (
358+
patch("asyncio.create_subprocess_exec") as MockCreateProcess,
359+
patch("asyncio.sleep"),
360+
patch("socket.socket") as MockSocket,
361+
patch("vectorcode.common.wait_for_server") as MockWaitForServer,
362+
patch("os.path.isdir") as mock_isdir,
363+
patch("os.makedirs") as mock_makedirs,
364+
):
365+
mock_isdir.side_effect = _new_isdir
366+
# Mock socket to return a specific port
367+
mock_socket = MagicMock()
368+
mock_socket.getsockname.return_value = ("localhost", 12345) # Mock port
369+
MockSocket.return_value.__enter__.return_value = mock_socket
370+
371+
# Mock the process object
372+
mock_process = MagicMock()
373+
mock_process.returncode = 0 # Simulate successful execution
374+
MockCreateProcess.return_value = mock_process
375+
376+
# Create a config object
368377
config = Config(
369378
host="localhost",
370379
port=8000,
@@ -398,11 +407,10 @@ async def test_start_server():
398407
assert kwargs["stderr"] == sys.stderr
399408
assert "ANONYMIZED_TELEMETRY" in kwargs["env"]
400409

401-
# Assert that wait_for_server was called with the correct arguments
402410
MockWaitForServer.assert_called_once_with("localhost", 12345)
403411

404-
# Assert that the function returns the process
405412
assert process == mock_process
413+
mock_makedirs.assert_called_once_with(config.db_log_path)
406414

407415

408416
@pytest.mark.asyncio

0 commit comments

Comments
 (0)