Skip to content

Commit 7bb3a66

Browse files
committed
tests(cli): Replace MagicMock with Config so that debug won't be truthy
1 parent f491c0b commit 7bb3a66

File tree

1 file changed

+30
-38
lines changed

1 file changed

+30
-38
lines changed

tests/test_main.py

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
@pytest.mark.asyncio
1111
async def test_async_main_no_stderr(monkeypatch):
12-
mock_cli_args = MagicMock(
13-
no_stderr=True, project_root=".", action=CliAction.version
14-
)
12+
mock_cli_args = Config(no_stderr=True, project_root=".", action=CliAction.version)
1513
monkeypatch.setattr(
1614
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
1715
)
@@ -24,9 +22,7 @@ async def test_async_main_no_stderr(monkeypatch):
2422

2523
@pytest.mark.asyncio
2624
async def test_async_main_default_project_root(monkeypatch):
27-
mock_cli_args = MagicMock(
28-
no_stderr=False, project_root=None, action=CliAction.version
29-
)
25+
mock_cli_args = Config(no_stderr=False, project_root=None, action=CliAction.version)
3026
monkeypatch.setattr(
3127
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
3228
)
@@ -42,9 +38,7 @@ async def test_async_main_default_project_root(monkeypatch):
4238

4339
@pytest.mark.asyncio
4440
async def test_async_main_ioerror(monkeypatch):
45-
mock_cli_args = MagicMock(
46-
no_stderr=False, project_root=".", action=CliAction.version
47-
)
41+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.version)
4842
monkeypatch.setattr(
4943
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
5044
)
@@ -61,7 +55,7 @@ async def test_async_main_ioerror(monkeypatch):
6155

6256
@pytest.mark.asyncio
6357
async def test_async_main_cli_action_check(monkeypatch):
64-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.check)
58+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.check)
6559
monkeypatch.setattr(
6660
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
6761
)
@@ -79,7 +73,7 @@ async def test_async_main_cli_action_check(monkeypatch):
7973

8074
@pytest.mark.asyncio
8175
async def test_async_main_cli_action_init(monkeypatch):
82-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.init)
76+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.init)
8377
monkeypatch.setattr(
8478
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
8579
)
@@ -94,15 +88,15 @@ async def test_async_main_cli_action_init(monkeypatch):
9488

9589
@pytest.mark.asyncio
9690
async def test_async_main_cli_action_chunks(monkeypatch):
97-
mock_cli_args = MagicMock(
98-
no_stderr=False, project_root=".", action=CliAction.chunks
99-
)
91+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.chunks)
10092
monkeypatch.setattr(
10193
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
10294
)
10395
mock_chunks = AsyncMock(return_value=0)
10496
monkeypatch.setattr("vectorcode.subcommands.chunks", mock_chunks)
105-
monkeypatch.setattr("vectorcode.main.get_project_config", AsyncMock())
97+
monkeypatch.setattr(
98+
"vectorcode.main.get_project_config", AsyncMock(return_value=Config())
99+
)
106100
monkeypatch.setattr("vectorcode.common.try_server", AsyncMock(return_value=True))
107101

108102
return_code = await async_main()
@@ -112,9 +106,7 @@ async def test_async_main_cli_action_chunks(monkeypatch):
112106

113107
@pytest.mark.asyncio
114108
async def test_async_main_cli_action_version(monkeypatch, capsys):
115-
mock_cli_args = MagicMock(
116-
no_stderr=False, project_root=".", action=CliAction.version
117-
)
109+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.version)
118110
monkeypatch.setattr(
119111
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
120112
)
@@ -127,13 +119,15 @@ async def test_async_main_cli_action_version(monkeypatch, capsys):
127119

128120
@pytest.mark.asyncio
129121
async def test_async_main_cli_action_prompts(monkeypatch):
130-
mock_cli_args = MagicMock(project_root=".", action=CliAction.prompts)
122+
mock_cli_args = Config(project_root=".", action=CliAction.prompts)
131123
monkeypatch.setattr(
132124
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
133125
)
134126
mock_prompts = MagicMock(return_value=0)
135127
monkeypatch.setattr("vectorcode.subcommands.prompts", mock_prompts)
136-
monkeypatch.setattr("vectorcode.main.get_project_config", AsyncMock())
128+
monkeypatch.setattr(
129+
"vectorcode.main.get_project_config", AsyncMock(return_value=Config())
130+
)
137131

138132
return_code = await async_main()
139133
assert return_code == 0
@@ -142,12 +136,12 @@ async def test_async_main_cli_action_prompts(monkeypatch):
142136

