'Regression test for https://github.com/spacetelescope/PyFITS/issues/51
Test data extracted from a header in an actual FITS file found in the
wild.  Names have been changed to protect the innocent.'

def test_newlines_in_commentary(self):

    h = fits.Header()
    pytest.raises(ValueError, h.set, 'HISTORY', '\n')
    pytest.raises(ValueError, h.set, 'HISTORY', '\nabc')
    pytest.raises(ValueError, h.set, 'HISTORY', 'abc\n')
    pytest.raises(ValueError, h.set, 'HISTORY', 'abc\ndef')
    test_cards = ["HISTORY    File    modified    by    user    'wilma'    with    fv        on    2013-04-22T21:42:18                                            HISTORY    File    modified    by    user    '    fred'    with    fv        on    2013-04-23T11:16:29                                            HISTORY    File    modified    by    user    '    fred'    with    fv        on    2013-11-04T16:59:14                                            HISTORY    File    modified    by    user    'wilma'    with    fv        on    2013-04-22T21:42:18\nFile    modifHISTORY    ied    by    user    'wilma'    with    fv        on    2013-04-23T11:16:29\nFile    modified    by    useHISTORY    r    '    fred'    with    fv        on    2013-11-04T16:59:14                                                                                                                            HISTORY    File    modified    by    user    'wilma'    with    fv        on    2013-04-22T21:42:18\nFile    modifHISTORY    ied    by    user    'wilma'    with    fv        on    2013-04-23T11:16:29\nFile    modified    by    useHISTORY    r    '    fred'    with    fv        on    2013-11-04T16:59:14\nFile    modified    by    user    'wilma'    HISTORY    with    fv        on    2013-04-22T21:42:18\nFile    modif\nied    by    user    'wilma'    with    fv        HISTORY    on    2013-04-23T11:16:29\nFile    modified    by    use\nr    '    fred'    with    fv        on    2013-1HISTORY    1-04T16:59:14                                                                                                                                                                                                                                            "]
    for card_image in test_cards:
        c = fits.Card.fromstring(card_image)
        if ('\n' in card_image):
            pytest.raises(fits.VerifyError, c.verify, 'exception')
        else:
            c.verify('exception')
