-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_radex.py
93 lines (79 loc) · 1.9 KB
/
test_radex.py
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
# standard library
from itertools import repeat
from pathlib import Path
# dependencies
from ndradex.consts import RADEX_BIN
from ndradex.lamda import query
from ndradex.radex import run, runmap, to_input
# test data
radex_input = (
"radex.out",
"110.0 120.0",
"100.0",
"1",
"H2",
"1000.0",
"2.73",
"1000000000000000.0",
"1.0",
"0",
)
radex_output = [
(
"1 -- 0",
"5.5",
"115.2712",
"2600.7576",
"132.463",
"9.966E-03",
"1.278E+00",
"4.934E-01",
"1.715E-01",
"1.360E+00",
"2.684E-08",
)
]
radex_params = {
"outfile": "radex.out",
"freq_min": 110.0,
"freq_max": 120.0,
"T_kin": 100.0,
"n_H2": 1e3,
"n_pH2": 0.0,
"n_oH2": 0.0,
"n_e": 0.0,
"n_H": 0.0,
"n_He": 0.0,
"n_Hp": 0.0,
"T_bg": 2.73,
"N": 1e15,
"dv": 1.0,
}
# test functions
def test_run() -> None:
with query("co").to_tempfile() as file:
output = run(
radex=RADEX_BIN / "radex-1",
input=(file.name, *radex_input),
)
# test non-existence of the input/output files
assert not Path(radex_input[0]).exists()
assert not Path(radex_input[1]).exists()
# test equality of the output values
assert output == radex_output
def test_runmap() -> None:
with query("co").to_tempfile() as file:
outputs = list(
runmap(
radexes=repeat(RADEX_BIN / "radex-1", 10),
inputs=repeat((file.name, *radex_input), 10),
)
)
# test non-existence of the input/output files
assert not Path(radex_input[0]).exists()
assert not Path(radex_input[1]).exists()
# test equality of the output values
assert outputs[0] == radex_output
def test_to_input() -> None:
input = to_input(datafile="dummy", **radex_params)
assert input[1:] == radex_input