Skip to content

Commit ba6ef8a

Browse files
committed
Framework/Streamlit: Add software tests
1 parent 40efea3 commit ba6ef8a

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ updates:
8080
schedule:
8181
interval: "daily"
8282

83+
- directory: "/framework/streamlit"
84+
package-ecosystem: "pip"
85+
schedule:
86+
interval: "daily"
87+
8388
# Topics.
8489

8590
- directory: "/topic/machine-learning/automl"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Streamlit
2+
3+
on:
4+
pull_request:
5+
branches: ~
6+
paths:
7+
- '.github/workflows/framework-streamlit.yml'
8+
- 'framework/streamlit/**'
9+
- '/requirements.txt'
10+
push:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/framework-streamlit.yml'
14+
- 'framework/streamlit/**'
15+
- '/requirements.txt'
16+
17+
# Allow job to be triggered manually.
18+
workflow_dispatch:
19+
20+
# Run job each night after CrateDB nightly has been published.
21+
schedule:
22+
- cron: '0 3 * * *'
23+
24+
# Cancel in-progress jobs when pushing to the same branch.
25+
concurrency:
26+
cancel-in-progress: true
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
29+
jobs:
30+
test:
31+
name: "
32+
Python: ${{ matrix.python-version }}
33+
CrateDB: ${{ matrix.cratedb-version }}
34+
on ${{ matrix.os }}"
35+
runs-on: ${{ matrix.os }}
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
os: [ 'ubuntu-latest' ]
40+
python-version: [ '3.10', '3.11', '3.12' ]
41+
cratedb-version: [ 'nightly' ]
42+
43+
services:
44+
cratedb:
45+
image: crate/crate:${{ matrix.cratedb-version }}
46+
ports:
47+
- 4200:4200
48+
- 5432:5432
49+
env:
50+
CRATE_HEAP_SIZE: 4g
51+
52+
steps:
53+
54+
- name: Acquire sources
55+
uses: actions/checkout@v4
56+
57+
- name: Set up Python
58+
uses: actions/setup-python@v5
59+
with:
60+
python-version: ${{ matrix.python-version }}
61+
architecture: x64
62+
cache: 'pip'
63+
cache-dependency-path: |
64+
requirements.txt
65+
framework/streamlit/requirements.txt
66+
framework/streamlit/requirements-dev.txt
67+
68+
- name: Install utilities
69+
run: |
70+
pip install -r requirements.txt
71+
72+
- name: Validate framework/streamlit
73+
run: |
74+
ngr test --accept-no-venv framework/streamlit

framework/streamlit/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@ streamlit run basic_sys_summits.py
3232
Enjoy the list of mountains.
3333

3434
![image](https://github.com/crate/cratedb-examples/assets/453543/7dc54224-06d0-4cfb-a5e0-b216c03bf3d2)
35+
36+
37+
## Development
38+
39+
Acquire `cratedb-example` repository, and set up sandbox:
40+
```shell
41+
git clone https://github.com/crate/cratedb-examples
42+
cd cratedb-examples
43+
python3 -m venv .venv
44+
source .venv/bin/activate
45+
pip install -r requirements.txt
46+
```
47+
48+
Then, invoke the integration test cases:
49+
```shell
50+
ngr test framework/streamlit
51+
```

framework/streamlit/pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[tool.pytest.ini_options]
2+
minversion = "2.0"
3+
addopts = """
4+
-rfEX -p pytester --strict-markers --verbosity=3
5+
--capture=no
6+
"""
7+
log_level = "DEBUG"
8+
log_cli_level = "DEBUG"
9+
testpaths = ["*.py"]
10+
xfail_strict = true
11+
markers = [
12+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest<9

framework/streamlit/test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from streamlit.testing.v1 import AppTest
2+
3+
4+
def test_read_sys_summits():
5+
"""
6+
Verify reading CrateDB's built-in `sys.summits` database table through Streamlit.
7+
"""
8+
9+
# Invoke Streamlit application.
10+
at = AppTest.from_file("basic_sys_summits.py").run()
11+
12+
# There should not be an exception.
13+
assert not at.exception
14+
15+
# Probe dataframe output.
16+
df = at.dataframe.values[0]
17+
mountains = df["mountain"].values
18+
assert "Mont Blanc" in mountains
19+
assert "Matterhorn" in mountains
20+
21+
# Probe table output.
22+
df = at.table.values[0]
23+
mountains = df["mountain"].values
24+
assert "Mont Blanc" in mountains
25+
assert "Matterhorn" in mountains
26+
27+
# Probe Markdown output.
28+
assert "Mont Blanc" in at.markdown.values
29+
assert "Monte Rosa" in at.markdown.values

0 commit comments

Comments
 (0)