Spaces:
Sleeping
Sleeping
Download tests/test_services.py from faseehsandhu/Digitalytics: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/spaces/faseehsandhu/Digitalytics/resolve/main/tests/test_services.py
- Command line
-
hf download hf://spaces/faseehsandhu/Digitalytics/tests/test_services.py
-
curl -L -o test_services.py https://huggingface.co/spaces/faseehsandhu/Digitalytics/resolve/main/tests/test_services.py
2.17 kB
| import pytest | |
| from src.services.data_dictionary_service import DataDictionaryService | |
| from src.services.file_parser_service import FileParserService | |
| # Sample test data | |
| sample_pdf_path = "data/user_uploads/sample_data_dictionary.pdf" | |
| sample_excel_path = "data/user_uploads/sample_data_dictionary.xlsx" | |
| def data_dictionary_service(): | |
| return DataDictionaryService() | |
| def test_load_default_dictionaries(data_dictionary_service): | |
| # Assuming there are default dictionaries in the data/default_dictionaries directory | |
| default_dictionaries = data_dictionary_service.load_default_dictionaries() | |
| assert isinstance(default_dictionaries, dict) | |
| assert len(default_dictionaries) > 0 # Ensure there are default dictionaries loaded | |
| def test_load_user_uploaded_dictionary(data_dictionary_service): | |
| # Test loading a user-uploaded PDF dictionary | |
| pdf_content = data_dictionary_service.load_user_uploaded_dictionary(sample_pdf_path) | |
| assert pdf_content is not None | |
| assert isinstance(pdf_content, str) # Ensure content is a string | |
| # Test loading a user-uploaded Excel dictionary | |
| excel_content = data_dictionary_service.load_user_uploaded_dictionary(sample_excel_path) | |
| assert excel_content is not None | |
| assert isinstance(excel_content, str) # Ensure content is a string | |
| def test_parse_file_service(): | |
| parser_service = FileParserService() | |
| # Test parsing a PDF file | |
| pdf_text = parser_service.extract_text_from_pdf(sample_pdf_path) | |
| assert pdf_text is not None | |
| assert isinstance(pdf_text, str) # Ensure text is extracted as a string | |
| # Test parsing an Excel file | |
| excel_text = parser_service.extract_data_from_excel(sample_excel_path) | |
| assert excel_text is not None | |
| assert isinstance(excel_text, str) # Ensure text is extracted as a string | |
| def test_invalid_file_upload(data_dictionary_service): | |
| # Test loading an invalid file type | |
| invalid_file_path = "data/user_uploads/invalid_file.txt" | |
| result = data_dictionary_service.load_user_uploaded_dictionary(invalid_file_path) | |
| assert result is None # Ensure that invalid file returns None or appropriate error handling |