|
| 1 | +import pathlib |
| 2 | +import shutil |
| 3 | +import textwrap |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +import _pytest.pytester |
| 8 | + |
| 9 | +from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.skipif(not shutil.which("git"), reason="git is not available") |
| 13 | +def test_create_git_remote_repo( |
| 14 | + create_git_remote_repo: CreateProjectCallbackFixtureProtocol, |
| 15 | + tmp_path: pathlib.Path, |
| 16 | + projects_path: pathlib.Path, |
| 17 | +) -> None: |
| 18 | + git_remote_1 = create_git_remote_repo() |
| 19 | + git_remote_2 = create_git_remote_repo() |
| 20 | + |
| 21 | + assert git_remote_1 != git_remote_2 |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.skipif(not shutil.which("svn"), reason="svn is not available") |
| 25 | +def test_create_svn_remote_repo( |
| 26 | + create_svn_remote_repo: CreateProjectCallbackFixtureProtocol, |
| 27 | + tmp_path: pathlib.Path, |
| 28 | + projects_path: pathlib.Path, |
| 29 | +) -> None: |
| 30 | + svn_remote_1 = create_svn_remote_repo() |
| 31 | + svn_remote_2 = create_svn_remote_repo() |
| 32 | + |
| 33 | + assert svn_remote_1 != svn_remote_2 |
| 34 | + |
| 35 | + |
| 36 | +def test_plugin( |
| 37 | + pytester: _pytest.pytester.Pytester, |
| 38 | + monkeypatch: pytest.MonkeyPatch, |
| 39 | +) -> None: |
| 40 | + # Initialize variables |
| 41 | + pytester.plugins = ["pytest_plugin"] |
| 42 | + pytester.makefile( |
| 43 | + ".ini", |
| 44 | + pytest=textwrap.dedent( |
| 45 | + """ |
| 46 | +[pytest] |
| 47 | +addopts=-vv |
| 48 | + """.strip() |
| 49 | + ), |
| 50 | + ) |
| 51 | + pytester.makeconftest( |
| 52 | + textwrap.dedent( |
| 53 | + r""" |
| 54 | +import pathlib |
| 55 | +import pytest |
| 56 | +
|
| 57 | +@pytest.fixture(autouse=True) |
| 58 | +def setup( |
| 59 | + request: pytest.FixtureRequest, |
| 60 | + gitconfig: pathlib.Path, |
| 61 | + set_home: pathlib.Path, |
| 62 | +) -> None: |
| 63 | + pass |
| 64 | + """ |
| 65 | + ) |
| 66 | + ) |
| 67 | + tests_path = pytester.path / "tests" |
| 68 | + files = { |
| 69 | + "example.py": textwrap.dedent( |
| 70 | + """ |
| 71 | +import pathlib |
| 72 | +
|
| 73 | +from libvcs.sync.git import GitSync |
| 74 | +from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol |
| 75 | +
|
| 76 | +def test_repo_git_remote_checkout( |
| 77 | + create_git_remote_repo: CreateProjectCallbackFixtureProtocol, |
| 78 | + tmp_path: pathlib.Path, |
| 79 | + projects_path: pathlib.Path, |
| 80 | +) -> None: |
| 81 | + git_server = create_git_remote_repo() |
| 82 | + git_repo_checkout_dir = projects_path / "my_git_checkout" |
| 83 | + git_repo = GitSync(dir=str(git_repo_checkout_dir), url=f"file://{git_server!s}") |
| 84 | +
|
| 85 | + git_repo.obtain() |
| 86 | + git_repo.update_repo() |
| 87 | +
|
| 88 | + assert git_repo.get_revision() == "initial" |
| 89 | +
|
| 90 | + assert git_repo_checkout_dir.exists() |
| 91 | + assert pathlib.Path(git_repo_checkout_dir / ".git").exists() |
| 92 | + """ |
| 93 | + ) |
| 94 | + } |
| 95 | + first_test_key = list(files.keys())[0] |
| 96 | + first_test_filename = str(tests_path / first_test_key) |
| 97 | + |
| 98 | + # Setup: Files |
| 99 | + tests_path.mkdir() |
| 100 | + for file_name, text in files.items(): |
| 101 | + rst_file = tests_path / file_name |
| 102 | + rst_file.write_text( |
| 103 | + text, |
| 104 | + encoding="utf-8", |
| 105 | + ) |
| 106 | + |
| 107 | + # Test |
| 108 | + result = pytester.runpytest(str(first_test_filename)) |
| 109 | + result.assert_outcomes(passed=1) |
0 commit comments