#!/usr/bin/python3.1 import unittest import email.mime.image class emailEncoderTestCase(unittest.TestCase): def setUp(self): bindata = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x00\x00\x00\x00V\x11%(\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\tpHYs\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\x00\x18IDAT8\xcbc\xfc\xcf\x80\x1f01\x8c*\x18U0\xaa`\x84*\x00\x00\xa3=\x01?\x96"\xc5\xf6\x00\x00\x00\x00IEND\xaeB`\x82' self.mimed = email.mime.image.MIMEImage(bindata) def test_convert(self): base64ed = self.mimed.get_payload() # uncoment the print for a visual clarification of the problem. #print (base64ed) # work out if any line within the string is > 76 chars chopped = base64ed.split('\n') lengths = [ len(x) for x in chopped ] toolong = [ x for x in lengths if x > 76 ] msg = 'There is at least one line of ' + str(max(lengths)) + ' chars.' self.assertEqual(0, len(toolong), msg) if __name__ == '__main__': unittest.main()