Skip to content

Commit ddedda2

Browse files
committed
Chatbot: Add software tests for workshop notebook
1 parent 45b6d08 commit ddedda2

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

.github/workflows/ml-chatbot.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Chatbot
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/ml-chatbot.yml'
7+
- 'topic/chatbot/**'
8+
- '/requirements.txt'
9+
push:
10+
branches: [ main ]
11+
paths:
12+
- '.github/workflows/ml-chatbot.yml'
13+
- 'topic/chatbot/**'
14+
- '/requirements.txt'
15+
16+
# Allow job to be triggered manually.
17+
workflow_dispatch:
18+
19+
# Run job each night after CrateDB nightly has been published.
20+
schedule:
21+
- cron: '0 3 * * *'
22+
23+
# Cancel in-progress jobs when pushing to the same branch.
24+
concurrency:
25+
cancel-in-progress: true
26+
group: ${{ github.workflow }}-${{ github.ref }}
27+
28+
jobs:
29+
test:
30+
name: "
31+
Python: ${{ matrix.python-version }}
32+
CrateDB: ${{ matrix.cratedb-version }}
33+
on ${{ matrix.os }}"
34+
runs-on: ${{ matrix.os }}
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
os: [ 'ubuntu-latest' ]
39+
python-version: [
40+
'3.10',
41+
'3.13',
42+
]
43+
cratedb-version: [ 'nightly' ]
44+
45+
services:
46+
cratedb:
47+
image: crate/crate:${{ matrix.cratedb-version }}
48+
ports:
49+
- 4200:4200
50+
- 5432:5432
51+
env:
52+
CRATE_HEAP_SIZE: 4g
53+
54+
env:
55+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
56+
57+
steps:
58+
59+
- name: Acquire sources
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
architecture: x64
67+
cache: 'pip'
68+
cache-dependency-path: |
69+
requirements.txt
70+
topic/chatbot/table-augmented-generation/app/requirements.txt
71+
topic/chatbot/table-augmented-generation/workshop/requirements-dev.txt
72+
73+
- name: Install utilities
74+
run: |
75+
pip install -r requirements.txt
76+
77+
- name: Validate topic/chatbot/table-augmented-generation/workshop
78+
run: |
79+
ngr test --accept-no-venv topic/chatbot/table-augmented-generation/workshop
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
from pathlib import Path
3+
4+
import pytest
5+
import sqlalchemy as sa
6+
from pueblo.testing.notebook import generate_tests
7+
8+
9+
def pytest_generate_tests(metafunc):
10+
"""
11+
Generate pytest test case per Jupyter Notebook.
12+
"""
13+
here = Path(__file__).parent
14+
generate_tests(metafunc, path=here)
15+
16+
17+
@pytest.fixture(autouse=True)
18+
def reset_database_tables():
19+
"""
20+
Before running a test case, reset relevant tables in database.
21+
"""
22+
23+
connection_string = os.environ.get("CRATEDB_CONNECTION_STRING")
24+
25+
engine = sa.create_engine(connection_string, echo=os.environ.get("DEBUG"))
26+
connection = engine.connect()
27+
28+
reset_tables = [
29+
"machine_manuals",
30+
"motor_readings",
31+
]
32+
33+
for table in reset_tables:
34+
connection.execute(sa.text(f"DROP TABLE IF EXISTS {table};"))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[tool.pytest.ini_options]
2+
minversion = "2.0"
3+
addopts = """
4+
-rfEX -p pytester --strict-markers --verbosity=3 --capture=no
5+
"""
6+
env = [
7+
"CRATEDB_CONNECTION_STRING=crate://crate@localhost/?schema=notebook",
8+
"PYDEVD_DISABLE_FILE_VALIDATION=1",
9+
]
10+
11+
log_level = "DEBUG"
12+
log_cli_level = "DEBUG"
13+
14+
testpaths = [
15+
"*.py",
16+
]
17+
xfail_strict = true
18+
markers = [
19+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pueblo[notebook,testing]>=0.0.10
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from testbook import testbook
2+
3+
4+
def test_notebook(notebook):
5+
"""
6+
Execute Jupyter Notebook, one test case per .ipynb file.
7+
"""
8+
with testbook(notebook) as tb:
9+
tb.execute()

0 commit comments

Comments
 (0)