Skip to content

Commit a5a54b0

Browse files
committed
Added download of test data if tests are run locally
1 parent 99304f7 commit a5a54b0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

tests/test_LFP/test_LFP.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# Import the python package 'ncpi'
99
import ncpi
10+
from ncpi import tools
1011

1112
# Import the test module
1213
import pytest
@@ -32,18 +33,42 @@
3233
# Methods used to compute the features
3334
# all_methods = ['catch22','power_spectrum_parameterization_1']
3435

36+
# Zenodo URL that contains the simulation and empirical test data and ML models for LFP method
37+
zenodo_URL_test = "https://zenodo.org/api/records/17479326"
38+
3539
# Get the directory where this test file is located
3640
test_dir = os.path.dirname(os.path.abspath(__file__))
3741

42+
# Path to save zenodo test files locally
43+
zenodo_test_files = os.path.join(test_dir, "..", "data", "zenodo_test_files_LFP")
44+
3845
# Paths to zenodo simulation files
39-
zenodo_dir_sim = os.path.join(test_dir, "..", "data", "zenodo_test_files_LFP", "zenodo_sim_files") # Dir of GitHub testing downloaded files (set in tests.yml)
46+
zenodo_dir_sim = os.path.join(zenodo_test_files, "zenodo_sim_files") # Dir of GitHub testing downloaded files (set in tests.yml)
4047

4148
# Paths to zenodo empirical files
42-
zenodo_dir_emp= os.path.join(test_dir, "..", "data", "zenodo_test_files_LFP", "zenodo_emp_files") # Dir of GitHub testing downloaded files (set in tests.yml)
49+
zenodo_dir_emp= os.path.join(zenodo_test_files, "zenodo_emp_files") # Dir of GitHub testing downloaded files (set in tests.yml)
4350

4451
# ML model used to compute the predictions (MLPRegressor, Ridge or NPE)
4552
ML_model = 'MLPRegressor'
4653

54+
def download_data_if_needed():
55+
"""Download test data only when running locally and data is missing"""
56+
# Skip if running in GitHub Actions
57+
if os.getenv('GITHUB_ACTIONS'):
58+
print("Running in CI - assuming test data is cached")
59+
return
60+
61+
# Download if zenodo sim files data don't exist locally
62+
if not os.path.exists(zenodo_dir_sim):
63+
tools.timer("Downloading simulation data for local execution...")(
64+
tools.download_zenodo_record
65+
)(zenodo_URL_test, download_dir=zenodo_test_files)
66+
else:
67+
print("Zenodo sim and emp test files already exist locally")
68+
69+
# Download the data if it's not already downloaded
70+
download_data_if_needed()
71+
4772
def LFP_mean(method):
4873
"""
4974
Compute only certain data for testing and calculate the average
@@ -83,3 +108,4 @@ def test_LFP():
83108
# mean_power = LFP_mean('power_spectrum_parameterization_1')
84109
# print(f'Is \n{mean_catch} equal or similar to \n-0.8690581451462226?')
85110
# print(f'Is \n{mean_power} equal or similar to \n-1.2395402659827317?')
111+
# print('If no error messages were showed, the tests completed successfully.')

0 commit comments

Comments
 (0)