-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |