Skip to content

Commit b07516f

Browse files
committed
Update URL tests to use enable/disable functions
1 parent ed87f7a commit b07516f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_url.py

+39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55
import pytest
66
from libvcs.url.git import GitURL
77

8+
from vcspull.url import disable_ssh_style_url_detection, enable_ssh_style_url_detection
9+
10+
11+
def test_ssh_style_url_detection_toggle() -> None:
12+
"""Test that SSH-style URL detection can be toggled on and off."""
13+
url = "[email protected]:org/repo.git"
14+
15+
# First, disable the detection
16+
disable_ssh_style_url_detection()
17+
18+
# Without the patch, SSH-style URLs should not be detected as explicit
19+
assert GitURL.is_valid(url) # Should be valid in non-explicit mode
20+
assert not GitURL.is_valid(
21+
url, is_explicit=True
22+
) # Should not be valid in explicit mode
23+
24+
# Now enable the detection
25+
enable_ssh_style_url_detection()
26+
27+
# With the patch, SSH-style URLs should be detected as explicit
28+
assert GitURL.is_valid(url) # Should still be valid in non-explicit mode
29+
assert GitURL.is_valid(
30+
url, is_explicit=True
31+
) # Should now be valid in explicit mode
32+
33+
# Verify the rule used
34+
git_url = GitURL(url)
35+
assert git_url.rule == "core-git-scp"
36+
37+
# Re-enable for other tests
38+
enable_ssh_style_url_detection()
39+
840

941
@pytest.mark.parametrize(
1042
"url",
@@ -17,7 +49,11 @@
1749
)
1850
def test_ssh_style_url_detection(url: str) -> None:
1951
"""Test that SSH-style URLs are correctly detected."""
52+
# Ensure detection is enabled
53+
enable_ssh_style_url_detection()
54+
2055
assert GitURL.is_valid(url)
56+
assert GitURL.is_valid(url, is_explicit=True) # Should be valid in explicit mode
2157
git_url = GitURL(url)
2258
assert git_url.rule == "core-git-scp"
2359

@@ -55,6 +91,9 @@ def test_ssh_style_url_parsing(
5591
url: str, expected_user: str, expected_hostname: str, expected_path: str
5692
) -> None:
5793
"""Test that SSH-style URLs are correctly parsed."""
94+
# Ensure detection is enabled
95+
enable_ssh_style_url_detection()
96+
5897
git_url = GitURL(url)
5998
assert git_url.user == expected_user
6099
assert git_url.hostname == expected_hostname

0 commit comments

Comments
 (0)