143137
@pytest.mark.asyncio
144138
async def test_async_main_cli_action_query(monkeypatch):
145-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.query)
139+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.query)
146140
monkeypatch.setattr(
147141
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
148142
)
149-
mock_final_configs = MagicMock(
150-
host="test_host", port=1234, action=CliAction.query, pipe=False
143+
mock_final_configs = Config(
144+
db_url="http://test_host:1234", action=CliAction.query, pipe=False
151145
)
152146
monkeypatch.setattr(
153147
"vectorcode.main.get_project_config",
@@ -168,7 +162,7 @@ async def test_async_main_cli_action_query(monkeypatch):
168162

169163
@pytest.mark.asyncio
170164
async def test_async_main_cli_action_vectorise(monkeypatch):
171-
mock_cli_args = MagicMock(
165+
mock_cli_args = Config(
172166
no_stderr=False,
173167
project_root=".",
174168
action=CliAction.vectorise,
@@ -177,8 +171,8 @@ async def test_async_main_cli_action_vectorise(monkeypatch):
177171
monkeypatch.setattr(
178172
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
179173
)
180-
mock_final_configs = MagicMock(
181-
host="test_host", port=1234, action=CliAction.vectorise, include_hidden=True
174+
mock_final_configs = Config(
175+
db_url="http://test_host:1234", action=CliAction.vectorise, include_hidden=True
182176
)
183177
monkeypatch.setattr(
184178
"vectorcode.main.get_project_config",
@@ -199,11 +193,11 @@ async def test_async_main_cli_action_vectorise(monkeypatch):
199193

200194
@pytest.mark.asyncio
201195
async def test_async_main_cli_action_drop(monkeypatch):
202-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.drop)
196+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.drop)
203197
monkeypatch.setattr(
204198
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
205199
)
206-
mock_final_configs = MagicMock(host="test_host", port=1234, action=CliAction.drop)
200+
mock_final_configs = Config(db_url="http://test_host:1234", action=CliAction.drop)
207201
monkeypatch.setattr(
208202
"vectorcode.main.get_project_config",
209203
AsyncMock(
@@ -223,11 +217,11 @@ async def test_async_main_cli_action_drop(monkeypatch):
223217

224218
@pytest.mark.asyncio
225219
async def test_async_main_cli_action_ls(monkeypatch):
226-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.ls)
220+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.ls)
227221
monkeypatch.setattr(
228222
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
229223
)
230-
mock_final_configs = MagicMock(host="test_host", port=1234, action=CliAction.ls)
224+
mock_final_configs = Config(db_url="http://test_host:1234", action=CliAction.ls)
231225
monkeypatch.setattr(
232226
"vectorcode.main.get_project_config",
233227
AsyncMock(
@@ -259,13 +253,11 @@ async def test_async_main_cli_action_files(monkeypatch):
259253

260254
@pytest.mark.asyncio
261255
async def test_async_main_cli_action_update(monkeypatch):
262-
mock_cli_args = MagicMock(
263-
no_stderr=False, project_root=".", action=CliAction.update
264-
)
256+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.update)
265257
monkeypatch.setattr(
266258
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
267259
)
268-
mock_final_configs = MagicMock(host="test_host", port=1234, action=CliAction.update)
260+
mock_final_configs = Config(db_url="http://test_host:1234", action=CliAction.update)
269261
monkeypatch.setattr(
270262
"vectorcode.main.get_project_config",
271263
AsyncMock(
@@ -285,11 +277,11 @@ async def test_async_main_cli_action_update(monkeypatch):
285277

286278
@pytest.mark.asyncio
287279
async def test_async_main_cli_action_clean(monkeypatch):
288-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.clean)
280+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.clean)
289281
monkeypatch.setattr(
290282
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
291283
)
292-
mock_final_configs = MagicMock(host="test_host", port=1234, action=CliAction.clean)
284+
mock_final_configs = Config(db_url="http://test_host:1234", action=CliAction.clean)
293285
monkeypatch.setattr(
294286
"vectorcode.main.get_project_config",
295287
AsyncMock(
@@ -309,11 +301,11 @@ async def test_async_main_cli_action_clean(monkeypatch):
309301

310302
@pytest.mark.asyncio
311303
async def test_async_main_exception_handling(monkeypatch):
312-
mock_cli_args = MagicMock(no_stderr=False, project_root=".", action=CliAction.query)
304+
mock_cli_args = Config(no_stderr=False, project_root=".", action=CliAction.query)
313305
monkeypatch.setattr(
314306
"vectorcode.main.parse_cli_args", AsyncMock(return_value=mock_cli_args)
315307
)
316-
mock_final_configs = MagicMock(host="test_host", port=1234, action=CliAction.query)
308+
mock_final_configs = Config(db_url="http://test_host:1234", action=CliAction.query)
317309
monkeypatch.setattr(
318310
"vectorcode.main.get_project_config",
319311
AsyncMock(

0 commit comments

Comments
 (0)