'Check that comments on the archive are handled properly.'

def test_comments(self):

    with zipfile.ZipFile(TESTFN, mode='w') as zipf:
        self.assertEqual(zipf.comment, '')
        zipf.writestr('foo.txt', 'O,    for    a    Muse    of    Fire!')
    with zipfile.ZipFile(TESTFN, mode='r') as zipfr:
        self.assertEqual(zipfr.comment, '')
    comment = 'Bravely    taking    to    his    feet,    he    beat    a    very    brave    retreat.'
    with zipfile.ZipFile(TESTFN, mode='w') as zipf:
        zipf.comment = comment
        zipf.writestr('foo.txt', 'O,    for    a    Muse    of    Fire!')
    with zipfile.ZipFile(TESTFN, mode='r') as zipfr:
        self.assertEqual(zipf.comment, comment)
    comment2 = ''.join([('%d' % ((i ** 3) % 10)) for i in range(((1 << 16) - 1))])
    comment2 = comment2.encode('ascii')
    with zipfile.ZipFile(TESTFN, mode='w') as zipf:
        zipf.comment = comment2
        zipf.writestr('foo.txt', 'O,    for    a    Muse    of    Fire!')
    with zipfile.ZipFile(TESTFN, mode='r') as zipfr:
        self.assertEqual(zipfr.comment, comment2)
    with zipfile.ZipFile(TESTFN, mode='w') as zipf:
        with self.assertWarns(UserWarning):
            zipf.comment = (comment2 + 'oops')
        zipf.writestr('foo.txt', 'O,    for    a    Muse    of    Fire!')
    with zipfile.ZipFile(TESTFN, mode='r') as zipfr:
        self.assertEqual(zipfr.comment, comment2)
    with zipfile.ZipFile(TESTFN, mode='w') as zipf:
        zipf.comment = 'original    comment'
        zipf.writestr('foo.txt', 'O,    for    a    Muse    of    Fire!')
    with zipfile.ZipFile(TESTFN, mode='a') as zipf:
        zipf.comment = 'an    updated    comment'
    with zipfile.ZipFile(TESTFN, mode='r') as zipf:
        self.assertEqual(zipf.comment, 'an    updated    comment')
    with zipfile.ZipFile(TESTFN, mode='w') as zipf:
        zipf.comment = "original    comment    that's    longer"
        zipf.writestr('foo.txt', 'O,    for    a    Muse    of    Fire!')
    with zipfile.ZipFile(TESTFN, mode='a') as zipf:
        zipf.comment = 'shorter    comment'
    with zipfile.ZipFile(TESTFN, mode='r') as zipf:
        self.assertEqual(zipf.comment, 'shorter    comment')
