Skip to content

Commit cd99bc2

Browse files
committed
split test and removed try blocks
1 parent 50a2e43 commit cd99bc2

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

tests/test_cmb.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def test_cmb_lensed(model_tag, freq):
7676

7777

7878
@pytest.mark.parametrize("freq", [100])
79-
def test_cmb_lensed_l01(freq):
79+
def test_cmb_lensed_with_patch_object(freq):
80+
# The CMBLensed Model expects the CAMB power spectrum output to
81+
# begin at l=2, resulting misalignment of ells when it is not
82+
# included. To test the fix, the method must be patched.
83+
# This test shows that patching works, complementing test_cmb_lensed_l01.
8084

8185
model_number = 5
8286
expected_output = pysm3.read_map(
@@ -93,7 +97,6 @@ def test_cmb_lensed_l01(freq):
9397
c1_delens_l = temp_model.read_txt('pysm_2/delens_ells.txt',
9498
unpack=True)
9599

96-
# This portion should always pass
97100
with patch.object(target=pysm3.models.cmb.CMBLensed,
98101
attribute="read_txt",
99102
side_effect=[c1_spectra, c1_delens_l]):
@@ -106,16 +109,34 @@ def test_cmb_lensed_l01(freq):
106109
)
107110
model = pysm3.Sky(nside=64, component_objects=[c1])
108111

109-
try:
110-
assert_quantity_allclose(
111-
expected_output,
112-
model.get_emission(freq * u.GHz),
113-
rtol=1e-5
114-
)
115-
except AssertionError:
116-
pytest.fail(f"Unexpected AssertionError. Superfail.")
112+
assert_quantity_allclose(
113+
expected_output,
114+
model.get_emission(freq * u.GHz),
115+
rtol=1e-5
116+
)
117+
118+
119+
@pytest.mark.parametrize("freq", [100])
120+
def test_cmb_lensed_l01(freq):
121+
# The CMBLensed Model expects the CAMB power spectrum output to
122+
# begin at l=2, resulting misalignment of ells when it is not
123+
# included. This test shows that the fix works, by changing the
124+
# input cls from the original test (test_cmb_lensed) to include l=0,1.
125+
126+
model_number = 5
127+
expected_output = pysm3.read_map(
128+
f"pysm_2_test_data/check{model_number}cmb_{freq}p0_64.fits",
129+
64,
130+
unit="uK_RJ",
131+
field=(0, 1, 2),
132+
)
117133

118-
# This portion should pass only with the fix
134+
# Use a temporary model to get access to the read_txt method
135+
temp_model = pysm3.Model(nside=64)
136+
c1_spectra = temp_model.read_txt('pysm_2/camb_lenspotentialCls.dat',
137+
unpack=True)
138+
c1_delens_l = temp_model.read_txt('pysm_2/delens_ells.txt',
139+
unpack=True)
119140

120141
# Add rows of 0s for l=0,1
121142
c1_spectra_l01 = np.zeros((c1_spectra.shape[0], c1_spectra.shape[1] + 2))

0 commit comments

Comments
 (0)