-
Notifications
You must be signed in to change notification settings - Fork 17
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
70 additions
and
4 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,64 @@ | ||
""" | ||
Tests for any decorators | ||
""" | ||
import astropy.units as u | ||
import pytest | ||
|
||
from fiasco import Ion | ||
from fiasco.util import needs_dataset | ||
from fiasco.util.exceptions import MissingDatasetException | ||
|
||
|
||
@pytest.fixture() | ||
def ion_like_object(hdf5_dbase_root): | ||
class NewIon(Ion): | ||
@needs_dataset('elvlc') | ||
def elvlc_method(self): | ||
pass | ||
@needs_dataset('fake') | ||
def fake_method(self): | ||
pass | ||
@property | ||
def _fake(self): | ||
raise KeyError | ||
return NewIon('Fe XI', 1*u.MK, hdf5_dbase_root=hdf5_dbase_root) | ||
|
||
|
||
@pytest.fixture() | ||
def non_ion_like_object(): | ||
class NonIon: | ||
@needs_dataset('elvlc') | ||
def elvlc_method(self): | ||
pass | ||
@property | ||
def _elvlc(self): | ||
pass | ||
@needs_dataset('fake') | ||
def fake_method(self): | ||
pass | ||
@property | ||
def _fake(self): | ||
raise KeyError | ||
def __str__(self): | ||
return 'non-ion' | ||
return NonIon() | ||
|
||
|
||
def test_decorator_ion_like_has_data(ion_like_object): | ||
# Just test that this does not throw an exception | ||
assert ion_like_object.elvlc_method() is None | ||
|
||
|
||
def test_decorator_ion_like_has_no_data(ion_like_object): | ||
with pytest.raises(MissingDatasetException, match='fake dataset missing for Fe 11'): | ||
ion_like_object.fake_method() | ||
|
||
|
||
def test_decorator_non_ion_like_has_data(non_ion_like_object): | ||
# Just test that this does not throw an exception | ||
assert non_ion_like_object.elvlc_method() is None | ||
|
||
|
||
def test_decorator_non_ion_like_has_no_data(non_ion_like_object): | ||
with pytest.raises(MissingDatasetException, match='fake dataset missing for non-ion'): | ||
non_ion_like_object.fake_method() |