-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_pytest_plugin.py
More file actions
131 lines (110 loc) · 3.34 KB
/
test_pytest_plugin.py
File metadata and controls
131 lines (110 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""Tests for libvcs pytest plugin."""
import pathlib
import shutil
import textwrap
import pytest
from libvcs._internal.run import run
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn, vcs_email
@pytest.mark.skipif(not shutil.which("git"), reason="git is not available")
def test_create_git_remote_repo(
create_git_remote_repo: CreateRepoPytestFixtureFn,
tmp_path: pathlib.Path,
projects_path: pathlib.Path,
) -> None:
"""Tests for create_git_remote_repo pytest fixture."""
git_remote_1 = create_git_remote_repo()
git_remote_2 = create_git_remote_repo()
assert git_remote_1 != git_remote_2
@pytest.mark.skipif(not shutil.which("svn"), reason="svn is not available")
def test_create_svn_remote_repo(
create_svn_remote_repo: CreateRepoPytestFixtureFn,
tmp_path: pathlib.Path,
projects_path: pathlib.Path,
) -> None:
"""Tests for create_svn_remote_repo pytest fixture."""
svn_remote_1 = create_svn_remote_repo()
svn_remote_2 = create_svn_remote_repo()
assert svn_remote_1 != svn_remote_2
def test_plugin(
pytester: pytest.Pytester,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Tests for libvcs pytest plugin at large."""
# Initialize variables
pytester.plugins = ["pytest_plugin"]
pytester.makefile(
".ini",
pytest=textwrap.dedent(
"""
[pytest]
addopts=-vv
""".strip(),
),
)
pytester.makeconftest(
textwrap.dedent(
r"""
import pathlib
import pytest
@pytest.fixture(autouse=True)
def setup(
request: pytest.FixtureRequest,
gitconfig: pathlib.Path,
set_home: pathlib.Path,
) -> None:
pass
""",
),
)
tests_path = pytester.path / "tests"
files = {
"example.py": textwrap.dedent(
"""
import pathlib
from libvcs.sync.git import GitSync
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
def test_repo_git_remote_checkout(
create_git_remote_repo: CreateRepoPytestFixtureFn,
tmp_path: pathlib.Path,
projects_path: pathlib.Path,
) -> None:
git_server = create_git_remote_repo()
git_repo_checkout_dir = projects_path / "my_git_checkout"
git_repo = GitSync(path=str(git_repo_checkout_dir), url=f"file://{git_server!s}")
git_repo.obtain()
git_repo.update_repo()
assert git_repo.get_revision() == "initial"
assert git_repo_checkout_dir.exists()
assert pathlib.Path(git_repo_checkout_dir / ".git").exists()
""",
),
}
first_test_key = next(iter(files.keys()))
first_test_filename = str(tests_path / first_test_key)
tests_path.mkdir()
for file_name, text in files.items():
test_file = tests_path / file_name
test_file.write_text(
text,
encoding="utf-8",
)
# Test
result = pytester.runpytest(str(first_test_filename))
result.assert_outcomes(passed=1)
def test_gitconfig(
gitconfig: pathlib.Path,
set_gitconfig: pathlib.Path,
) -> None:
"""Test gitconfig fixture."""
output = run(["git", "config", "--get", "user.email"])
used_config_file_output = run(
[
"git",
"config",
"--show-origin",
"--get",
"user.email",
],
)
assert str(gitconfig) in used_config_file_output
assert vcs_email in output, "Should use our fixture config and home directory"