Skip to content

Commit 363000e

Browse files
committed
test(svn,parse): Tests for Subversion URL Parsing
1 parent 2cf23b3 commit 363000e

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

tests/parse/test_svn.py

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
import typing
2+
3+
import pytest
4+
5+
from libvcs.parse.base import MatcherRegistry
6+
from libvcs.parse.svn import DEFAULT_MATCHERS, PIP_DEFAULT_MATCHERS, SvnURL
7+
from libvcs.projects.svn import SubversionProject
8+
9+
10+
class SvnURLFixture(typing.NamedTuple):
11+
url: str
12+
is_valid: bool
13+
svn_location: SvnURL
14+
15+
16+
# Valid schemes for svn(1).
17+
# See Table 1.1 Repository access URLs in SVN Book
18+
# https://svnbook.red-bean.com/nightly/en/svn.basic.in-action.html#svn.basic.in-action.wc.tbl-1
19+
TEST_FIXTURES: list[SvnURLFixture] = [
20+
SvnURLFixture(
21+
url="https://bitbucket.com/vcs-python/libvcs",
22+
is_valid=True,
23+
svn_location=SvnURL(
24+
url="https://bitbucket.com/vcs-python/libvcs",
25+
scheme="https",
26+
hostname="bitbucket.com",
27+
path="vcs-python/libvcs",
28+
),
29+
),
30+
SvnURLFixture(
31+
url="https://bitbucket.com/vcs-python/libvcs",
32+
is_valid=True,
33+
svn_location=SvnURL(
34+
url="https://bitbucket.com/vcs-python/libvcs",
35+
scheme="https",
36+
hostname="bitbucket.com",
37+
path="vcs-python/libvcs",
38+
),
39+
),
40+
SvnURLFixture(
41+
url="svn://svn@bitbucket.com/tony/AlgoXY",
42+
is_valid=True,
43+
svn_location=SvnURL(
44+
url="svn://svn@bitbucket.com/tony/AlgoXY",
45+
scheme="https",
46+
hostname="bitbucket.com",
47+
path="tony/AlgoXY",
48+
),
49+
),
50+
SvnURLFixture(
51+
url="svn+ssh://svn@bitbucket.com/tony/AlgoXY",
52+
is_valid=True,
53+
svn_location=SvnURL(
54+
url="svn+ssh://svn@bitbucket.com/tony/AlgoXY",
55+
scheme="https",
56+
hostname="bitbucket.com",
57+
path="tony/AlgoXY",
58+
),
59+
),
60+
]
61+
62+
63+
@pytest.mark.parametrize(
64+
"url,is_valid,svn_location",
65+
TEST_FIXTURES,
66+
)
67+
def test_svn_location(
68+
url: str,
69+
is_valid: bool,
70+
svn_location: SvnURL,
71+
svn_repo: SubversionProject,
72+
):
73+
url = url.format(local_repo=svn_repo.dir)
74+
svn_location.url = svn_location.url.format(local_repo=svn_repo.dir)
75+
76+
assert SvnURL.is_valid(url) == is_valid, f"{url} compatibility should be {is_valid}"
77+
assert SvnURL(url) == svn_location
78+
79+
80+
class SvnURLKwargs(typing.TypedDict):
81+
url: str
82+
83+
84+
class SvnURLKwargsFixture(typing.NamedTuple):
85+
url: str
86+
is_valid: bool
87+
svn_location_kwargs: SvnURLKwargs
88+
89+
90+
#
91+
#
92+
# Extensibility: pip(1)
93+
# w/ VCS prefixes, e.g. svn+https, svn+ssh, svn+file
94+
# https://pip.pypa.io/en/stable/topics/vcs-support/
95+
#
96+
#
97+
PIP_TEST_FIXTURES: list[SvnURLKwargsFixture] = [
98+
SvnURLKwargsFixture(
99+
url="svn+http://svn@bitbucket.com/tony/AlgoXY",
100+
is_valid=True,
101+
svn_location_kwargs=SvnURLKwargs(
102+
url="svn+http://svn@bitbucket.com/tony/AlgoXY"
103+
),
104+
),
105+
SvnURLKwargsFixture(
106+
url="svn+https://svn@bitbucket.com/tony/AlgoXY",
107+
is_valid=True,
108+
svn_location_kwargs=SvnURLKwargs(
109+
url="svn+https://svn@bitbucket.com/tony/AlgoXY"
110+
),
111+
),
112+
SvnURLKwargsFixture(
113+
url="svn+file://{local_repo}",
114+
is_valid=True,
115+
svn_location_kwargs=SvnURLKwargs(url="svn+file://{local_repo}"),
116+
),
117+
]
118+
119+
120+
@pytest.mark.parametrize(
121+
"url,is_valid,svn_location_kwargs",
122+
PIP_TEST_FIXTURES,
123+
)
124+
def test_svn_location_extension_pip(
125+
url: str,
126+
is_valid: bool,
127+
svn_location_kwargs: SvnURLKwargs,
128+
svn_repo: SubversionProject,
129+
):
130+
class SvnURLWithPip(SvnURL):
131+
matchers = MatcherRegistry = MatcherRegistry(
132+
_matchers={m.label: m for m in [*DEFAULT_MATCHERS, *PIP_DEFAULT_MATCHERS]}
133+
)
134+
135+
svn_location_kwargs["url"] = svn_location_kwargs["url"].format(
136+
local_repo=svn_repo.dir
137+
)
138+
url = url.format(local_repo=svn_repo.dir)
139+
svn_location = SvnURLWithPip(**svn_location_kwargs)
140+
svn_location.url = svn_location.url.format(local_repo=svn_repo.dir)
141+
142+
assert (
143+
SvnURL.is_valid(url) != is_valid
144+
), f"{url} compatibility should work with core, expects {not is_valid}"
145+
assert (
146+
SvnURLWithPip.is_valid(url) == is_valid
147+
), f"{url} compatibility should be {is_valid}"
148+
assert SvnURLWithPip(url) == svn_location
149+
150+
151+
class ToURLFixture(typing.NamedTuple):
152+
svn_location: SvnURL
153+
expected: str
154+
155+
156+
@pytest.mark.parametrize(
157+
"svn_location,expected",
158+
[
159+
ToURLFixture(
160+
expected="https://bitbucket.com/vcs-python/libvcs",
161+
svn_location=SvnURL(
162+
url="https://bitbucket.com/vcs-python/libvcs",
163+
scheme="https",
164+
hostname="bitbucket.com",
165+
path="vcs-python/libvcs",
166+
),
167+
),
168+
ToURLFixture(
169+
expected="https://bitbucket.com/vcs-python/libvcs",
170+
svn_location=SvnURL(
171+
url="https://bitbucket.com/vcs-python/libvcs",
172+
scheme="https",
173+
hostname="bitbucket.com",
174+
path="vcs-python/libvcs",
175+
),
176+
),
177+
#
178+
# SCP-style URLs:
179+
# e.g. 'ssh://svn@example.com/foo/bar'
180+
#
181+
ToURLFixture(
182+
expected="ssh://svn@bitbucket.com/liuxinyu95/AlgoXY",
183+
svn_location=SvnURL(
184+
url="ssh://svn@bitbucket.com/liuxinyu95/AlgoXY",
185+
user="svn",
186+
scheme="ssh",
187+
hostname="bitbucket.com",
188+
path="liuxinyu95/AlgoXY",
189+
),
190+
),
191+
ToURLFixture(
192+
expected="ssh://username@bitbucket.com/vcs-python/libvcs",
193+
svn_location=SvnURL(
194+
url="username@bitbucket.com/vcs-python/libvcs",
195+
user="username",
196+
scheme="ssh",
197+
hostname="bitbucket.com",
198+
path="vcs-python/libvcs",
199+
),
200+
),
201+
],
202+
)
203+
def test_svn_to_url(
204+
expected: str,
205+
svn_location: SvnURL,
206+
svn_repo: SubversionProject,
207+
):
208+
"""Test SvnURL.to_url()"""
209+
svn_location.url = svn_location.url.format(local_repo=svn_repo.dir)
210+
211+
assert svn_location.to_url() == expected

0 commit comments

Comments
 (0)