@@ -124,75 +124,6 @@ def git_repo(temp_dir):
124
124
return git_dir
125
125
126
126
127
- @pytest .fixture
128
- def git_repo_with_https_remote (temp_dir ):
129
- """Create a git repository with HTTPS remote for testing."""
130
- git_dir = temp_dir / "test_repo_https"
131
- git_dir .mkdir ()
132
-
133
- # Initialize git repo
134
- subprocess .run (["git" , "init" ], cwd = git_dir , check = True , capture_output = True )
135
- subprocess .run (
136
- [
"git" ,
"config" ,
"user.email" ,
"[email protected] " ],
cwd = git_dir ,
check = True
137
- )
138
- subprocess .run (["git" , "config" , "user.name" , "Test User" ], cwd = git_dir , check = True )
139
-
140
- # Create a test file and commit
141
- test_file = git_dir / "test_file.py"
142
- test_file .write_text ("# Test file\n print('hello')\n " )
143
- subprocess .run (["git" , "add" , "." ], cwd = git_dir , check = True )
144
- subprocess .run (["git" , "commit" , "-m" , "Initial commit" ], cwd = git_dir , check = True )
145
-
146
- # Add HTTPS remote
147
- subprocess .run (
148
- [
149
- "git" ,
150
- "remote" ,
151
- "add" ,
152
- "origin" ,
153
- "https://github.com/test-user/test-repo.git" ,
154
- ],
155
- cwd = git_dir ,
156
- check = True ,
157
- )
158
-
159
- return git_dir
160
-
161
-
162
- @pytest .fixture
163
- def git_repo_multiple_remotes (temp_dir ):
164
- """Create a git repository with multiple remotes for testing."""
165
- git_dir = temp_dir / "test_repo_multiple"
166
- git_dir .mkdir ()
167
-
168
- # Initialize git repo
169
- subprocess .run (["git" , "init" ], cwd = git_dir , check = True , capture_output = True )
170
- subprocess .run (
171
- [
"git" ,
"config" ,
"user.email" ,
"[email protected] " ],
cwd = git_dir ,
check = True
172
- )
173
- subprocess .run (["git" , "config" , "user.name" , "Test User" ], cwd = git_dir , check = True )
174
-
175
- # Create a test file and commit
176
- test_file = git_dir / "test_file.py"
177
- test_file .write_text ("# Test file\n print('hello')\n " )
178
- subprocess .run (["git" , "add" , "." ], cwd = git_dir , check = True )
179
- subprocess .run (["git" , "commit" , "-m" , "Initial commit" ], cwd = git_dir , check = True )
180
-
181
- # Add multiple remotes
182
- subprocess .run (
183
- [
"git" ,
"remote" ,
"add" ,
"upstream" ,
"[email protected] :upstream/test-repo.git" ],
184
- cwd = git_dir ,
185
- check = True ,
186
- )
187
- subprocess .run (
188
- [
"git" ,
"remote" ,
"add" ,
"origin" ,
"[email protected] :test-user/test-repo.git" ],
189
- cwd = git_dir ,
190
- check = True ,
191
- )
192
-
193
- return git_dir
194
-
195
-
196
127
@pytest .fixture
197
128
def sample_needlinks ():
198
129
"""Create sample NeedLink objects for testing."""
@@ -354,75 +285,6 @@ def test_group_by_need_empty_list():
354
285
assert len (result ) == 0
355
286
356
287
357
- # Test git-related functions
358
- def test_parse_git_output_ssh_format ():
359
- """Test parsing git remote output in SSH format."""
360
- git_line = "origin [email protected] :test-user/test-repo.git (fetch)"
361
- result = parse_remote_git_output (git_line )
362
- assert result == "test-user/test-repo"
363
-
364
-
365
- def test_parse_git_output_https_format ():
366
- """Test parsing git remote output in HTTPS format."""
367
- git_line = "origin https://github.com/test-user/test-repo.git (fetch)"
368
- result = parse_remote_git_output (git_line )
369
- assert result == "test-user/test-repo"
370
-
371
-
372
- def test_parse_git_output_ssh_format_without_git_suffix ():
373
- """Test parsing git remote output in SSH format without .git suffix."""
374
- git_line = "origin [email protected] :test-user/test-repo (fetch)"
375
- result = parse_remote_git_output (git_line )
376
- assert result == "test-user/test-repo"
377
-
378
-
379
- def test_parse_git_output_invalid_format ():
380
- """Test parsing invalid git remote output."""
381
- git_line = "invalid"
382
- result = parse_remote_git_output (git_line )
383
- assert result == ""
384
-
385
-
386
- def test_parse_git_output_empty_string ():
387
- """Test parsing empty git remote output."""
388
- git_line = ""
389
- result = parse_remote_git_output (git_line )
390
- assert result == ""
391
-
392
-
393
- def test_get_github_repo_info_ssh_remote (git_repo ):
394
- """Test getting GitHub repository information with SSH remote."""
395
- result = get_github_repo_info (git_repo )
396
- assert result == "test-user/test-repo"
397
-
398
-
399
- def test_get_github_repo_info_https_remote (git_repo_with_https_remote ):
400
- """Test getting GitHub repository information with HTTPS remote."""
401
- result = get_github_repo_info (git_repo_with_https_remote )
402
- assert result == "test-user/test-repo"
403
-
404
-
405
- def test_get_github_repo_info_multiple_remotes (git_repo_multiple_remotes ):
406
- """Test GitHub repo info retrieval with multiple remotes (origin preferred)."""
407
- result = get_github_repo_info (git_repo_multiple_remotes )
408
- assert result == "test-user/test-repo"
409
-
410
-
411
- def test_get_current_git_hash (git_repo ):
412
- """Test getting current git hash."""
413
- result = get_current_git_hash (git_repo )
414
-
415
- # Verify it's a valid git hash (40 hex characters)
416
- assert len (result ) == 40
417
- assert all (c in "0123456789abcdef" for c in result )
418
-
419
-
420
- def test_get_current_git_hash_invalid_repo (temp_dir ):
421
- """Test getting git hash from invalid repository."""
422
- with pytest .raises (subprocess .CalledProcessError ):
423
- get_current_git_hash (temp_dir )
424
-
425
-
426
288
def test_get_github_link_with_real_repo (git_repo ):
427
289
"""Test generating GitHub link with real repository."""
428
290
# Create a needlink
0 commit comments