'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/158
Tests several additional use cases for working with HIERARCH cards.'

def test_hierarch_create_and_update(self):

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