diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 21fe61a..8cb2b7c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -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 diff --git a/tests/test_smoke.py b/tests/test_smoke.py new file mode 100644 index 0000000..e705b67 --- /dev/null +++ b/tests/test_smoke.py @@ -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()