1
1
import pathlib
2
2
import shutil
3
+ import textwrap
3
4
4
5
import pytest
5
6
7
+ import _pytest .pytester
8
+
6
9
from libvcs .pytest_plugin import CreateProjectCallbackFixtureProtocol
7
10
8
11
@@ -28,3 +31,79 @@ def test_create_svn_remote_repo(
28
31
svn_remote_2 = create_svn_remote_repo ()
29
32
30
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