Skip to content

Commit 50e0bfd

Browse files
fix: Update test file imports to use proper package paths
Fixed import errors in test_pdf_scraper.py and test_github_scraper.py: - Replaced absolute imports with proper package imports - Changed 'from pdf_scraper import' to 'from skill_seekers.cli.pdf_scraper import' - Changed 'from github_scraper import' to 'from skill_seekers.cli.github_scraper import' - Updated all @patch() decorators to use full module paths - Removed sys.path manipulation workarounds This completes the fix for import issues discovered during Task 1.2 (Issue #193). Test Results: - test_pdf_scraper.py: 18/18 passed ✅ - test_github_scraper.py: 22/22 passed ✅
1 parent d7a4c51 commit 50e0bfd

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

tests/test_github_scraper.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
from unittest.mock import Mock, patch, MagicMock
2525
from datetime import datetime
2626

27-
# Add parent directory to path for imports
28-
sys.path.insert(0, str(Path(__file__).parent.parent / "cli"))
29-
3027
try:
3128
from github import Github, GithubException
3229
PYGITHUB_AVAILABLE = True
@@ -40,7 +37,7 @@ class TestGitHubScraperInitialization(unittest.TestCase):
4037
def setUp(self):
4138
if not PYGITHUB_AVAILABLE:
4239
self.skipTest("PyGithub not installed")
43-
from github_scraper import GitHubScraper
40+
from skill_seekers.cli.github_scraper import GitHubScraper
4441
self.GitHubScraper = GitHubScraper
4542

4643
# Create temporary directory for test output
@@ -74,7 +71,7 @@ def test_init_with_token_from_config(self):
7471
'github_token': 'test_token_123'
7572
}
7673

77-
with patch('github_scraper.Github') as mock_github:
74+
with patch('skill_seekers.cli.github_scraper.Github') as mock_github:
7875
scraper = self.GitHubScraper(config)
7976
mock_github.assert_called_once_with('test_token_123')
8077

@@ -87,7 +84,7 @@ def test_init_with_token_from_env(self):
8784
}
8885

8986
with patch.dict(os.environ, {'GITHUB_TOKEN': 'env_token_456'}):
90-
with patch('github_scraper.Github') as mock_github:
87+
with patch('skill_seekers.cli.github_scraper.Github') as mock_github:
9188
scraper = self.GitHubScraper(config)
9289
mock_github.assert_called_once_with('env_token_456')
9390

@@ -99,7 +96,7 @@ def test_init_without_token(self):
9996
'github_token': None
10097
}
10198

102-
with patch('github_scraper.Github') as mock_github:
99+
with patch('skill_seekers.cli.github_scraper.Github') as mock_github:
103100
with patch.dict(os.environ, {}, clear=True):
104101
scraper = self.GitHubScraper(config)
105102
# Should create unauthenticated client
@@ -125,7 +122,7 @@ class TestREADMEExtraction(unittest.TestCase):
125122
def setUp(self):
126123
if not PYGITHUB_AVAILABLE:
127124
self.skipTest("PyGithub not installed")
128-
from github_scraper import GitHubScraper
125+
from skill_seekers.cli.github_scraper import GitHubScraper
129126
self.GitHubScraper = GitHubScraper
130127

131128
def test_extract_readme_success(self):
@@ -139,7 +136,7 @@ def test_extract_readme_success(self):
139136
mock_content = Mock()
140137
mock_content.decoded_content = b'# React\n\nA JavaScript library'
141138

142-
with patch('github_scraper.Github'):
139+
with patch('skill_seekers.cli.github_scraper.Github'):
143140
scraper = self.GitHubScraper(config)
144141
scraper.repo = Mock()
145142
scraper.repo.get_contents.return_value = mock_content
@@ -157,7 +154,7 @@ def test_extract_readme_tries_multiple_locations(self):
157154
'github_token': None
158155
}
159156

160-
with patch('github_scraper.Github'):
157+
with patch('skill_seekers.cli.github_scraper.Github'):
161158
scraper = self.GitHubScraper(config)
162159
scraper.repo = Mock()
163160

@@ -184,7 +181,7 @@ def test_extract_readme_not_found(self):
184181
'github_token': None
185182
}
186183

