diff --git a/sources/__init__.py b/sources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sources/aprom_table_scraper.py b/sources/aprom_table_scraper.py index fa10798..5a95bac 100644 --- a/sources/aprom_table_scraper.py +++ b/sources/aprom_table_scraper.py @@ -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: diff --git a/sources/brands_json_to_csv.py b/sources/brands_json_to_csv.py index 2310b90..e1bd67e 100644 --- a/sources/brands_json_to_csv.py +++ b/sources/brands_json_to_csv.py @@ -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) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_aprom_scraper.py b/tests/test_aprom_scraper.py index 51b2ae1..a96adff 100644 --- a/tests/test_aprom_scraper.py +++ b/tests/test_aprom_scraper.py @@ -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):