Skip to content

Commit

Permalink
Add a build and smoke test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ma595 committed Nov 11, 2024
1 parent 07ba290 commit b898c9e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Smoke test
run: |
export PYTHONPATH=$(pwd)/lib:$PYTHONPATH
pytest ./tests
45 changes: 45 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
import os
import numpy as np
import pandas as pd
import pickle
import tempfile
from lib.forecast import load_ts


def test_smoke_load_ts():
"""Smoke test for the load_ts function using a temporary file."""
try:
# Create a temporary directory
with tempfile.TemporaryDirectory() as temp_dir:
# Define mock variable name and file paths
var_name = "mock_var"
ts_data = np.random.rand(10, 2) # Example time series data
pca_mock = "mock_pca_object"

# Save mock time series data to a .npz file
np.savez(os.path.join(temp_dir, f"{var_name}.npz"), ts=ts_data)

# Pickle and save the mock PCA object
with open(os.path.join(temp_dir, f"pca_{var_name}"), "wb") as f:
pickle.dump(pca_mock, f)

# Test: Load the time series data using load_ts
df, dico = load_ts(temp_dir, var_name)

# Basic checks to ensure the function executed without exceptions
assert isinstance(df, pd.DataFrame), "Expected a pandas DataFrame"
assert df.shape == (
10,
2,
), f"Expected DataFrame shape (10, 2), but got {df.shape}"
assert "pca" in dico, "Expected 'pca' key in the returned dictionary"
assert dico["pca"] == pca_mock, "PCA object does not match the mock object"

except Exception as e:
pytest.fail(f"Smoke test failed: {e}")


# Run the tests with pytest
if __name__ == "__main__":
pytest.main()

0 comments on commit b898c9e

Please sign in to comment.