Test basic functionality of the enhanced library.
()
| 9 | |
| 10 | |
| 11 | def test_basic_functionality(): |
| 12 | """Test basic functionality of the enhanced library.""" |
| 13 | print("🧪 Testing Enhanced Document Data Extractor Library") |
| 14 | print("=" * 50) |
| 15 | |
| 16 | extractor = DocumentExtractor() |
| 17 | |
| 18 | # Test 1: Text file conversion |
| 19 | print("\n1. Testing text file conversion...") |
| 20 | try: |
| 21 | with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f: |
| 22 | f.write("This is a test document.\n\nIt has multiple lines.\n\n# This is a heading\n\n- List item 1\n- List item 2") |
| 23 | temp_file = f.name |
| 24 | |
| 25 | result = extractor.extract(temp_file) |
| 26 | print(f"✅ Text conversion successful: {len(result.content)} characters") |
| 27 | print(f" Metadata: {result.metadata}") |
| 28 | |
| 29 | # Test different output formats |
| 30 | markdown = result.extract_markdown() |
| 31 | html = result.extract_html() |
| 32 | json_output = result.extract_data() |
| 33 | |
| 34 | print(f" Markdown length: {len(markdown)}") |
| 35 | print(f" HTML length: {len(html)}") |
| 36 | print(f" JSON keys: {list(json_output.keys())}") |
| 37 | |
| 38 | os.unlink(temp_file) |
| 39 | |
| 40 | except Exception as e: |
| 41 | print(f"❌ Text conversion failed: {e}") |
| 42 | |
| 43 | # Test 2: URL conversion |
| 44 | print("\n2. Testing URL conversion...") |
| 45 | try: |
| 46 | result = extractor.convert_url("https://httpbin.org/html") |
| 47 | print(f"✅ URL conversion successful: {len(result.content)} characters") |
| 48 | print(f" Status code: {result.metadata.get('status_code')}") |
| 49 | |
| 50 | except Exception as e: |
| 51 | print(f"❌ URL conversion failed: {e}") |
| 52 | |
| 53 | # Test 3: Plain text conversion |
| 54 | print("\n3. Testing plain text conversion...") |
| 55 | try: |
| 56 | text = "This is plain text for testing the extractor." |
| 57 | result = extractor.extract_text(text) |
| 58 | print(f"✅ Plain text conversion successful: {len(result.content)} characters") |
| 59 | |
| 60 | except Exception as e: |
| 61 | print(f"❌ Plain text conversion failed: {e}") |
| 62 | |
| 63 | # Test 4: Supported formats |
| 64 | print("\n4. Testing supported formats...") |
| 65 | try: |
| 66 | formats = extractor.get_supported_formats() |
| 67 | print(f"✅ Supported formats: {formats}") |
| 68 |
no test coverage detected