187-
with patch('github_scraper.Github'):
184+
with patch('skill_seekers.cli.github_scraper.Github'):
188185
scraper = self.GitHubScraper(config)
189186
scraper.repo = Mock()
190187
scraper.repo.get_contents.side_effect = GithubException(404, 'Not found')
@@ -201,7 +198,7 @@ class TestLanguageDetection(unittest.TestCase):
201198
def setUp(self):
202199
if not PYGITHUB_AVAILABLE:
203200
self.skipTest("PyGithub not installed")
204-
from github_scraper import GitHubScraper
201+
from skill_seekers.cli.github_scraper import GitHubScraper
205202
self.GitHubScraper = GitHubScraper
206203

207204
def test_extract_languages_success(self):
@@ -212,7 +209,7 @@ def test_extract_languages_success(self):
212209
'github_token': None
213210
}
214211

215-
with patch('github_scraper.Github'):
212+
with patch('skill_seekers.cli.github_scraper.Github'):
216213
scraper = self.GitHubScraper(config)
217214
scraper.repo = Mock()
218215
scraper.repo.get_languages.return_value = {
@@ -243,7 +240,7 @@ def test_extract_languages_empty(self):
243240
'github_token': None
244241
}
245242

246-
with patch('github_scraper.Github'):
243+
with patch('skill_seekers.cli.github_scraper.Github'):
247244
scraper = self.GitHubScraper(config)
248245
scraper.repo = Mock()
249246
scraper.repo.get_languages.return_value = {}
@@ -260,7 +257,7 @@ class TestIssuesExtraction(unittest.TestCase):
260257
def setUp(self):
261258
if not PYGITHUB_AVAILABLE:
262259
self.skipTest("PyGithub not installed")
263-
from github_scraper import GitHubScraper
260+
from skill_seekers.cli.github_scraper import GitHubScraper
264261
self.GitHubScraper = GitHubScraper
265262

266263
def test_extract_issues_success(self):
@@ -310,7 +307,7 @@ def test_extract_issues_success(self):
310307
mock_issue2.body = 'Feature description'
311308
mock_issue2.pull_request = None
312309

313-
with patch('github_scraper.Github'):
310+
with patch('skill_seekers.cli.github_scraper.Github'):
314311
scraper = self.GitHubScraper(config)
315312
scraper.repo = Mock()
316313
scraper.repo.get_issues.return_value = [mock_issue1, mock_issue2]
@@ -361,7 +358,7 @@ def test_extract_issues_filters_pull_requests(self):
361358
mock_pr.title = 'Pull request'
362359
mock_pr.pull_request = Mock() # Has pull_request attribute
363360

364-
with patch('github_scraper.Github'):
361+
with patch('skill_seekers.cli.github_scraper.Github'):
365362
scraper = self.GitHubScraper(config)
366363
scraper.repo = Mock()
367364
scraper.repo.get_issues.return_value = [mock_issue, mock_pr]
@@ -399,7 +396,7 @@ def test_extract_issues_respects_max_limit(self):
399396
mock_issue.pull_request = None
400397
mock_issues.append(mock_issue)
401398

402-
with patch('github_scraper.Github'):
399+
with patch('skill_seekers.cli.github_scraper.Github'):
403400
scraper = self.GitHubScraper(config)
404401
scraper.repo = Mock()
405402
scraper.repo.get_issues.return_value = mock_issues
@@ -417,7 +414,7 @@ class TestChangelogExtraction(unittest.TestCase):
417414
def setUp(self):
418415
if not PYGITHUB_AVAILABLE:
419416
self.skipTest("PyGithub not installed")
420-
from github_scraper import GitHubScraper
417+
from skill_seekers.cli.github_scraper import GitHubScraper
421418
self.GitHubScraper = GitHubScraper
422419

423420
def test_extract_changelog_success(self):
@@ -431,7 +428,7 @@ def test_extract_changelog_success(self):
431428
mock_content = Mock()
432429
mock_content.decoded_content = b'# Changelog\n\n## v1.0.0\n- Initial release'
433430

434-
with patch('github_scraper.Github'):
431+
with patch('skill_seekers.cli.github_scraper.Github'):
435432
scraper = self.GitHubScraper(config)
436433
scraper.repo = Mock()
437434
scraper.repo.get_contents.return_value = mock_content
@@ -449,7 +446,7 @@ def test_extract_changelog_tries_multiple_locations(self):
449446
'github_token': None
450447
}
451448

