Files
skill-seekers-reference/tests/test_llms_txt_detector.py
yusyus 119e642ced fix: Add package installation check and fix test imports (Task 2.1)
Fixes test import errors in 7 test files that failed without package installed.

**Changes:**

1. **tests/conftest.py** - Added pytest_configure() hook
   - Checks if skill_seekers package is installed before running tests
   - Shows helpful error message guiding users to run `pip install -e .`
   - Prevents confusing ModuleNotFoundError during test runs

2. **tests/test_constants.py** - Fixed dynamic imports
   - Changed `from cli import` to `from skill_seekers.cli import` (6 locations)
   - Fixes imports in test methods that dynamically import modules
   - All 16 tests now pass 

3. **tests/test_llms_txt_detector.py** - Fixed patch decorators
   - Changed `patch('cli.llms_txt_detector.` to `patch('skill_seekers.cli.llms_txt_detector.` (4 locations)
   - All 4 tests now pass 

4. **docs/CLAUDE.md** - Added "Running Tests" section
   - Clear instructions on installing package before testing
   - Explanation of why installation is required
   - Common pytest commands and options
   - Test coverage statistics

**Testing:**
-  All 101 tests pass across the 7 affected files:
  - test_async_scraping.py (11 tests)
  - test_config_validation.py (26 tests)
  - test_constants.py (16 tests)
  - test_estimate_pages.py (8 tests)
  - test_integration.py (23 tests)
  - test_llms_txt_detector.py (4 tests)
  - test_llms_txt_downloader.py (13 tests)
-  conftest.py check works correctly
-  Helpful error shown when package not installed

**Impact:**
- Developers now get clear guidance when tests fail due to missing installation
- All test import issues resolved
- Better developer experience for contributors
2025-11-29 22:13:13 +03:00

78 lines
2.7 KiB
Python

import pytest
from unittest.mock import patch, Mock
from skill_seekers.cli.llms_txt_detector import LlmsTxtDetector
def test_detect_llms_txt_variants():
"""Test detection of llms.txt file variants"""
detector = LlmsTxtDetector("https://hono.dev/docs")
with patch('skill_seekers.cli.llms_txt_detector.requests.head') as mock_head:
mock_response = Mock()
mock_response.status_code = 200
mock_head.return_value = mock_response
variants = detector.detect()
assert variants is not None
assert variants['url'] == 'https://hono.dev/llms-full.txt'
assert variants['variant'] == 'full'
mock_head.assert_called()
def test_detect_no_llms_txt():
"""Test detection when no llms.txt file exists"""
detector = LlmsTxtDetector("https://example.com/docs")
with patch('skill_seekers.cli.llms_txt_detector.requests.head') as mock_head:
mock_response = Mock()
mock_response.status_code = 404
mock_head.return_value = mock_response
variants = detector.detect()
assert variants is None
assert mock_head.call_count == 3 # Should try all three variants
def test_url_parsing_with_complex_paths():
"""Test URL parsing handles non-standard paths correctly"""
detector = LlmsTxtDetector("https://example.com/docs/v2/guide")
with patch('skill_seekers.cli.llms_txt_detector.requests.head') as mock_head:
mock_response = Mock()
mock_response.status_code = 200
mock_head.return_value = mock_response
variants = detector.detect()
assert variants is not None
assert variants['url'] == 'https://example.com/llms-full.txt'
mock_head.assert_called_with(
'https://example.com/llms-full.txt',
timeout=5,
allow_redirects=True
)
def test_detect_all_variants():
"""Test detecting all llms.txt variants"""
detector = LlmsTxtDetector("https://hono.dev/docs")
with patch('skill_seekers.cli.llms_txt_detector.requests.head') as mock_head:
# Mock responses for different variants
def mock_response(url, **kwargs):
response = Mock()
# All 3 variants exist for Hono
if 'llms-full.txt' in url or 'llms.txt' in url or 'llms-small.txt' in url:
response.status_code = 200
else:
response.status_code = 404
return response
mock_head.side_effect = mock_response
variants = detector.detect_all()
assert len(variants) == 3
assert any(v['variant'] == 'full' for v in variants)
assert any(v['variant'] == 'standard' for v in variants)
assert any(v['variant'] == 'small' for v in variants)
assert all('url' in v for v in variants)