Skip to content

Commit fc31d69

Browse files
committed
Add initial test
1 parent 358312a commit fc31d69

File tree

3 files changed

+108
-9
lines changed

3 files changed

+108
-9
lines changed

kadi/commands/tests/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import pytest
22
import ska_sun
33

4+
import kadi.commands as kc
5+
46

57
@pytest.fixture()
68
def fast_sun_position_method(monkeypatch: pytest.MonkeyPatch):
79
monkeypatch.setattr(ska_sun.conf, "sun_position_method_default", "fast")
10+
11+
12+
@pytest.fixture(scope="module", autouse=True)
13+
def cmds_dir(tmp_path_factory):
14+
with kc.conf.set_temp("cache_loads_in_astropy_cache", True):
15+
with kc.conf.set_temp("clean_loads_dir", False):
16+
cmds_dir = tmp_path_factory.mktemp("cmds_dir")
17+
with kc.conf.set_temp("commands_dir", str(cmds_dir)):
18+
yield

kadi/commands/tests/test_commands.py

-9
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@
4242
HAS_AGASC_1P8 = False
4343

4444

45-
@pytest.fixture(scope="module", autouse=True)
46-
def cmds_dir(tmp_path_factory):
47-
with commands.conf.set_temp("cache_loads_in_astropy_cache", True):
48-
with commands.conf.set_temp("clean_loads_dir", False):
49-
cmds_dir = tmp_path_factory.mktemp("cmds_dir")
50-
with commands.conf.set_temp("commands_dir", str(cmds_dir)):
51-
yield
52-
53-
5445
def test_find():
5546
idx_cmds = commands_v2.IDX_CMDS
5647
pars_dict = commands_v2.PARS_DICT
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Use data file from parse_cm.test for get_cmds_from_backstop test.
2+
# This package is a dependency
3+
import astropy.table as apt
4+
import numpy as np
5+
import pytest
6+
from testr.test_helper import has_internet
7+
8+
import kadi.commands as kc
9+
import kadi.commands.commands_v2 as kcc2
10+
import kadi.commands.observations as kco
11+
12+
HAS_INTERNET = has_internet()
13+
14+
15+
@pytest.mark.skipif(not HAS_INTERNET, reason="No internet connection")
16+
def test_filter_scs107_2024366(cmds_dir):
17+
"""Filter the command events associated with SCS-107 on 2024:366"""
18+
start = "2024:365"
19+
stop = "2025:003"
20+
21+
obss_as_run = apt.Table(kc.get_observations(start, stop))
22+
23+
with kc.set_time_now(stop), kc.conf.set_temp("default_lookback", 20):
24+
obss_planned = apt.Table(
25+
kc.get_observations(start, stop, event_filter=kc.filter_scs107_events)
26+
)
27+
28+
# As-run gets an extra observation because the manual obsid update at
29+
# 2025:001:12:48:34.040 breaks the observation into two.
30+
assert len(obss_as_run) == 34
31+
assert len(obss_planned) == 33
32+
33+
# Now get rid of the 2nd of the observation that was split into two. The source of
34+
# CMD_EVT is from the Obsid command event at 2025:001:12:48:34.040.
35+
ok = obss_as_run["source"] != "CMD_EVT"
36+
obss_as_run = obss_as_run[ok]
37+
38+
# Make sure that the source and starcat_date are the same.
39+
assert set(obss_as_run.colnames) == set(obss_planned.colnames)
40+
for name in obss_as_run.colnames:
41+
if name in ["obsid", "simpos"]:
42+
continue
43+
assert np.all(obss_as_run[name] == obss_planned[name])
44+
45+
# Now filter out the two observations that have no star catalog. These are both
46+
# the gyro hold in the high-IR zone.
47+
ok = ~obss_as_run["starcat_date"].mask
48+
obss_as_run = obss_as_run[ok]
49+
obss_planned = obss_planned[ok]
50+
51+
obss_run_planned = apt.join(obss_as_run, obss_planned, keys="starcat_date")
52+
lines = obss_run_planned[
53+
"obsid_1", "obsid_2", "simpos_1", "simpos_2", "starcat_date"
54+
].pformat()
55+
56+
assert lines == [
57+
"obsid_1 obsid_2 simpos_1 simpos_2 starcat_date ",
58+
"------- ------- -------- -------- ---------------------",
59+
" 30693 30693 92904 92904 2024:364:21:02:54.559",
60+
" 30699 30699 92560 92560 2024:365:00:21:34.399",
61+
" 28631 28631 92904 92904 2024:365:03:49:22.699",
62+
" 30486 30486 -50504 -50504 2024:365:12:13:55.474",
63+
" 30497 30497 75624 75624 2024:365:16:49:40.474",
64+
" 42815 42815 -99616 -99616 2024:365:21:32:34.599",
65+
" 42814 42814 -99616 -99616 2024:365:23:24:58.901",
66+
" 42813 42813 -99616 -99616 2024:366:01:17:07.965",
67+
" 42812 42812 -99616 -99616 2024:366:02:58:28.076",
68+
" 42810 42810 -99616 -99616 2024:366:05:08:36.000",
69+
" 42809 42809 -99616 -99616 2024:366:05:48:15.632",
70+
" 30700 30700 92560 92560 2024:366:08:26:39.076",
71+
" 30690 30690 92904 92904 2024:366:11:55:08.999",
72+
" 30550 30550 -99616 -99616 2024:366:15:21:03.938",
73+
" 30550 28803 -99616 92904 2024:366:18:05:04.938",
74+
" 30550 28365 -99616 75624 2024:366:21:21:07.538",
75+
" 30550 29835 -99616 92560 2025:001:08:44:07.810",
76+
" 65518 25501 -99616 -50504 2025:001:13:08:09.384",
77+
" 65518 26975 -99616 92904 2025:001:16:38:50.384",
78+
" 65518 30500 -99616 75624 2025:001:20:54:41.492",
79+
" 65518 25505 -99616 -50504 2025:002:01:35:29.276",
80+
" 65518 29904 -99616 92904 2025:002:03:07:54.276",
81+
" 65518 30688 -99616 92904 2025:002:04:53:45.276",
82+
" 65518 30082 -99616 92904 2025:002:08:11:25.231",
83+
" 65518 42808 -99616 -99616 2025:002:12:59:42.571",
84+
" 65518 42807 -99616 -99616 2025:002:14:17:07.525",
85+
" 65518 42806 -99616 -99616 2025:002:17:17:25.479",
86+
" 65518 42805 -99616 -99616 2025:002:18:36:19.655",
87+
" 65518 42803 -99616 -99616 2025:002:20:37:36.000",
88+
" 65518 42802 -99616 -99616 2025:002:21:24:48.840",
89+
" 65518 42801 -99616 -99616 2025:002:23:18:02.848",
90+
]
91+
92+
keys = [
93+
(None, None, 30, None),
94+
(None, "2025:003", 20, kc.filter_scs107_events),
95+
]
96+
assert list(kcc2.CMDS_RECENT) == keys
97+
assert list(kco.OBSERVATIONS) == keys

0 commit comments

Comments
 (0)