Spaces:
Sleeping
Sleeping
File size: 4,075 Bytes
1ae86a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | #!/usr/bin/env python3
"""
Basic tests for AI Notes Summarizer modules
"""
import sys
import os
# Add the current directory to Python path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_imports():
"""Test if all modules can be imported"""
print("Testing module imports...")
try:
from modules.pdf_processor import PDFProcessor
print("β
PDF Processor imported successfully")
except ImportError as e:
print(f"β Failed to import PDF Processor: {e}")
return False
try:
from modules.text_summarizer import TextSummarizer
print("β
Text Summarizer imported successfully")
except ImportError as e:
print(f"β Failed to import Text Summarizer: {e}")
return False
try:
from modules.utils import setup_logging, validate_input
print("β
Utils imported successfully")
except ImportError as e:
print(f"β Failed to import Utils: {e}")
return False
return True
def test_pdf_processor():
"""Test PDF processor basic functionality"""
print("\nTesting PDF Processor...")
try:
from modules.pdf_processor import PDFProcessor
processor = PDFProcessor()
# Test text preprocessing
test_text = "This is a test\n\nwith multiple spaces\nand newlines."
cleaned = processor.preprocess_text(test_text)
print(f"β
Text preprocessing works: '{cleaned}'")
return True
except Exception as e:
print(f"β PDF Processor test failed: {e}")
return False
def test_text_summarizer():
"""Test text summarizer basic functionality"""
print("\nTesting Text Summarizer...")
try:
from modules.text_summarizer import TextSummarizer
summarizer = TextSummarizer()
# Test text chunking without model loading
test_text = "This is a test sentence. " * 100
chunks = summarizer.chunk_text(test_text)
print(f"β
Text chunking works: {len(chunks)} chunks created")
# Test bullet formatting
test_summary = "This is the first point. This is the second point. This is the third point."
bullets = summarizer.format_as_bullets(test_summary)
print(f"β
Bullet formatting works:\n{bullets}")
return True
except Exception as e:
print(f"β Text Summarizer test failed: {e}")
return False
def test_utils():
"""Test utility functions"""
print("\nTesting Utils...")
try:
from modules.utils import validate_input, clean_text, format_file_size
# Test input validation
valid = validate_input("This is a test text that is long enough to pass validation.")
print(f"β
Input validation works: {valid}")
# Test text cleaning
dirty_text = "This has multiple spaces and special@#$%characters!"
clean = clean_text(dirty_text)
print(f"β
Text cleaning works: '{clean}'")
# Test file size formatting
size_str = format_file_size(1024 * 1024)
print(f"β
File size formatting works: {size_str}")
return True
except Exception as e:
print(f"β Utils test failed: {e}")
return False
def main():
"""Run all tests"""
print("π§ͺ Running Basic Tests for AI Notes Summarizer\n")
tests = [
test_imports,
test_pdf_processor,
test_text_summarizer,
test_utils
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
print()
print(f"π Test Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! The application is ready to run.")
return True
else:
print("β οΈ Some tests failed. Please check the errors above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)
|