-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunittests.py
More file actions
93 lines (82 loc) · 2.68 KB
/
unittests.py
File metadata and controls
93 lines (82 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pytest
import numpy as np
from astropy import units as u
from mh.MR_relation import *
class Test_inputs:
@pytest.mark.parametrize(
"x, y, thickness, err",
[
("abc", 8.00, "thick", TypeError),
(10000, "ab", "thick", TypeError),
(10000, 8.00, 1234567, TypeError),
(10000, 8.00, "wrong", ValueError),
],
)
def test_input_exceptions(self, x, y, thickness, err):
with pytest.raises(err):
M_from_Teff_logg(x, y, thickness=thickness)
@pytest.mark.parametrize(
"x, y, expected_type",
[
(0.6, 0.013, np.float64),
(0.6 * np.ones(100), 0.013, np.ndarray),
(0.6, 0.013 * np.ones(100), np.ndarray),
(0.6 * np.ones(100), 0.013 * np.ones(100), np.ndarray),
],
)
def test_floats_vs_array(self, x, y, expected_type):
logg = logg_from_M_R(x, y)
assert isinstance(logg, expected_type)
class Test_units:
def test_no_units(self):
logg = logg_from_M_R(0.6, 0.013)
assert not isinstance(logg, u.Quantity)
@pytest.mark.parametrize(
"x, y",
[
(0.6 * u.Msun, 0.013),
(0.6, 0.013 * u.Rsun),
(0.6 * u.Msun, 0.013 * u.Rsun),
],
)
def test_with_units(self, x, y):
logg = logg_from_M_R(x, y)
assert isinstance(logg, u.Quantity)
assert logg.unit == u.dex(u.cm / u.s**2)
@pytest.mark.parametrize(
"x, y",
[
(0.6 * u.K, 0.013),
(0.6, 0.013 * u.erg),
(0.6 * u.K, 0.013 * u.erg),
],
)
def test_wrong_units(self, x, y):
with pytest.raises(u.UnitsError):
logg = logg_from_M_R(x, y)
class Test_model_grids:
@pytest.mark.parametrize(
"value",
[
"Bedard20",
"Fontaine01",
"Camisassa25",
"Althaus13ELM",
],
)
def test_valid_grids(self, value):
MR_grid.set_grid(value)
def test_invalid_grid(self):
with pytest.raises(ValueError):
MR_grid.set_grid("Something else")
def test_Althaus_thin(self):
MR_grid.set_grid("Althaus13ELM")
with pytest.raises(ValueError):
tau2 = tau_from_Teff_M(10000, 0.6, "thin")
def test_switch_grid(self):
# changing model grid should give different results
MR_grid.set_grid("Bedard20")
tau1 = tau_from_Teff_M(10000, 0.6, "thick")
MR_grid.set_grid("Fontaine01")
tau2 = tau_from_Teff_M(10000, 0.6, "thick")
assert tau1 != tau2