Skip to content

Commit 7e55a57

Browse files
committed
Added test env, local execution tests
1 parent 0b13df8 commit 7e55a57

9 files changed

Lines changed: 816 additions & 13 deletions

File tree

.github/workflows/rust.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,50 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v4
19+
20+
- name: Set up Rust cache
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
~/.cargo/bin/
25+
~/.cargo/registry/index/
26+
~/.cargo/registry/cache/
27+
~/.cargo/git/db/
28+
target/
29+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-cargo-
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.11'
37+
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v5
40+
with:
41+
enable-cache: true
42+
43+
- name: Cache Python test venv
44+
uses: actions/cache@v4
45+
with:
46+
path: tests/.test-venv
47+
key: ${{ runner.os }}-test-venv-${{ hashFiles('requirements.txt') }}
48+
restore-keys: |
49+
${{ runner.os }}-test-venv-
50+
51+
- name: Setup test environment
52+
run: ./tests/setup_test_env.sh
53+
continue-on-error: true
54+
1955
- name: Build
2056
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
57+
58+
- name: Run local mode tests
59+
run: cargo test --test integration_local_mode --verbose
60+
61+
- name: Run execution tests
62+
run: cargo test --test integration_execution --verbose
63+
64+
- name: Run all other tests
65+
run: cargo test --lib --bins --verbose

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ target
2727

2828
.ipynb_checkpoints/
2929
.jupyter/
30+
tests/.test-venv

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# Python dependencies for nb-cli local execution
1+
# Python dependencies for nb-cli local execution and testing
22
# Install with: pip install -r requirements.txt
33

44
# Core dependencies for local notebook execution
55
nbclient>=0.8.0
66
nbformat>=5.9.0
77

8+
# Required for execution tests
9+
ipykernel>=6.0.0
10+
811
# Note: These are only required for local mode execution
912
# Remote mode (connecting to Jupyter Server) doesn't need these

tests/README.md

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,84 @@ This directory contains integration tests for the nb-cli tool's local mode opera
66

77
```
88
tests/
9-
├── integration_local_mode.rs # Main integration test suite
9+
├── integration_local_mode.rs # Core CLI operations (no execution)
10+
├── integration_execution.rs # Execution tests (requires Python)
11+
├── test_helpers.rs # Test utilities and venv setup
12+
├── setup_test_env.sh # Script to setup test environment
1013
├── fixtures/ # Test notebook fixtures
11-
│ ├── empty.ipynb # Empty notebook with no cells
12-
│ ├── basic.ipynb # Basic notebook with one empty cell
13-
│ ├── with_code.ipynb # Notebook with code cells
14-
│ ├── mixed_cells.ipynb # Notebook with mixed cell types
15-
│ └── with_outputs.ipynb # Notebook with cell outputs
14+
│ ├── empty.ipynb # Empty notebook with no cells
15+
│ ├── basic.ipynb # Basic notebook with one empty cell
16+
│ ├── with_code.ipynb # Notebook with code cells
17+
│ ├── mixed_cells.ipynb # Notebook with mixed cell types
18+
│ ├── with_outputs.ipynb # Notebook with cell outputs
19+
│ ├── for_execution.ipynb # Simple execution test notebook
20+
│ └── with_error.ipynb # Notebook with error cell
21+
├── .test-venv/ # Test virtual environment (auto-created)
1622
└── README.md # This file
1723
```
1824

1925
## Running Tests
2026

21-
Run all integration tests:
27+
### Setup (One Time)
28+
29+
For execution tests, you need to setup the Python environment:
30+
31+
```bash
32+
# Option 1: Use the setup script (requires uv)
33+
./tests/setup_test_env.sh
34+
35+
# Option 2: Manual setup
36+
uv venv tests/.test-venv
37+
tests/.test-venv/bin/pip install nbclient nbformat ipykernel
38+
```
39+
40+
**Note**: If you don't have `uv` installed:
41+
```bash
42+
curl -LsSf https://astral.sh/uv/install.sh | sh
43+
```
44+
45+
### Run All Tests
46+
47+
Run all integration tests (both local and execution):
48+
```bash
49+
cargo test
50+
```
51+
52+
### Run Specific Test Suites
53+
54+
Run only local mode tests (no Python required):
2255
```bash
2356
cargo test --test integration_local_mode
2457
```
2558

26-
Run specific tests:
59+
Run only execution tests (requires Python venv):
60+
```bash
61+
cargo test --test integration_execution
62+
```
63+
64+
### Run Specific Tests
65+
2766
```bash
2867
cargo test --test integration_local_mode test_create_empty_notebook
29-
cargo test --test integration_local_mode test_add_cell
68+
cargo test --test integration_execution test_execute_single_cell
3069
```
3170

32-
Run tests with output:
71+
### Run with Output
72+
3373
```bash
3474
cargo test --test integration_local_mode -- --nocapture
75+
cargo test --test integration_execution -- --nocapture
76+
```
77+
78+
### Execution Tests Behavior
79+
80+
Execution tests will automatically:
81+
-**Skip gracefully** if Python environment is not set up
82+
-**Auto-create venv** with `uv` if available
83+
-**Install dependencies** (nbclient, nbformat, ipykernel)
84+
-**Use isolated environment** (tests/.test-venv)
85+
86+
If execution tests are skipped, you'll see:
87+
```
88+
⚠️ Skipping test: execution environment not available
3589
```

tests/fixtures/for_execution.ipynb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "cell-1",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"x = 42"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "cell-2",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"y = x + 10"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "cell-3",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"print(f'Result: {y}')"
31+
]
32+
}
33+
],
34+
"metadata": {
35+
"kernelspec": {
36+
"display_name": "Python 3 (ipykernel)",
37+
"language": "python",
38+
"name": "python3"
39+
}
40+
},
41+
"nbformat": 4,
42+
"nbformat_minor": 5
43+
}

tests/fixtures/with_error.ipynb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "cell-1",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"valid_code = 123"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "cell-2",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"undefined_variable"
21+
]
22+
}
23+
],
24+
"metadata": {
25+
"kernelspec": {
26+
"display_name": "Python 3 (ipykernel)",
27+
"language": "python",
28+
"name": "python3"
29+
}
30+
},
31+
"nbformat": 4,
32+
"nbformat_minor": 5
33+
}

0 commit comments

Comments
 (0)