Skip to content

Commit 5224152

Browse files
committed
Adds a regression test for the unicode column width issue mentioned in #4228--should improve the coverage too.
1 parent f4b76b0 commit 5224152

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎astropy/io/fits/tests/test_connect.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,26 @@ def test_bool_column(tmpdir):
269269
with fits.open(str(tmpdir.join('test.fits'))) as hdul:
270270
assert hdul[1].data['col0'].dtype == np.dtype('bool')
271271
assert np.all(hdul[1].data['col0'] == arr)
272+
273+
274+
def test_unicode_column(tmpdir):
275+
"""
276+
Test that a column of unicode strings is still written as one
277+
byte-per-character in the FITS table (so long as the column can be ASCII
278+
encoded).
279+
280+
Regression test for one of the issues fixed in
281+
https://github.com/astropy/astropy/pull/4228
282+
"""
283+
284+
t = Table([np.array([u'a', u'b', u'cd'])])
285+
t.write(str(tmpdir.join('test.fits')), overwrite=True)
286+
287+
with fits.open(str(tmpdir.join('test.fits'))) as hdul:
288+
assert np.all(hdul[1].data['col0'] == ['a', 'b', 'cd'])
289+
assert hdul[1].header['TFORM1'] == '2A'
290+
291+
t2 = Table([np.array([u'\N{SNOWMAN}'])])
292+
293+
with pytest.raises(UnicodeEncodeError):
294+
t2.write(str(tmpdir.join('test.fits')), overwrite=True)

0 commit comments

Comments
 (0)