Address code review feedback - improve error handling and imports

Co-authored-by: ArtemFilin1990 <221041513+ArtemFilin1990@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andArtemFilin1990 committed 2025-12-28 18:38:51 +00:00
1 parent 1db78ee324
commit ab47ea4abf
5 files changed
+46 -14

No files matched your search

View File
Whitespace-only changes.
+17 -2
View File
@@ -208,9 +208,24 @@ def table_to_records(table: List[List[TableCell]]) -> List[Dict[str, str]]:
def fetch_html(url: str, timeout: int, max_retries: int = DEFAULT_MAX_RETRIES, retry_delay: float = DEFAULT_RETRY_DELAY) -> str:
"""Fetch HTML with retry logic for transient network errors."""
"""
Fetch HTML with retry logic for transient network errors.
Args:
url: URL to fetch
timeout: Request timeout in seconds
max_retries: Maximum number of retry attempts (default: 3)
retry_delay: Delay between retries in seconds (default: 2.0)
Returns:
str: HTML content decoded as UTF-8
Raises:
HTTPError: If HTTP request fails after all retries
URLError: If network connection fails after all retries
"""
request = Request(url, headers={"User-Agent": DEFAULT_USER_AGENT})
last_error = None
last_error = URLError("No retry attempts made")
for attempt in range(max_retries):
try:
+2 -1
View File
@@ -79,4 +79,5 @@ def main():
if __name__ == '__main__':
sys.exit(main())
exit_code = main()
sys.exit(exit_code if exit_code is not None else 1)
View File
Whitespace-only changes.
+27 -11
View File
@@ -6,24 +6,40 @@ Run tests with:
python -m pytest tests/test_aprom_scraper.py -v
Or with standard unittest:
python tests/test_aprom_scraper.py
python -m unittest tests.test_aprom_scraper
Or from tests directory:
cd tests && python test_aprom_scraper.py
"""
import sys
import unittest
from pathlib import Path
# Add sources directory to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent / "sources"))
# Only modify sys.path when running as standalone script (not imported as module)
if __name__ == "__main__" and __package__ is None:
sys.path.insert(0, str(Path(__file__).parent.parent / "sources"))
from aprom_table_scraper import (
TableCell,
extract_tables,
derive_headers,
table_to_records,
clean_text,
normalize_url,
)
try:
from aprom_table_scraper import (
TableCell,
extract_tables,
derive_headers,
table_to_records,
clean_text,
normalize_url,
)
except ImportError:
# Fallback for different execution contexts
sys.path.insert(0, str(Path(__file__).parent.parent / "sources"))
from aprom_table_scraper import (
TableCell,
extract_tables,
derive_headers,
table_to_records,
clean_text,
normalize_url,
)
class TestCleanText(unittest.TestCase):