'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/134
Assigning a unicode literal as a header value should not fail silently.
If the value can be converted to ASCII then it should just work.
Otherwise it should fail with an appropriate value error.
Also tests unicode for keywords and comments.'

def test_assign_unicode(self):

    erikku = u('\\u30a8\\u30ea\\u30c3\\u30af')
    def assign(keyword, val):
        h[keyword] = val
    h = fits.Header()
    h[u('FOO')] = 'BAR'
    assert ('FOO' in h)
    assert (h['FOO'] == 'BAR')
    assert (h[u('FOO')] == 'BAR')
    assert (repr(h) == _pad("FOO                    =    'BAR                    '"))
    pytest.raises(ValueError, assign, erikku, 'BAR')
    h['FOO'] = u('BAZ')
    assert (h[u('FOO')] == 'BAZ')
    assert (h[u('FOO')] == u('BAZ'))
    assert (repr(h) == _pad("FOO                    =    'BAZ                    '"))
    pytest.raises(ValueError, assign, 'FOO', erikku)
    h['FOO'] = ('BAR', u('BAZ'))
    assert (h['FOO'] == 'BAR')
    assert (h['FOO'] == u('BAR'))
    assert (h.comments['FOO'] == 'BAZ')
    assert (h.comments['FOO'] == u('BAZ'))
    assert (repr(h) == _pad("FOO                    =    'BAR                    '                                            /    BAZ"))
    h['FOO'] = (u('BAR'), u('BAZ'))
    assert (h['FOO'] == 'BAR')
    assert (h['FOO'] == u('BAR'))
    assert (h.comments['FOO'] == 'BAZ')
    assert (h.comments['FOO'] == u('BAZ'))
    assert (repr(h) == _pad("FOO                    =    'BAR                    '                                            /    BAZ"))
    pytest.raises(ValueError, assign, 'FOO', ('BAR', erikku))
    pytest.raises(ValueError, assign, 'FOO', (erikku, 'BAZ'))
    pytest.raises(ValueError, assign, 'FOO', (erikku, erikku))
