1
1
import os
2
2
from pathlib import Path
3
3
import numpy as np
4
+ import pytest
4
5
from astropy .time import Time
5
6
import astropy .units as u
6
7
from ctapipe .core import Provenance
@@ -69,7 +70,7 @@ def test_load_position_and_bending_corrections():
69
70
def test_read_target_log (tmp_path ):
70
71
from ctapipe_io_lst .pointing import PointingSource
71
72
72
- targets = PointingSource ._read_target_log (test_target_log )
73
+ targets = PointingSource .read_target_log (test_target_log )
73
74
assert len (targets ) == 7
74
75
assert targets .colnames == ["start_unix" , "ra" , "dec" , "name" , "end_unix" , "start" , "end" ]
75
76
@@ -83,7 +84,7 @@ def test_read_target_log(tmp_path):
83
84
# test with empty file
84
85
empty_log = (tmp_path / "Target_log.txt" )
85
86
empty_log .open ("w" ).close ()
86
- targets = PointingSource ._read_target_log (empty_log )
87
+ targets = PointingSource .read_target_log (empty_log )
87
88
assert len (targets ) == 0
88
89
assert targets .colnames == ["start_unix" , "ra" , "dec" , "name" , "end_unix" , "start" , "end" ]
89
90
assert targets ["ra" ].unit == u .deg
@@ -99,13 +100,28 @@ def test_read_target_log(tmp_path):
99
100
tokens = tokens [:- 1 ]
100
101
f .write (" " .join (tokens ) + "\n " )
101
102
102
- targets = PointingSource ._read_target_log (log_no_names )
103
+ targets = PointingSource .read_target_log (log_no_names )
103
104
assert len (targets ) == 7
104
105
assert targets .colnames == ["start_unix" , "ra" , "dec" , "name" , "end_unix" , "start" , "end" ]
105
106
106
107
np .testing .assert_array_equal (targets ["name" ], ["unknown" ] * 7 )
107
108
np .testing .assert_array_equal (targets ["ra" ], [83.6296 , 86.6333 ] * 3 + [79.1725 ])
108
109
110
+ # test with missing TrackEnd line
111
+ log_missing_end = tmp_path / "target_log_missing_end.txt"
112
+ log_lines .pop (1 )
113
+ log_missing_end .write_text ('\n ' .join (log_lines ))
114
+
115
+ with pytest .warns (match = "Expected TrackingEnd" ):
116
+ targets = PointingSource .read_target_log (log_missing_end )
117
+
118
+ assert len (targets ) == 7
119
+ assert targets [0 ]['end_unix' ] == targets [1 ]['start_unix' ] - 1
120
+
121
+ with pytest .raises (ValueError , match = "Expected TrackingEnd" ):
122
+ targets = PointingSource .read_target_log (log_missing_end , ignore_missing_end = False )
123
+
124
+
109
125
110
126
def test_targets ():
111
127
from ctapipe_io_lst import PointingSource , LSTEventSource
0 commit comments