452-
with patch('github_scraper.Github'):
449+
with patch('skill_seekers.cli.github_scraper.Github'):
453450
scraper = self.GitHubScraper(config)
454451
scraper.repo = Mock()
455452

@@ -479,7 +476,7 @@ def test_extract_changelog_not_found(self):
479476
'github_token': None
480477
}
481478

482-
with patch('github_scraper.Github'):
479+
with patch('skill_seekers.cli.github_scraper.Github'):
483480
scraper = self.GitHubScraper(config)
484481
scraper.repo = Mock()
485482
scraper.repo.get_contents.side_effect = GithubException(404, 'Not found')
@@ -496,7 +493,7 @@ class TestReleasesExtraction(unittest.TestCase):
496493
def setUp(self):
497494
if not PYGITHUB_AVAILABLE:
498495
self.skipTest("PyGithub not installed")
499-
from github_scraper import GitHubScraper
496+
from skill_seekers.cli.github_scraper import GitHubScraper
500497
self.GitHubScraper = GitHubScraper
501498

502499
def test_extract_releases_success(self):
@@ -532,7 +529,7 @@ def test_extract_releases_success(self):
532529
mock_release2.tarball_url = 'https://github.com/facebook/react/archive/v18.0.0-rc.0.tar.gz'
533530
mock_release2.zipball_url = 'https://github.com/facebook/react/archive/v18.0.0-rc.0.zip'
534531

535-
with patch('github_scraper.Github'):
532+
with patch('skill_seekers.cli.github_scraper.Github'):
536533
scraper = self.GitHubScraper(config)
537534
scraper.repo = Mock()
538535
scraper.repo.get_releases.return_value = [mock_release1, mock_release2]
@@ -562,7 +559,7 @@ def test_extract_releases_empty(self):
562559
'github_token': None
563560
}
564561

565-
with patch('github_scraper.Github'):
562+
with patch('skill_seekers.cli.github_scraper.Github'):
566563
scraper = self.GitHubScraper(config)
567564
scraper.repo = Mock()
568565
scraper.repo.get_releases.return_value = []
@@ -579,7 +576,7 @@ class TestGitHubToSkillConverter(unittest.TestCase):
579576
def setUp(self):
580577
if not PYGITHUB_AVAILABLE:
581578
self.skipTest("PyGithub not installed")
582-
from github_scraper import GitHubToSkillConverter
579+
from skill_seekers.cli.github_scraper import GitHubToSkillConverter
583580
self.GitHubToSkillConverter = GitHubToSkillConverter
584581

585582
# Create temporary directory for test output
@@ -646,7 +643,7 @@ def test_init_loads_data(self):
646643
}
647644

648645
# Override data file path
649-
with patch('github_scraper.GitHubToSkillConverter.__init__') as mock_init:
646+
with patch('skill_seekers.cli.github_scraper.GitHubToSkillConverter.__init__') as mock_init:
650647
mock_init.return_value = None
651648
converter = self.GitHubToSkillConverter(config)
652649
converter.data_file = str(self.data_file)
@@ -669,7 +666,7 @@ def test_build_skill_creates_directory_structure(self):
669666
}
670667

671668
# Patch the paths to use our temp directory
672-
with patch('github_scraper.GitHubToSkillConverter._load_data') as mock_load:
669+
with patch('skill_seekers.cli.github_scraper.GitHubToSkillConverter._load_data') as mock_load:
673670
mock_load.return_value = self.mock_data
674671
converter = self.GitHubToSkillConverter(config)
675672
converter.skill_dir = str(self.output_dir / 'test_skill')
@@ -689,7 +686,7 @@ class TestErrorHandling(unittest.TestCase):
689686
def setUp(self):
690687
if not PYGITHUB_AVAILABLE:
691688
self.skipTest("PyGithub not installed")
692-
from github_scraper import GitHubScraper
689+
from skill_seekers.cli.github_scraper import GitHubScraper
693690
self.GitHubScraper = GitHubScraper
694691

695692
def test_invalid_repo_name(self):
@@ -700,7 +697,7 @@ def test_invalid_repo_name(self):
700697
'github_token': None
701698
}
702699

