Add test script for JSON extraction functionality
This commit introduces a new test script, `test_json_extraction.py`, which verifies the correctness of the JSON extraction logic. The script includes a function to extract the first valid JSON object from raw input and a series of test cases covering various scenarios, such as clean JSON, JSON with extra text, nested JSON, and escaped quotes. The tests ensure that the extraction function behaves as expected and handles edge cases appropriately.
This commit is contained in:
+26
-1
@@ -27,7 +27,32 @@ Base = declarative_base()
|
||||
|
||||
|
||||
def create_db_tables():
|
||||
Base.metadata.create_all(bind=engine)
|
||||
"""Create database tables safely with error handling"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
# Check if tables already exist to avoid unnecessary DDL operations
|
||||
from sqlalchemy import inspect
|
||||
inspector = inspect(engine)
|
||||
existing_tables = inspector.get_table_names()
|
||||
|
||||
if existing_tables:
|
||||
logger.info(f"Database tables already exist: {existing_tables}")
|
||||
return
|
||||
|
||||
# Create tables with timeout protection
|
||||
logger.info("Creating database tables...")
|
||||
Base.metadata.create_all(bind=engine, checkfirst=True)
|
||||
logger.info("Database tables created successfully")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.warning("Database creation interrupted by user")
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating database tables: {e}")
|
||||
# Don't crash the app - tables might already exist
|
||||
pass
|
||||
|
||||
|
||||
def clear_all_data():
|
||||
|
||||
Reference in New Issue
Block a user