-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for functions in run_cosmosis
- Loading branch information
1 parent
fed430f
commit dac5840
Showing
3 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ __pycache__/ | |
*$py.class | ||
*.DS_Store | ||
*.png | ||
*.ipy | ||
|
||
# C extensions | ||
*.so | ||
|
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,57 @@ | ||
import pytest | ||
from blind_2pt_cosmosis.run_cosmosis_2pt import setup_pipeline, modify_settings, run_pipeline, run_cosmosis_togen_2ptdict | ||
|
||
def test_modify_settings(): | ||
# Setup | ||
class MockIni: | ||
def __init__(self): | ||
self.__dict__ = {'_sections': {'test': {}, 'output': {}, 'pipeline': {}, 'shear_2pt_eplusb': {}, '2pt_gal': {}, 'fits_nz': {}}} | ||
|
||
ini = MockIni() | ||
angles_file = 'angles.fits' | ||
nz_file = 'nz.fits' | ||
|
||
# Exercise | ||
result = modify_settings(ini, angles_file, nz_file) | ||
|
||
# Verify | ||
assert result._sections['test']['save_dir'] == '' | ||
assert result._sections['output']['save_dir'] == '' | ||
assert result._sections['pipeline']['debug'] == 'F' | ||
assert result._sections['pipeline']['quiet'] == 'T' | ||
assert result._sections['shear_2pt_eplusb']['theta_file'] == angles_file | ||
assert result._sections['2pt_gal']['theta_file'] == angles_file | ||
assert result._sections['fits_nz']['nz_file'] == nz_file | ||
|
||
def test_modify_settings_no_files(): | ||
# Setup | ||
class MockIni: | ||
def __init__(self): | ||
self.__dict__ = {'_sections': {'test': {}, 'output': {}, 'pipeline': {}, 'shear_2pt_eplusb': {}, '2pt_gal': {}, 'fits_nz': {}}} | ||
|
||
ini = MockIni() | ||
|
||
# Exercise | ||
result = modify_settings(ini) | ||
|
||
# Verify | ||
assert result._sections['test']['save_dir'] == '' | ||
assert result._sections['output']['save_dir'] == '' | ||
assert result._sections['pipeline']['debug'] == 'F' | ||
assert result._sections['pipeline']['quiet'] == 'T' | ||
assert 'theta_file' not in result._sections['shear_2pt_eplusb'] | ||
assert 'theta_file' not in result._sections['2pt_gal'] | ||
assert 'nz_file' not in result._sections['fits_nz'] | ||
|
||
def test_modify_settings_missing_section(): | ||
# Setup | ||
class MockIni: | ||
def __init__(self): | ||
self.__dict__ = {'_sections': {'test': {}, 'output': {}, 'pipeline': {}, 'shear_2pt_eplusb': {}, '2pt_gal': {}}} | ||
|
||
ini = MockIni() | ||
nz_file = 'nz.fits' | ||
|
||
# Exercise and Verify | ||
with pytest.raises(ValueError): | ||
modify_settings(ini, None, nz_file) |
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