-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from thegyro/issue88
Fix for Issue #88: Moved test functions for tardis.util from test_config_reader
- Loading branch information
Showing
2 changed files
with
57 additions
and
64 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 |
---|---|---|
@@ -1,8 +1,61 @@ | ||
from tardis import util | ||
#tests for util module | ||
|
||
import pytest | ||
from astropy import units as u | ||
from tardis import atomic | ||
from tardis.util import species_string_to_tuple, parse_quantity, element_symbol2atomic_number, atomic_number2element_symbol, reformat_element_symbol, MalformedQuantityError | ||
|
||
def test_quantity_parser_normal(): | ||
q1 = parse_quantity('5 km/s') | ||
assert q1.value == 5. | ||
assert q1.unit == u.Unit('km/s') | ||
|
||
def test_quantity_parser_malformed_quantity1(): | ||
with pytest.raises(MalformedQuantityError): | ||
q1 = parse_quantity('abcd') | ||
|
||
def test_quantity_parser_malformed_quantity2(): | ||
with pytest.raises(MalformedQuantityError): | ||
q1 = parse_quantity('5 abcd') | ||
|
||
def test_atomic_number2element_symbol(): | ||
assert util.atomic_number2element_symbol(14) == 'Si' | ||
assert atomic_number2element_symbol(14) == 'Si' | ||
|
||
def test_element_symbol2atomic_number(): | ||
assert util.element_symbol2atomic_number('Si') == 14 | ||
atom_data = atomic.AtomData.from_hdf5(atomic.default_atom_h5_path) | ||
def _test_element_symbol2atomic_number(element_string, atomic_number): | ||
assert element_symbol2atomic_number(element_string) == atomic_number | ||
|
||
data = [('sI', 14), | ||
('ca', 20), | ||
('Fe', 26)] | ||
|
||
for element_symbol, atomic_number in data: | ||
yield _test_element_symbol2atomic_number, element_symbol, atomic_number | ||
|
||
def test_element_symbol_reformatter(): | ||
def _test_element_symbol_reformatter(unformatted_element_string, formatted_element_string): | ||
assert reformat_element_symbol(unformatted_element_string) == formatted_element_string | ||
|
||
data = [('si', 'Si'), | ||
('sI', 'Si'), | ||
('Si', 'Si'), | ||
('c', 'C'), | ||
('C', 'C'), | ||
] | ||
|
||
for unformatted_element_string, formatted_element_string in data: | ||
yield _test_element_symbol_reformatter, unformatted_element_string, formatted_element_string | ||
|
||
def test_species_string_to_species(): | ||
atom_data = atomic.AtomData.from_hdf5(atomic.default_atom_h5_path) | ||
def _test_species_string_to_species_tuple(species_string, species_tuple): | ||
assert species_string_to_tuple(species_string) == species_tuple | ||
|
||
data = [('si ii', (14, 1) ), | ||
('si 2', (14, 1)), | ||
('si ix', (14, 8)), | ||
] | ||
|
||
for species_string, species_tuple in data: | ||
yield _test_species_string_to_species_tuple, species_string, species_tuple |