|
7 | 7 |
|
8 | 8 | from __future__ import annotations
|
9 | 9 |
|
10 |
| -import os |
11 | 10 | import pathlib
|
12 | 11 | import typing as t
|
13 | 12 |
|
14 | 13 | import hypothesis.strategies as st
|
15 |
| -import pytest |
16 |
| -from hypothesis import given, settings |
| 14 | +from hypothesis import given |
17 | 15 |
|
18 | 16 | from vcspull.config.models import Repository, Settings, VCSPullConfig
|
19 | 17 |
|
@@ -75,7 +73,9 @@ def valid_path_strategy(draw: t.Callable[[st.SearchStrategy[t.Any]], t.Any]) ->
|
75 | 73 |
|
76 | 74 |
|
77 | 75 | @st.composite
|
78 |
| -def repository_strategy(draw: t.Callable[[st.SearchStrategy[t.Any]], t.Any]) -> Repository: |
| 76 | +def repository_strategy( |
| 77 | + draw: t.Callable[[st.SearchStrategy[t.Any]], t.Any], |
| 78 | +) -> Repository: |
79 | 79 | """Generate valid Repository instances."""
|
80 | 80 | name = draw(st.one_of(st.none(), st.text(min_size=1, max_size=20)))
|
81 | 81 | url = draw(valid_url_strategy())
|
@@ -142,7 +142,7 @@ def settings_strategy(draw: t.Callable[[st.SearchStrategy[t.Any]], t.Any]) -> Se
|
142 | 142 |
|
143 | 143 | @st.composite
|
144 | 144 | def vcspull_config_strategy(
|
145 |
| - draw: t.Callable[[st.SearchStrategy[t.Any]], t.Any] |
| 145 | + draw: t.Callable[[st.SearchStrategy[t.Any]], t.Any], |
146 | 146 | ) -> VCSPullConfig:
|
147 | 147 | """Generate valid VCSPullConfig instances."""
|
148 | 148 | settings = draw(settings_strategy())
|
@@ -175,30 +175,31 @@ def test_repository_construction(self, repository: Repository) -> None:
|
175 | 175 | # Check computed fields
|
176 | 176 | if repository.name is None:
|
177 | 177 | # Name should be derived from URL if not explicitly set
|
178 |
| - assert repository.get_name() != "" |
| 178 | + repo_name = extract_name_from_url(repository.url) |
| 179 | + assert repo_name != "" |
179 | 180 |
|
180 | 181 | @given(url=valid_url_strategy())
|
181 | 182 | def test_repository_name_extraction(self, url: str) -> None:
|
182 | 183 | """Test Repository can extract names from URLs."""
|
183 |
| - repo = Repository(url=url, path="/tmp/repo") |
184 |
| - # Should be able to extract a name from any valid URL |
185 |
| - assert repo.get_name() != "" |
| 184 | + # No need to create a repo instance for this test |
| 185 | + repo_name = extract_name_from_url(url) |
| 186 | + assert repo_name != "" |
186 | 187 | # The name shouldn't contain protocol or domain parts
|
187 |
| - assert "://" not in repo.get_name() |
188 |
| - assert "github.com" not in repo.get_name() |
| 188 | + assert "://" not in repo_name |
| 189 | + assert "github.com" not in repo_name |
189 | 190 |
|
190 | 191 | @given(repository=repository_strategy())
|
191 | 192 | def test_repository_path_expansion(self, repository: Repository) -> None:
|
192 | 193 | """Test path expansion in Repository model."""
|
193 | 194 | # Get the expanded path
|
194 |
| - expanded_path = repository.get_path() |
| 195 | + expanded_path = pathlib.Path(repository.path) |
195 | 196 |
|
196 | 197 | # Check for tilde expansion
|
197 | 198 | assert "~" not in str(expanded_path)
|
198 | 199 |
|
199 | 200 | # If original path started with ~, expanded should be absolute
|
200 | 201 | if repository.path.startswith("~"):
|
201 |
| - assert os.path.isabs(expanded_path) |
| 202 | + assert expanded_path.is_absolute() |
202 | 203 |
|
203 | 204 |
|
204 | 205 | class TestSettingsModel:
|
@@ -244,3 +245,27 @@ def test_config_with_multiple_repositories(
|
244 | 245 | assert repo1 in config.repositories
|
245 | 246 | assert repo2 in config.repositories
|
246 | 247 | assert repo3 in config.repositories
|
| 248 | + |
| 249 | + |
| 250 | +def extract_name_from_url(url: str) -> str: |
| 251 | + """Extract repository name from URL. |
| 252 | +
|
| 253 | + Parameters |
| 254 | + ---------- |
| 255 | + url : str |
| 256 | + Repository URL |
| 257 | +
|
| 258 | + Returns |
| 259 | + ------- |
| 260 | + str |
| 261 | + Repository name |
| 262 | + """ |
| 263 | + # Extract the last part of the URL path |
| 264 | + parts = url.rstrip("/").split("/") |
| 265 | + name = parts[-1] |
| 266 | + |
| 267 | + # Remove .git suffix if present |
| 268 | + if name.endswith(".git"): |
| 269 | + name = name[:-4] |
| 270 | + |
| 271 | + return name |
0 commit comments