Skip to content

Commit 7e6bcf8

Browse files
committed
Update URL tests to use enable/disable functions
1 parent 5611f27 commit 7e6bcf8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_url.py

+35
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@
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(url, is_explicit=True) # Should not be valid in explicit mode
21+
22+
# Now enable the detection
23+
enable_ssh_style_url_detection()
24+
25+
# With the patch, SSH-style URLs should be detected as explicit
26+
assert GitURL.is_valid(url) # Should still be valid in non-explicit mode
27+
assert GitURL.is_valid(url, is_explicit=True) # Should now be valid in explicit mode
28+
29+
# Verify the rule used
30+
git_url = GitURL(url)
31+
assert git_url.rule == "core-git-scp"
32+
33+
# Re-enable for other tests
34+
enable_ssh_style_url_detection()
35+
836

937
@pytest.mark.parametrize(
1038
"url",
@@ -17,7 +45,11 @@
1745
)
1846
def test_ssh_style_url_detection(url: str) -> None:
1947
"""Test that SSH-style URLs are correctly detected."""
48+
# Ensure detection is enabled
49+
enable_ssh_style_url_detection()
50+
2051
assert GitURL.is_valid(url)
52+
assert GitURL.is_valid(url, is_explicit=True) # Should be valid in explicit mode
2153
git_url = GitURL(url)
2254
assert git_url.rule == "core-git-scp"
2355

@@ -55,6 +87,9 @@ def test_ssh_style_url_parsing(
5587
url: str, expected_user: str, expected_hostname: str, expected_path: str
5688
) -> None:
5789
"""Test that SSH-style URLs are correctly parsed."""
90+
# Ensure detection is enabled
91+
enable_ssh_style_url_detection()
92+
5893
git_url = GitURL(url)
5994
assert git_url.user == expected_user
6095
assert git_url.hostname == expected_hostname

0 commit comments

Comments
 (0)