@@ -127,20 +127,23 @@ def test_votable_quantity_write(tmpdir):
127127
128128
129129@pytest .mark .parametrize ('table_types' , (Table , QTable ))
130- def test_io_time_write_fits (tmpdir , table_types ):
130+ def test_io_time_write_fits_standard (tmpdir , table_types ):
131131 """
132132 Test that table with Time mixin columns can be written by io.fits.
133133 Validation of the output is done. Test that io.fits writes a table
134134 containing Time mixin columns that can be partially round-tripped
135135 (metadata scale, location).
136+
137+ Note that we postpone checking the "local" scale, since that cannot
138+ be done with format 'cxcsec', as it requires an epoch.
136139 """
137- t = table_types ([[1 ,2 ], ['string' , 'column' ]])
138- for scale in time .TIME_SCALES :
139- t ['a' + scale ] = time .Time ([[1 ,2 ],[3 ,4 ]], format = 'cxcsec' , scale = scale ,
140- location = EarthLocation (- 2446354 ,
141- 4237210 , 4077985 , unit = 'm' ))
140+ t = table_types ([[1 , 2 ], ['string' , 'column' ]])
141+ for scale in time .STANDARD_TIME_SCALES :
142+ t ['a' + scale ] = time .Time ([[1 , 2 ], [3 , 4 ]], format = 'cxcsec' ,
143+ scale = scale , location = EarthLocation (
144+ - 2446354 , 4237210 , 4077985 , unit = 'm' ))
142145 t ['b' + scale ] = time .Time (['1999-01-01T00:00:00.123456789' ,
143- '2010-01-01T00:00:00' ], format = 'isot' , scale = scale )
146+ '2010-01-01T00:00:00' ], scale = scale )
144147 t ['c' ] = [3. , 4. ]
145148
146149 filename = str (tmpdir .join ('table-tmp' ))
@@ -149,7 +152,7 @@ def test_io_time_write_fits(tmpdir, table_types):
149152 t .write (filename , format = 'fits' , overwrite = True )
150153 tm = table_types .read (filename , format = 'fits' , astropy_native = True )
151154
152- for scale in time .TIME_SCALES :
155+ for scale in time .STANDARD_TIME_SCALES :
153156 for ab in ('a' , 'b' ):
154157 name = ab + scale
155158
@@ -176,22 +179,85 @@ def test_io_time_write_fits(tmpdir, table_types):
176179 assert (tm [name ] == t [name ]).all ()
177180
178181 # Test for conversion of time data to its value, as defined by its format
179- for scale in time .TIME_SCALES :
182+ for scale in time .STANDARD_TIME_SCALES :
180183 for ab in ('a' , 'b' ):
181184 name = ab + scale
182185 t [name ].info .serialize_method ['fits' ] = 'formatted_value'
183186
184187 t .write (filename , format = 'fits' , overwrite = True )
185188 tm = table_types .read (filename , format = 'fits' )
186189
187- for scale in time .TIME_SCALES :
190+ for scale in time .STANDARD_TIME_SCALES :
188191 for ab in ('a' , 'b' ):
189192 name = ab + scale
190193
191194 assert not isinstance (tm [name ], time .Time )
192195 assert (tm [name ] == t [name ].value ).all ()
193196
194197
198+ @pytest .mark .parametrize ('table_types' , (Table , QTable ))
199+ def test_io_time_write_fits_local (tmpdir , table_types ):
200+ """
201+ Test that table with a Time mixin with scale local can also be written
202+ by io.fits. Like ``test_io_time_write_fits_standard`` above, but avoiding
203+ ``cxcsec`` format, which requires an epoch and thus cannot be used for a
204+ local time scale.
205+ """
206+ t = table_types ([[1 , 2 ], ['string' , 'column' ]])
207+ t ['a_local' ] = time .Time ([[50001 , 50002 ], [50003 , 50004 ]],
208+ format = 'mjd' , scale = 'local' ,
209+ location = EarthLocation (- 2446354 , 4237210 , 4077985 ,
210+ unit = 'm' ))
211+ t ['b_local' ] = time .Time (['1999-01-01T00:00:00.123456789' ,
212+ '2010-01-01T00:00:00' ], scale = 'local' )
213+ t ['c' ] = [3. , 4. ]
214+
215+ filename = str (tmpdir .join ('table-tmp' ))
216+
217+ # Show that FITS format succeeds
218+ t .write (filename , format = 'fits' , overwrite = True )
219+ tm = table_types .read (filename , format = 'fits' , astropy_native = True )
220+
221+ for ab in ('a' , 'b' ):
222+ name = ab + '_local'
223+
224+ # Assert that the time columns are read as Time
225+ assert isinstance (tm [name ], time .Time )
226+
227+ # Assert that the scales round-trip
228+ assert tm [name ].scale == t [name ].scale
229+
230+ # Assert that the format is jd
231+ assert tm [name ].format == 'jd'
232+
233+ # Assert that the location round-trips
234+ assert tm [name ].location == t [name ].location
235+
236+ # Finally assert that the column data round-trips
237+ assert (tm [name ] == t [name ]).all ()
238+
239+ for name in ('col0' , 'col1' , 'c' ):
240+ # Assert that the non-time columns are read as Column
241+ assert isinstance (tm [name ], Column )
242+
243+ # Assert that the non-time columns' data round-trips
244+ assert (tm [name ] == t [name ]).all ()
245+
246+ # Test for conversion of time data to its value, as defined by its format.
247+ for ab in ('a' , 'b' ):
248+ name = ab + '_local'
249+ t [name ].info .serialize_method ['fits' ] = 'formatted_value'
250+
251+ t .write (filename , format = 'fits' , overwrite = True )
252+ tm = table_types .read (filename , format = 'fits' )
253+
254+ for ab in ('a' , 'b' ):
255+ name = ab + '_local'
256+
257+ assert not isinstance (tm [name ], time .Time )
258+ assert (tm [name ] == t [name ].value ).all ()
259+
260+
195261def test_votable_mixin_write_fail (mixin_cols ):
196262 """
197263 Test that table with mixin columns (excluding Quantity) cannot be written by
0 commit comments