Skip to content

Commit 22f57bd

Browse files
Made test stubs for multimedia processor. Split up llm optimizer tests for LLM document. Created factory classes for unified test data.
1 parent e115c03 commit 22f57bd

File tree

65 files changed

+9074
-2281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+9074
-2281
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
"Jaccard",
1919
"kylerose",
2020
"LAION",
21+
"ndarray",
22+
"ndarrays",
2123
"psutil",
2224
"pydantic",
25+
"pytest",
2326
"sparql",
2427
"tesseract",
25-
"uvicorn"
28+
"uvicorn",
29+
"ytdlp"
2630
],
2731
"cSpell.ignoreWords": [
2832
"Chunker",

_example_test_format.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ from resource_monitor import (
1515
ResourceMonitor,
1616
)
1717

18-
from _test_utils import (
19-
_has_good_callable_metadata,
20-
_raise_on_fake_code,
21-
_raise_on_mocked_code,
18+
from tests._test_utils import (
19+
has_good_callable_metadata,
20+
raise_on_bad_callable_code_quality,
21+
get_ast_tree,
22+
BadDocumentationError,
23+
BadSignatureError
2224
)
2325

2426
# Check if the ResourceMonitor class has the required attributes
@@ -40,7 +42,7 @@ class TestErrorMonitorInitialization(unittest.TestCase):
4042
Ensure that the docstring of the ErrorMonitor class meets the standards set forth in `_example_docstring_format.md`.
4143
"""
4244
try:
43-
_has_good_callable_metadata(ResourceMonitor)
45+
has_good_callable_metadata(ResourceMonitor)
4446
except Exception as e:
4547
self.fail(f"Callable metadata in ResourceMonitor does not meet standards: {e}")
4648

@@ -101,7 +103,7 @@ class TestErrorMonitorInitialization:
101103
Ensure that the docstring of the ErrorMonitor class meets the standards set forth in `_example_docstring_format.md`.
102104
"""
103105
try:
104-
_has_good_callable_metadata(ResourceMonitor)
106+
has_good_callable_metadata(ResourceMonitor)
105107
except Exception as e:
106108
self.fail(f"Callable metadata in ResourceMonitor does not meet standards: {e}")
107109

@@ -117,12 +119,6 @@ class TestErrorMonitorInitialization:
117119
WHEN ErrorMonitor is initialized
118120
THEN expect:
119121
- Instance created successfully
120-
- _logger is set from resources['logger']
121-
- _suppress_errors is set from configs.processing.suppress_errors
122-
- _root_dir is set from configs.paths.ROOT_DIR
123-
- _error_counters initialized as empty dict
124-
- _error_types initialized as empty set
125-
- traceback and datetime attributes are set from resources
126122
"""
127123
raise NotImplementedError("test_init_with_valid_resources_and_configs test needs to be implemented")
128124

ipfs_datasets_py/mcp_server/tools/vector_tools/vector_store_management.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ async def search_vector_index(
467467
Returns:
468468
Dictionary with search results
469469
"""
470-
try:
470+
try: # TODO _search_qdrant_index and _search_elasticsearch_index are hallucinated. Make them or remove them.
471471
if backend == "faiss":
472472
return await _search_faiss_index(index_name, query, top_k, config)
473473
elif backend == "qdrant":
474-
return await _search_qdrant_index(index_name, query, top_k, filters, config)
474+
pass # return await _search_qdrant_index(index_name, query, top_k, filters, config)
475475
elif backend == "elasticsearch":
476-
return await _search_elasticsearch_index(index_name, query, top_k, filters, config)
476+
pass # return await _search_elasticsearch_index(index_name, query, top_k, filters, config)
477477
else:
478478
return {
479479
"status": "error",

ipfs_datasets_py/multimedia/media_processor.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,50 @@
44
This module provides a unified interface for processing multimedia content
55
using various backends like FFmpeg and yt-dlp.
66
"""
7-
8-
import asyncio
97
import logging
10-
from typing import Dict, List, Any, Optional, Union
8+
from typing import Dict, Any, Optional
119
from pathlib import Path
1210

1311
from .ytdlp_wrapper import YtDlpWrapper, YTDLP_AVAILABLE
1412
from .ffmpeg_wrapper import FFmpegWrapper, FFMPEG_AVAILABLE
1513

16-
logger = logging.getLogger(__name__)
14+
15+
16+
def make_media_processor(
17+
default_output_dir: Optional[str] = None,
18+
enable_logging: bool = True,
19+
logger: logging.Logger = logging.getLogger(__name__),
20+
ytdlp: Optional[YtDlpWrapper] = None,
21+
ffmpeg: Optional[FFmpegWrapper] = None
22+
) -> 'MediaProcessor':
23+
"""
24+
Factory function to create a MediaProcessor instance.
25+
26+
Args:
27+
default_output_dir (Optional[str], optional): Default directory path for output files.
28+
If not provided, defaults to the current working directory. The directory will
29+
be created if it doesn't exist. Defaults to None.
30+
enable_logging (bool, optional): Enable detailed logging for debugging and monitoring.
31+
When True, logs initialization status, operation progress, and error details.
32+
Defaults to True.
33+
34+
Returns:
35+
MediaProcessor: Configured MediaProcessor instance.
36+
"""
37+
input_dict = {
38+
"default_output_dir": default_output_dir,
39+
"enable_logging": enable_logging,
40+
"logger": logger,
41+
"ytdlp": ytdlp,
42+
"ffmpeg": ffmpeg
43+
}
44+
if input_dict["ytdlp"] is None and YTDLP_AVAILABLE:
45+
input_dict["ytdlp"] = YtDlpWrapper(default_output_dir, enable_logging)
46+
47+
if input_dict["ffmpeg"] is None and FFMPEG_AVAILABLE:
48+
input_dict["ffmpeg"] = FFmpegWrapper(default_output_dir, enable_logging)
49+
50+
return MediaProcessor(**input_dict)
1751

1852

1953
class MediaProcessor:
@@ -96,8 +130,12 @@ class MediaProcessor:
96130
"""
97131

98132
def __init__(self,
99-
default_output_dir: Optional[str] = None,
100-
enable_logging: bool = True) -> None:
133+
default_output_dir: Optional[str] = None,
134+
enable_logging: bool = True,
135+
logger: logging.Logger = logging.getLogger(__name__),
136+
ytdlp: Optional[YtDlpWrapper] = None,
137+
ffmpeg: Optional[FFmpegWrapper] = None
138+
) -> None:
101139
"""
102140
Initialize the MediaProcessor with specified configuration options.
103141
@@ -150,12 +188,12 @@ def __init__(self,
150188
The initialization process logs the availability status of backend libraries
151189
(yt-dlp and FFmpeg) when logging is enabled.
152190
"""
153-
self.default_output_dir = Path(default_output_dir) if default_output_dir else Path.cwd()
154-
self.enable_logging = enable_logging
155-
191+
self.default_output_dir: Path = Path(default_output_dir) if default_output_dir else Path.cwd()
192+
self.enable_logging: bool = enable_logging
193+
156194
# Initialize component wrappers
157-
self.ytdlp = YtDlpWrapper(default_output_dir, enable_logging) if YTDLP_AVAILABLE else None
158-
self.ffmpeg = FFmpegWrapper(default_output_dir, enable_logging) if FFMPEG_AVAILABLE else None
195+
self.ytdlp: Optional[YtDlpWrapper] = ytdlp
196+
self.ffmpeg: Optional[FFmpegWrapper] = ffmpeg
159197

160198
logger.info(f"MediaProcessor initialized - YT-DLP: {YTDLP_AVAILABLE}, FFmpeg: {FFMPEG_AVAILABLE}")
161199

@@ -273,7 +311,7 @@ async def download_and_convert(self,
273311
return download_result
274312

275313
except Exception as e:
276-
logger.error(f"Error in download_and_convert: {e}")
314+
self.logger.error(f"Error in download_and_convert: {e}")
277315
return {
278316
"status": "error",
279317
"error": str(e)

ipfs_datasets_py/pdf_processing/batch_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ async def process_batch(self,
607607
failed_jobs=0,
608608
pending_jobs=len(pdf_paths),
609609
processing_jobs=0,
610-
start_time=datetime.utcnow().isoformat()
610+
start_time=datetime.now().isoformat()
611611
)
612612
self.active_batches[batch_id] = batch_status
613613

0 commit comments

Comments
 (0)