Add test code to verify CI pipeline
- src/train.py: example training script - tests/test_train.py: pytest test - requirements.txt: pandas, scikit-learn - Fix ci.yaml: use python:3.10-slim container Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b25b7d080e
commit
d782c2741d
|
|
@ -8,16 +8,13 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint-and-test:
|
lint-and-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
|
container:
|
||||||
|
image: python:3.10-slim
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.10"
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
pandas>=2.0.0
|
||||||
|
scikit-learn>=1.3.0
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
"""Example training script for MLOps pipeline test."""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def train():
|
||||||
|
"""Simple training function for pipeline testing."""
|
||||||
|
model_info = {
|
||||||
|
"model": "test-model",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"accuracy": 0.95,
|
||||||
|
}
|
||||||
|
|
||||||
|
os.makedirs("models", exist_ok=True)
|
||||||
|
with open("models/model_info.json", "w") as f:
|
||||||
|
json.dump(model_info, f, indent=2)
|
||||||
|
|
||||||
|
print(f"Training complete: {model_info}")
|
||||||
|
return model_info
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
train()
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""Tests for training script."""
|
||||||
|
from src.train import train
|
||||||
|
|
||||||
|
|
||||||
|
def test_train_returns_model_info():
|
||||||
|
result = train()
|
||||||
|
assert result["model"] == "test-model"
|
||||||
|
assert "accuracy" in result
|
||||||
|
assert result["accuracy"] > 0
|
||||||
Loading…
Reference in New Issue