'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/158
Tests several additional use cases for working with HIERARCH cards,
specifically where the keyword is fewer than 8 characters, but contains
invalid characters such that it can only be created as a HIERARCH card.'

def test_short_hierarch_create_and_update(self):

    msg = 'a    HIERARCH    card    will    be    created'
    header = fits.Header()
    with catch_warnings(VerifyWarning) as w:
        header.update({'HIERARCH    BLA    BLA': 'TESTA'})
        assert (len(w) == 0)
        assert ('BLA    BLA' in header)
        assert (header['BLA    BLA'] == 'TESTA')
        header.update({'HIERARCH    BLA    BLA': 'TESTB'})
        assert (len(w) == 0)
        assert header['BLA    BLA'], 'TESTB'
        header.update({'BLA    BLA': 'TESTC'})
        assert (len(w) == 1)
        assert header['BLA    BLA'], 'TESTC'
        header.update({'HIERARCH    bla    bla': 'TESTD'})
        assert (len(w) == 1)
        assert (len(header) == 1)
        assert header['bla    bla'], 'TESTD'
        header.update({'bla    bla': 'TESTE'})
        assert (len(w) == 2)
        assert (len(header) == 1)
        assert header['bla    bla'], 'TESTE'
    header = fits.Header()
    with catch_warnings(VerifyWarning) as w:
        header.update({'BLA    BLA': 'TESTA'})
        print [x.category for x in w]
        assert (len(w) == 1)
        assert (msg in str(w[0].message))
        header.update({'HIERARCH    BLA    BLA': 'TESTB'})
        assert (len(w) == 1)
        assert header['BLA    BLA'], 'TESTB'
        header.update({'BLA    BLA': 'TESTC'})
        assert (len(w) == 2)
        assert header['BLA    BLA'], 'TESTC'
        header.update({'HIERARCH    bla    bla': 'TESTD'})
        assert (len(w) == 2)
        assert (len(header) == 1)
        assert header['bla    bla'], 'TESTD'
        header.update({'bla    bla': 'TESTE'})
        assert (len(w) == 3)
        assert (len(header) == 1)
        assert header['bla    bla'], 'TESTE'
