|
1 |
| -import pytest |
| 1 | +import pathlib |
2 | 2 |
|
| 3 | +import yaml |
3 | 4 | from click.testing import CliRunner
|
4 | 5 |
|
| 6 | +from libvcs.sync.git import GitSync |
5 | 7 | from vcspull.cli import cli
|
6 | 8 |
|
7 | 9 |
|
8 |
| -@pytest.mark.skip(reason="todo") |
9 |
| -def test_command_line(self): |
| 10 | +def test_sync_cli_non_existent(tmp_path: pathlib.Path) -> None: |
10 | 11 | runner = CliRunner()
|
11 |
| - result = runner.invoke(cli, ["sync", "hi"]) |
12 |
| - assert result.exit_code == 0 |
13 |
| - assert "Debug mode is on" in result.output |
14 |
| - assert "Syncing" in result.output |
| 12 | + with runner.isolated_filesystem(temp_dir=tmp_path): |
| 13 | + result = runner.invoke(cli, ["sync", "hi"]) |
| 14 | + assert result.exit_code == 0 |
| 15 | + assert "" in result.output |
| 16 | + |
| 17 | + |
| 18 | +def test_sync( |
| 19 | + home_path: pathlib.Path, |
| 20 | + config_path: pathlib.Path, |
| 21 | + tmp_path: pathlib.Path, |
| 22 | + git_repo: GitSync, |
| 23 | +) -> None: |
| 24 | + runner = CliRunner() |
| 25 | + with runner.isolated_filesystem(temp_dir=tmp_path): |
| 26 | + config = { |
| 27 | + "~/github_projects/": { |
| 28 | + "my_git_repo": { |
| 29 | + "url": f"git+file://{git_repo.dir}", |
| 30 | + "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, |
| 31 | + }, |
| 32 | + "broken_repo": { |
| 33 | + "url": f"git+file://{git_repo.dir}", |
| 34 | + "remotes": {"test_remote": "git+file://non-existent-remote"}, |
| 35 | + }, |
| 36 | + } |
| 37 | + } |
| 38 | + yaml_config = config_path / ".vcspull.yaml" |
| 39 | + yaml_config_data = yaml.dump(config, default_flow_style=False) |
| 40 | + yaml_config.write_text(yaml_config_data, encoding="utf-8") |
| 41 | + |
| 42 | + # CLI can sync |
| 43 | + result = runner.invoke(cli, ["sync", "my_git_repo"]) |
| 44 | + assert result.exit_code == 0 |
| 45 | + output = "".join(list(result.output)) |
| 46 | + assert "my_git_repo" in output |
0 commit comments