Jatin Mehra commited on
Commit
9dbace0
Β·
1 Parent(s): 3da73e5

Remove test_refactored.py as part of codebase cleanup and refactoring efforts

Browse files
Files changed (1) hide show
  1. test_refactored.py +0 -176
test_refactored.py DELETED
@@ -1,176 +0,0 @@
1
- """
2
- Test script to verify the refactored code works correctly.
3
-
4
- This script tests the main functionality to ensure backward compatibility
5
- and proper operation of the refactored modules.
6
- """
7
-
8
- import sys
9
- import os
10
- import tempfile
11
- import traceback
12
-
13
- # Add the current directory to Python path
14
- sys.path.insert(0, '/workspaces/PDF-Insight-Beta')
15
-
16
- def test_imports():
17
- """Test that all modules can be imported successfully."""
18
- print("Testing imports...")
19
-
20
- try:
21
- # Test config import
22
- from configs.config import Config, ModelConfig, ErrorMessages
23
- print("βœ“ Config module imported successfully")
24
-
25
- # Test models import
26
- from models.models import ChatRequest, UploadResponse
27
- print("βœ“ Models module imported successfully")
28
-
29
- # Test utils import
30
- from utils import estimate_tokens, process_pdf_file
31
- print("βœ“ Utils module imported successfully")
32
-
33
- # Test services import
34
- from services import create_llm_model, session_manager, rag_service
35
- print("βœ“ Services module imported successfully")
36
-
37
- # Test API import
38
- from api import upload_pdf_handler, chat_handler
39
- print("βœ“ API module imported successfully")
40
-
41
- # Test backward compatibility
42
- from preprocessing import model_selection, chunk_text, agentic_rag
43
- print("βœ“ Backward compatibility import successful")
44
-
45
- return True
46
-
47
- except Exception as e:
48
- print(f"βœ— Import failed: {e}")
49
- traceback.print_exc()
50
- return False
51
-
52
- def test_basic_functionality():
53
- """Test basic functionality of key components."""
54
- print("\nTesting basic functionality...")
55
-
56
- try:
57
- from configs.config import Config
58
- from utils.text_processing import estimate_tokens
59
- from services.llm_service import get_available_models
60
-
61
- # Test token estimation
62
- tokens = estimate_tokens("This is a test string")
63
- assert tokens > 0
64
- print(f"βœ“ Token estimation works: {tokens} tokens")
65
-
66
- # Test model listing
67
- models = get_available_models()
68
- assert len(models) > 0
69
- print(f"βœ“ Model listing works: {len(models)} models available")
70
-
71
- # Test config access
72
- assert Config.DEFAULT_CHUNK_SIZE > 0
73
- print(f"βœ“ Config access works: chunk size = {Config.DEFAULT_CHUNK_SIZE}")
74
-
75
- return True
76
-
77
- except Exception as e:
78
- print(f"βœ— Basic functionality test failed: {e}")
79
- traceback.print_exc()
80
- return False
81
-
82
- def test_backward_compatibility():
83
- """Test that original interfaces still work."""
84
- print("\nTesting backward compatibility...")
85
-
86
- try:
87
- # Test original preprocessing interface
88
- from preprocessing import model_selection, tools, estimate_tokens
89
-
90
- # These should work without errors
91
- assert callable(model_selection)
92
- assert isinstance(tools, list)
93
- assert callable(estimate_tokens)
94
-
95
- print("βœ“ Original preprocessing interface preserved")
96
-
97
- # Test that we can still access the original functions
98
- from preprocessing import (
99
- process_pdf_file, chunk_text, create_embeddings,
100
- build_faiss_index, retrieve_similar_chunks, agentic_rag
101
- )
102
-
103
- print("βœ“ All original functions accessible")
104
-
105
- return True
106
-
107
- except Exception as e:
108
- print(f"βœ— Backward compatibility test failed: {e}")
109
- traceback.print_exc()
110
- return False
111
-
112
- def test_app_creation():
113
- """Test that the FastAPI app can be created."""
114
- print("\nTesting app creation...")
115
-
116
- try:
117
- from app import create_app
118
-
119
- app = create_app()
120
- assert app is not None
121
- print("βœ“ FastAPI app created successfully")
122
-
123
- # Check that routes are properly defined
124
- routes = [route.path for route in app.routes]
125
- expected_routes = ["/", "/upload-pdf", "/chat", "/models"]
126
-
127
- for route in expected_routes:
128
- if route in routes:
129
- print(f"βœ“ Route {route} found")
130
- else:
131
- print(f"βœ— Route {route} missing")
132
- return False
133
-
134
- return True
135
-
136
- except Exception as e:
137
- print(f"βœ— App creation test failed: {e}")
138
- traceback.print_exc()
139
- return False
140
-
141
- def main():
142
- """Run all tests."""
143
- print("=" * 50)
144
- print("Testing Refactored PDF Insight Beta")
145
- print("=" * 50)
146
-
147
- tests = [
148
- test_imports,
149
- test_basic_functionality,
150
- test_backward_compatibility,
151
- test_app_creation
152
- ]
153
-
154
- results = []
155
- for test in tests:
156
- results.append(test())
157
-
158
- print("\n" + "=" * 50)
159
- print("Test Results:")
160
- print("=" * 50)
161
-
162
- passed = sum(results)
163
- total = len(results)
164
-
165
- print(f"Tests passed: {passed}/{total}")
166
-
167
- if passed == total:
168
- print("βœ“ All tests passed! Refactoring successful.")
169
- return 0
170
- else:
171
- print("βœ— Some tests failed. Please check the issues above.")
172
- return 1
173
-
174
- if __name__ == "__main__":
175
- exit_code = main()
176
- sys.exit(exit_code)