703-
with patch('github_scraper.Github'):
700+
with patch('skill_seekers.cli.github_scraper.Github'):
704701
scraper = self.GitHubScraper(config)
705702
scraper.repo = None
706703
scraper.github.get_repo = Mock(side_effect=GithubException(404, 'Not found'))
@@ -720,7 +717,7 @@ def test_rate_limit_error(self):
720717
'max_issues': 10
721718
}
722719

723-
with patch('github_scraper.Github'):
720+
with patch('skill_seekers.cli.github_scraper.Github'):
724721
scraper = self.GitHubScraper(config)
725722
scraper.repo = Mock()
726723
scraper.repo.get_issues.side_effect = GithubException(403, 'Rate limit exceeded')

tests/test_pdf_scraper.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
from pathlib import Path
2020
from unittest.mock import Mock, patch, MagicMock
2121

22-
# Add parent directory to path for imports
23-
sys.path.insert(0, str(Path(__file__).parent.parent / "cli"))
24-
2522
try:
2623
import fitz # PyMuPDF
2724
PYMUPDF_AVAILABLE = True
@@ -35,7 +32,7 @@ class TestPDFToSkillConverter(unittest.TestCase):
3532
def setUp(self):
3633
if not PYMUPDF_AVAILABLE:
3734
self.skipTest("PyMuPDF not installed")
38-
from pdf_scraper import PDFToSkillConverter
35+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
3936
self.PDFToSkillConverter = PDFToSkillConverter
4037

4138
# Create temporary directory for test output
@@ -88,7 +85,7 @@ class TestCategorization(unittest.TestCase):
8885
def setUp(self):
8986
if not PYMUPDF_AVAILABLE:
9087
self.skipTest("PyMuPDF not installed")
91-
from pdf_scraper import PDFToSkillConverter
88+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
9289
self.PDFToSkillConverter = PDFToSkillConverter
9390
self.temp_dir = tempfile.mkdtemp()
9491

@@ -196,7 +193,7 @@ class TestSkillBuilding(unittest.TestCase):
196193
def setUp(self):
197194
if not PYMUPDF_AVAILABLE:
198195
self.skipTest("PyMuPDF not installed")
199-
from pdf_scraper import PDFToSkillConverter
196+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
200197
self.PDFToSkillConverter = PDFToSkillConverter
201198
self.temp_dir = tempfile.mkdtemp()
202199

@@ -308,7 +305,7 @@ class TestCodeBlockHandling(unittest.TestCase):
308305
def setUp(self):
309306
if not PYMUPDF_AVAILABLE:
310307
self.skipTest("PyMuPDF not installed")
311-
from pdf_scraper import PDFToSkillConverter
308+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
312309
self.PDFToSkillConverter = PDFToSkillConverter
313310
self.temp_dir = tempfile.mkdtemp()
314311

@@ -402,7 +399,7 @@ class TestImageHandling(unittest.TestCase):
402399
def setUp(self):
403400
if not PYMUPDF_AVAILABLE:
404401
self.skipTest("PyMuPDF not installed")
405-
from pdf_scraper import PDFToSkillConverter
402+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
406403
self.PDFToSkillConverter = PDFToSkillConverter
407404
self.temp_dir = tempfile.mkdtemp()
408405

@@ -501,7 +498,7 @@ class TestErrorHandling(unittest.TestCase):
501498
def setUp(self):
502499
if not PYMUPDF_AVAILABLE:
503500
self.skipTest("PyMuPDF not installed")
504-
from pdf_scraper import PDFToSkillConverter
501+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
505502
self.PDFToSkillConverter = PDFToSkillConverter
506503
self.temp_dir = tempfile.mkdtemp()
507504

@@ -541,7 +538,7 @@ class TestJSONWorkflow(unittest.TestCase):
541538
def setUp(self):
542539
if not PYMUPDF_AVAILABLE:
543540
self.skipTest("PyMuPDF not installed")
544-
from pdf_scraper import PDFToSkillConverter
541+
from skill_seekers.cli.pdf_scraper import PDFToSkillConverter
545542
self.PDFToSkillConverter = PDFToSkillConverter
546543
self.temp_dir = tempfile.mkdtemp()
547544

0 commit comments

Comments
 (0)