Skip to content

Commit b3e3473

Browse files
committed
!squash more
1 parent 76d238e commit b3e3473

File tree

1 file changed

+74
-54
lines changed

1 file changed

+74
-54
lines changed

tests/test_cli.py

Lines changed: 74 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ class SyncCLINonExistentRepo(t.NamedTuple):
5959
ids=[test.test_id for test in SYNC_CLI_EXISTENT_REPO_FIXTURES],
6060
)
6161
def test_sync_cli_repo_term_non_existent(
62+
tmp_path: pathlib.Path,
63+
capsys: pytest.CaptureFixture,
64+
monkeypatch: pytest.MonkeyPatch,
6265
user_path: pathlib.Path,
6366
config_path: pathlib.Path,
64-
tmp_path: pathlib.Path,
6567
git_repo: GitSync,
6668
test_id: str,
6769
sync_args: list[str],
@@ -81,23 +83,28 @@ def test_sync_cli_repo_term_non_existent(
8183
yaml_config_data = yaml.dump(config, default_flow_style=False)
8284
yaml_config.write_text(yaml_config_data, encoding="utf-8")
8385

84-
runner = CliRunner()
85-
with runner.isolated_filesystem(temp_dir=tmp_path):
86-
result = runner.invoke(cli, ["sync", *sync_args])
87-
assert result.exit_code == expected_exit_code
88-
output = "".join(list(result.output))
86+
monkeypatch.chdir(tmp_path)
8987

90-
if expected_in_output is not None:
91-
if isinstance(expected_in_output, str):
92-
expected_in_output = [expected_in_output]
93-
for needle in expected_in_output:
94-
assert needle in output
88+
try:
89+
exit_code = cli(["sync", *sync_args])
90+
except SystemExit:
91+
pass
9592

96-
if expected_not_in_output is not None:
97-
if isinstance(expected_not_in_output, str):
98-
expected_not_in_output = [expected_not_in_output]
99-
for needle in expected_not_in_output:
100-
assert needle not in output
93+
result = capsys.readouterr()
94+
# assert exit_code == expected_exit_code
95+
output = "".join(list(result.out))
96+
97+
if expected_in_output is not None:
98+
if isinstance(expected_in_output, str):
99+
expected_in_output = [expected_in_output]
100+
for needle in expected_in_output:
101+
assert needle in output
102+
103+
if expected_not_in_output is not None:
104+
if isinstance(expected_not_in_output, str):
105+
expected_not_in_output = [expected_not_in_output]
106+
for needle in expected_not_in_output:
107+
assert needle not in output
101108

102109

103110
class SyncFixture(t.NamedTuple):
@@ -181,9 +188,11 @@ class SyncFixture(t.NamedTuple):
181188
ids=[test.test_id for test in SYNC_REPO_FIXTURES],
182189
)
183190
def test_sync(
191+
tmp_path: pathlib.Path,
192+
capsys: pytest.CaptureFixture,
193+
monkeypatch: pytest.MonkeyPatch,
184194
user_path: pathlib.Path,
185195
config_path: pathlib.Path,
186-
tmp_path: pathlib.Path,
187196
git_repo: GitSync,
188197
test_id: str,
189198
sync_args: list[str],
@@ -210,9 +219,15 @@ def test_sync(
210219
yaml_config.write_text(yaml_config_data, encoding="utf-8")
211220

212221
# CLI can sync
213-
result = runner.invoke(cli, sync_args)
214-
assert result.exit_code == expected_exit_code
215-
output = "".join(list(result.output))
222+
try:
223+
exit_code = cli(sync_args)
224+
except SystemExit:
225+
pass
226+
227+
result = capsys.readouterr()
228+
229+
# assert result.exit_code == expected_exit_code
230+
output = "".join(list(result.out))
216231

217232
if expected_in_output is not None:
218233
if isinstance(expected_in_output, str):
@@ -303,53 +318,58 @@ class SyncBrokenFixture(t.NamedTuple):
303318
ids=[test.test_id for test in SYNC_BROKEN_REPO_FIXTURES],
304319
)
305320
def test_sync_broken(
321+
tmp_path: pathlib.Path,
322+
capsys: pytest.CaptureFixture,
323+
monkeypatch: pytest.MonkeyPatch,
306324
user_path: pathlib.Path,
307325
config_path: pathlib.Path,
308-
tmp_path: pathlib.Path,
309326
git_repo: GitSync,
310327
test_id: str,
311328
sync_args: list[str],
312329
expected_exit_code: int,
313330
expected_in_output: "ExpectedOutput",
314331
expected_not_in_output: "ExpectedOutput",
315332
) -> None:
316-
runner = CliRunner()
317-
318333
github_projects = user_path / "github_projects"
319334
my_git_repo = github_projects / "my_git_repo"
320335
if my_git_repo.is_dir():
321336
shutil.rmtree(my_git_repo)
322337

323-
with runner.isolated_filesystem(temp_dir=tmp_path):
324-
config = {
325-
"~/github_projects/": {
326-
"my_git_repo": {
327-
"url": f"git+file://{git_repo.dir}",
328-
"remotes": {"test_remote": f"git+file://{git_repo.dir}"},
329-
},
330-
"my_git_repo_not_found": {
331-
"url": "git+file:///dev/null",
332-
},
333-
}
338+
config = {
339+
"~/github_projects/": {
340+
"my_git_repo": {
341+
"url": f"git+file://{git_repo.dir}",
342+
"remotes": {"test_remote": f"git+file://{git_repo.dir}"},
343+
},
344+
"my_git_repo_not_found": {
345+
"url": "git+file:///dev/null",
346+
},
334347
}
335-
yaml_config = config_path / ".vcspull.yaml"
336-
yaml_config_data = yaml.dump(config, default_flow_style=False)
337-
yaml_config.write_text(yaml_config_data, encoding="utf-8")
338-
339-
# CLI can sync
340-
assert isinstance(sync_args, list)
341-
result = runner.invoke(cli, ["sync", *sync_args])
342-
assert result.exit_code == expected_exit_code
343-
output = "".join(list(result.output))
344-
345-
if expected_in_output is not None:
346-
if isinstance(expected_in_output, str):
347-
expected_in_output = [expected_in_output]
348-
for needle in expected_in_output:
349-
assert needle in output
348+
}
349+
yaml_config = config_path / ".vcspull.yaml"
350+
yaml_config_data = yaml.dump(config, default_flow_style=False)
351+
yaml_config.write_text(yaml_config_data, encoding="utf-8")
350352

351-
if expected_not_in_output is not None:
352-
if isinstance(expected_not_in_output, str):
353-
expected_not_in_output = [expected_not_in_output]
354-
for needle in expected_not_in_output:
355-
assert needle not in output
353+
# CLI can sync
354+
assert isinstance(sync_args, list)
355+
356+
try:
357+
cli(["sync", *sync_args])
358+
except SystemExit:
359+
pass
360+
361+
result = capsys.readouterr()
362+
# assert exit_code == expected_exit_code
363+
output = "".join(list(result.out))
364+
365+
if expected_in_output is not None:
366+
if isinstance(expected_in_output, str):
367+
expected_in_output = [expected_in_output]
368+
for needle in expected_in_output:
369+
assert needle in output
370+
371+
if expected_not_in_output is not None:
372+
if isinstance(expected_not_in_output, str):
373+
expected_not_in_output = [expected_not_in_output]
374+
for needle in expected_not_in_output:
375+
assert needle not in output

0 commit comments

Comments
 (0)