Skip to content

Commit 0c68338

Browse files
authored
Merge pull request #10 from LSSTDESC/issue/4/update-unit-tests-for-py311
Fixing up unit tests
2 parents a681428 + 79276fb commit 0c68338

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ __pycache__/
2323

2424
auxiliary_files/cosmo
2525
auxiliary_files/cosmo.hpp
26+
.DS_Store

resspect/cosmo_metric_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def fish_deriv_m(redshift, model, step, screen=False):
8383
at given redshifts.
8484
"""
8585

86-
Ob0=0.022
87-
Om0=model[1]
88-
Ode0 =model[2]
89-
cosmo = w0waCDM(model[0], Ob0, Om0, Ode0, model[3],model[4], name="w0waCDM")
86+
Ob0 = 0.022
87+
Om0 = model[1]
88+
Ode0 = model[2]
89+
cosmo = w0waCDM(H0=model[0], Ob0=Ob0, Om0=Om0, Ode0=Ode0, w0=model[3], wa=model[4], name="w0waCDM")
9090

9191
cosmo=assign_cosmo(cosmo, model)
9292

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
def test_data_path():
1313
return Path(__file__).parent.parent / "data" / "tests"
1414

15+
@pytest.fixture
16+
def test_des_data_path():
17+
return Path(__file__).parent.parent / "data" / "tests" / "DES_data"
18+
1519

1620
@pytest.fixture(scope="session")
1721
def base_temp(tmp_path_factory):

tests/test_batch_functions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import numpy as np
44

55

6-
@pytest.mark.skip(reason='Test failing with numpy.AxisError - Check inputs')
76
def test_entropy_from_probs_b_M_C():
87

98
from resspect import batch_functions
109

1110
np.random.seed(42)
12-
x = np.random.rand(100)
11+
num_data_points = 3
12+
committee_size = 10
13+
num_classes = 5
14+
x = np.random.rand(num_data_points, committee_size, num_classes)
1315

1416
foo = batch_functions.entropy_from_probs_b_M_C(x)
1517

tests/test_learn_loop.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
1+
import os
22
import pytest
3-
4-
5-
# ToDo @emilleishida - Check this test later
6-
@pytest.mark.skip("Test failing for now")
7-
def test_can_run_learn_loop(extract_feature):
8-
"""Just a sanity test"""
9-
10-
from resspect.learn_loop import learn_loop
11-
12-
learn_loop(nloops=1,
13-
features_method="bazin",
14-
strategy="RandomSampling",
15-
path_to_features=extract_feature,
16-
output_metrics_file="just_a_name.csv",
17-
output_queried_file="just_other_name.csv")
18-
19-
20-
@pytest.fixture(scope="function")
21-
def extract_feature(path_to_test_data):
22-
from resspect import fit_snpcc
23-
24-
path_to_data_dir = path_to_test_data
25-
output_file = 'output_file.dat'
26-
27-
fit_snpcc(path_to_data_dir=path_to_data_dir, features_file=output_file)
28-
29-
return output_file
30-
3+
import tempfile
4+
5+
from resspect import fit_snpcc
6+
from resspect.learn_loop import learn_loop
7+
8+
def test_can_run_learn_loop(test_des_data_path):
9+
"""Test that learn_loop can load data and run."""
10+
with tempfile.TemporaryDirectory() as dir_name:
11+
# Create the feature files to use for the learning loop.
12+
output_file = os.path.join(dir_name, "output_file.dat")
13+
fit_snpcc(
14+
path_to_data_dir=test_des_data_path,
15+
features_file=output_file,
16+
)
17+
18+
learn_loop(
19+
nloops=1,
20+
features_method="bazin",
21+
strategy="RandomSampling",
22+
path_to_features=output_file,
23+
output_metrics_file=os.path.join(dir_name,"just_a_name.csv"),
24+
output_queried_file=os.path.join(dir_name,"just_other_name.csv"),
25+
)
3126

3227
if __name__ == '__main__':
3328
pytest.main()

0 commit comments

Comments
 (0)