MCPcopy
hub / github.com/langroid/langroid / mock_db_session

Function mock_db_session

tests/main/sql_chat/test_sql_chat_agent.py:55–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53
54@pytest.fixture
55def mock_db_session() -> Session:
56 # Create an in-memory SQLite database
57 engine = create_engine("sqlite:///:memory:", echo=False)
58 Base.metadata.create_all(engine)
59
60 Session = sessionmaker(bind=engine)
61 session = Session()
62
63 # Insert data
64 sales_dept = Department(id=1, name="Sales")
65 marketing_dept = Department(id=2, name="Marketing")
66
67 alice = Employee(id=1, name="Alice", department=sales_dept)
68 bob = Employee(id=2, name="Bob", department=marketing_dept)
69
70 sale1 = Sale(id=1, amount=100, employee=alice)
71 sale2 = Sale(id=2, amount=500, employee=bob)
72
73 session.add(sales_dept)
74 session.add(marketing_dept)
75 session.add(alice)
76 session.add(bob)
77 session.add(sale1)
78 session.add(sale2)
79
80 session.commit()
81
82 yield session # this is where the fixture's value comes from
83
84 session.close()
85
86
87@pytest.fixture

Callers

nothing calls this directly

Calls 5

DepartmentClass · 0.70
EmployeeClass · 0.70
SaleClass · 0.70
addMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…