本文整理匯總了Python中Picture.setTitle方法的典型用法代碼示例。如果您正苦於以下問題:Python Picture.setTitle方法的具體用法?Python Picture.setTitle怎麽用?Python Picture.setTitle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Picture
的用法示例。
在下文中一共展示了Picture.setTitle方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Test_Picture_BMP
# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import setTitle [as 別名]
#.........這裏部分代碼省略.........
"Pixel (%s,%s): Blue = %s != %s" % (i, j, self.pix1.getBlue(), self.pix2.getBlue()),
)
self.assertEqual(
self.pix1.getGreen(),
self.pix2.getGreen(),
"Pixel (%s,%s): Green = %s != %s" % (i, j, self.pix1.getGreen(), self.pix2.getGreen()),
)
self.pix1array = self.pict.getPixels()
self.pix2array = self.pict2.getPixels()
self.assertEqual(len(self.pix1array), len(self.pix2array), "Error, pixel arrays are different sizes")
for k in range(len(self.pix1array)):
self.pix1 = self.pix1array[k]
self.pix2 = self.pix2array[k]
self.assertEqual(
self.pix1.getRed(),
self.pix2.getRed(),
"Pixel (k:%s): Red = %s != %s" % (k, self.pix1.getRed(), self.pix2.getRed()),
)
self.assertEqual(
self.pix1.getBlue(),
self.pix2.getBlue(),
"Pixel (k:%s): Blue = %s != %s" % (k, self.pix1.getBlue(), self.pix2.getBlue()),
)
self.assertEqual(
self.pix1.getGreen(),
self.pix2.getGreen(),
"Pixel (k:%s): Green = %s != %s" % (k, self.pix1.getGreen(), self.pix2.getGreen()),
)
def testTitlePsB(self):
"""Test picture - changing title from Picture(String) (bmp)"""
self.pict = Picture("white.bmp")
self.assertEqual(self.pict.getTitle(), "white.bmp", "Title %s != white.bmp" % self.pict.getTitle())
self.pict.setTitle("Not white.bmp")
self.assertNotEqual(self.pict.getTitle(), "white.bmp", "Title is still white.bmp")
self.assertEqual(self.pict.getTitle(), "Not white.bmp", "Title %s != Not white.bmp" % self.pict.getTitle())
def testGetPictureWithHeightB1(self):
"""Test Picture.getPictureWithHeight(int) (bmp) [1] - smaller"""
self.pict = Picture()
self.loaded = self.pict.load("addMsg.bmp")
self.assertEqual(self.loaded, 1, "Load is broken")
self.heightSm = self.pict.getHeight() - 20
self.pictSm1 = self.pict.getPictureWithHeight(self.heightSm)
self.assertEqual(
self.pictSm1.getHeight(), self.heightSm, "Height %s!=%s" % (self.pictSm1.getHeight(), self.heightSm)
)
self.pictSm1.write("addMsgSmOut.bmp")
self.pictSm2 = Picture()
self.loaded = self.pictSm2.load("addMsgSmOut.bmp")
self.assertEqual(self.loaded, 1, "Write seems to be broken")
self.pictSm3 = Picture("addMsgSm.bmp")
self.assertEqual(
self.pictSm2.getHeight(),
self.heightSm,
"Either write or load seems to be broken (Height %s != %s)" % (self.pictSm2.getHeight(), self.heightSm),
)
self.assertEqual(
self.pictSm2.getHeight(),
self.pictSm3.getHeight(),
"Height %s != %s" % (self.pictSm2.getHeight(), self.pictSm3.getHeight()),
)
self.widthSm = self.pictSm1.getWidth()
self.assertEqual(
示例2: Test_Picture_GIF
# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import setTitle [as 別名]
#.........這裏部分代碼省略.........
def testPictureCopyB(self):
'''Test Picture(copyPicture) constructor (gif) [all]'''
self.pict = Picture(WHITE_GIF)
self.pict2 = Picture(self.pict)
self.assertEqual(self.pict2.getFileName(), WHITE_GIF, 'Filename %s != %s' % (
self.pict2.getFileName(), WHITE_GIF))
self.assertEqual(self.pict2.getExtension(), 'gif',
'File extension %s != gif' % self.pict2.getExtension())
self.assertEqual(self.pict2.getTitle(), WHITE_GIF_TITLE, 'Title %s != %s' % (
self.pict2.getTitle(), WHITE_GIF_TITLE))
self.height = self.pict.getHeight()
self.assertEqual(self.height, 50, 'Height %s != 50' % self.height)
self.width = self.pict.getWidth()
self.assertEqual(self.width, 50, 'Width %s != 50' % self.width)
self.assertNotEqual(self.pict2.getWidth(), 49, 'Width is 49?')
self.assertEqual(self.pict.toString(), 'Picture, filename %s height 50 width 50' % WHITE_GIF,
'toString %s != Picture, filename %s height 50 width 50' % (self.pict.toString(), WHITE_GIF))
for i in range(self.width):
for j in range(self.height):
self.pix1 = self.pict.getPixel(i, j)
self.pix2 = self.pict2.getPixel(i, j)
self.assertEqual(self.pix1.getRed(), self.pix2.getRed(
), 'Pixel (%s,%s): Red = %s != %s' % (i, j, self.pix1.getRed(), self.pix2.getRed()))
self.assertEqual(self.pix1.getBlue(), self.pix2.getBlue(
), 'Pixel (%s,%s): Blue = %s != %s' % (i, j, self.pix1.getBlue(), self.pix2.getBlue()))
self.assertEqual(self.pix1.getGreen(), self.pix2.getGreen(
), 'Pixel (%s,%s): Green = %s != %s' % (i, j, self.pix1.getGreen(), self.pix2.getGreen()))
self.pix1array = self.pict.getPixels()
self.pix2array = self.pict2.getPixels()
self.assertEqual(len(self.pix1array), len(
self.pix2array), 'Error, pixel arrays are different sizes')
for k in range(len(self.pix1array)):
self.pix1 = self.pix1array[k]
self.pix2 = self.pix2array[k]
self.assertEqual(self.pix1.getRed(), self.pix2.getRed(
), 'Pixel (k:%s): Red = %s != %s' % (k, self.pix1.getRed(), self.pix2.getRed()))
self.assertEqual(self.pix1.getBlue(), self.pix2.getBlue(
), 'Pixel (k:%s): Blue = %s != %s' % (k, self.pix1.getBlue(), self.pix2.getBlue()))
self.assertEqual(self.pix1.getGreen(), self.pix2.getGreen(
), 'Pixel (k:%s): Green = %s != %s' % (k, self.pix1.getGreen(), self.pix2.getGreen()))
def testTitlePsB(self):
'''Test picture - changing title from Picture(String) (gif)'''
self.pict = Picture(WHITE_GIF)
self.assertEqual(self.pict.getTitle(), WHITE_GIF_TITLE, 'Title %s != %s' % (
self.pict.getTitle(), WHITE_GIF_TITLE))
self.pict.setTitle("Not white.gif")
self.assertNotEqual(
self.pict.getTitle(), WHITE_GIF_TITLE, 'Title is still %s' % WHITE_GIF)
self.assertEqual(self.pict.getTitle(), 'Not white.gif',
'Title %s != Not white.gif' % self.pict.getTitle())
def testGetPictureWithHeightB1(self):
'''Test Picture.getPictureWithHeight(int) (gif) [1] - smaller'''
self.pict = Picture()
self.loaded = self.pict.load(PICTURES + "addMsg.gif")
self.assertEqual(self.loaded, 1, "Load is broken")
self.heightSm = self.pict.getHeight() - 20
self.pictSm1 = self.pict.getPictureWithHeight(self.heightSm)
self.assertEqual(self.pictSm1.getHeight(), self.heightSm, 'Height %s!=%s' % (
self.pictSm1.getHeight(), self.heightSm))
self.pictSm3 = Picture(PICTURES + "addMsgSm.gif")
self.assertEqual(self.pictSm1.getHeight(), self.pictSm3.getHeight(
), 'Height %s != %s' % (self.pictSm1.getHeight(), self.pictSm3.getHeight()))
self.widthSm = self.pictSm1.getWidth()
self.assertEqual(self.widthSm, self.pictSm1.getWidth(), 'Width %s != %s' % (
self.widthSm, self.pictSm1.getWidth()))
self.assertEqual(self.pictSm1.getWidth(), self.pictSm3.getWidth(
), 'Width %s != %s' % (self.pictSm1.getWidth(), self.pictSm3.getWidth()))
for i in range(self.widthSm):
for j in range(self.heightSm):
self.pix1 = self.pictSm1.getBasicPixel(i, j)
self.pix2 = self.pictSm3.getBasicPixel(i, j)
self.assertEqual(
self.pix1, self.pix2, 'Pixel (%s,%s): %s!=%s' % (i, j, self.pix1, self.pix2))
def testGetPictureWithHeightB2(self):
'''Test Picture.getPictureWithHeight(int) (gif) [2] - larger'''
self.pict = Picture()
self.loaded = self.pict.load(PICTURES + "addMsg.gif")
self.assertEqual(self.loaded, 1, "Load is broken")
self.heightLg = self.pict.getHeight() + 20
self.pictLg1 = self.pict.getPictureWithHeight(self.heightLg)
self.assertEqual(self.pictLg1.getHeight(), self.heightLg, 'Height %s!=%s' % (
self.pictLg1.getHeight(), self.heightLg))
self.pictLg3 = Picture(PICTURES + "addMsgLg.gif")
self.assertEqual(self.pictLg1.getHeight(), self.pictLg3.getHeight(
), 'Height %s != %s' % (self.pictLg1.getHeight(), self.pictLg3.getHeight()))
self.widthLg = self.pictLg1.getWidth()
self.assertEqual(self.widthLg, self.pictLg1.getWidth(), 'Width %s != %s' % (
self.widthLg, self.pictLg1.getWidth()))
self.assertEqual(self.pictLg1.getWidth(), self.pictLg3.getWidth(
), 'Width %s != %s' % (self.pictLg1.getWidth(), self.pictLg3.getWidth()))
for i in range(self.widthLg):
for j in range(self.heightLg):
self.pix1 = self.pictLg1.getBasicPixel(i, j)
self.pix2 = self.pictLg3.getBasicPixel(i, j)
self.assertEqual(
self.pix1, self.pix2, 'Pixel (%s,%s): %s!=%s' % (i, j, self.pix1, self.pix2))
示例3: Test_Picture
# 需要導入模塊: import Picture [as 別名]
# 或者: from Picture import setTitle [as 別名]
class Test_Picture(unittest.TestCase):
# def setUp(self):
# No code needed here
# Would run at the start of every individual test
#
# Timmy: I think these null tests are worthless since the book
# doesn't ever use a null picture, it always uses
# makePicture(filename)
# def testPictureNull1(self):
# '''Test Picture() constructor [1] - filename'''
# self.pict = Picture()
# self.assertEqual('%s'%self.pict.getFileName(), 'None', 'Filename %s != None' % self.pict.getFileName())
# def testPictureNull2(self):
# '''Test Picture() constructor [2] - extension'''
# self.pict = Picture()
# self.assertEqual('%s'%self.pict.getExtension(), 'None', 'File extension %s != None' % self.pict.getExtension())
# def testPictureNull3(self):
# '''Test Picture() constructor [3] - title'''
# self.pict = Picture()
# self.assertEqual('%s'%self.pict.getTitle(), 'None', 'Title %s != None' % self.pict.getTitle())
# def testPictureNull4(self):
# '''Test Picture() constructor [4] - width'''
# self.pict = Picture()
# self.assertEqual(self.pict.getWidth(), 0, 'Width %s != 0' % self.pict.getWidth())
# self.assertNotEqual(self.pict.getWidth(), 1, 'Width is 1?')
# def testPictureNull5(self):
# '''Test Picture() constructor [5] - height'''
# self.pict = Picture()
# self.assertEqual(self.pict.getHeight(), 0, 'Height %s != 0' % self.pict.getHeight())
# def testPictureNull6(self):
# '''Test Picture() constructor [6] - toString'''
# self.pict = Picture()
# self.assertEqual(self.pict.toString(), 'Picture, filename null height 0 width 0',
# 'toString %s != Picture, filename null height 0 width 0' % self.pict.toString())
# def testPictureNull(self):
# '''Test Picture() constructor [all]'''
# self.pict = Picture()
# NOTE: Must do a null check here by sending null to '%s' so it prints as 'None' and does not
# end up throwing a null pointer exception
# self.assertEqual('%s'%self.pict.getFileName(), 'None', 'Filename %s != None' % self.pict.getFileName())
# self.assertEqual('%s'%self.pict.getExtension(), 'None', 'File extension %s != None' % self.pict.getExtension())
# self.assertEqual('%s'%self.pict.getTitle(), 'None', 'Title %s != None' % self.pict.getTitle())
# self.assertEqual(self.pict.getWidth(), 0, 'Width %s != 0' % self.pict.getWidth())
# self.assertEqual(self.pict.getHeight(), 0, 'Height %s != 0' % self.pict.getHeight())
# self.assertNotEqual(self.pict.getWidth(), 1, 'Width is 1?')
# self.assertEqual(self.pict.toString(), 'Picture, filename None height 0 width 0',
# 'toString %s != Picture, filename None height 0 width 0' % self.pict.toString())
def testPictureWdtHgt(self):
'''Test Picture(width, height) constructor'''
self.pict = Picture(500, 500)
# NOTE: Must do a null check here by sending null to '%s' so it prints as 'None' and does not
# end up throwing a null pointer exception
# self.assertEqual('%s'%self.pict.getFileName(), 'None', 'Filename %s != None' % self.pict.getFileName())
# self.assertEqual(self.pict.getExtension(), 'jpg', 'File extension %s != jpg' % self.pict.getExtension())
# self.assertEqual(self.pict.getTitle(), 'New Picture', 'Title %s != New Picture' % self.pict.getTitle())
self.assertEqual(
media.getWidth(self.pict), 500, 'Width %s != 500' % self.pict.getWidth())
self.assertEqual(
media.getHeight(self.pict), 500, 'Height %s != 500' % self.pict.getHeight())
# self.assertNotEqual(self.pict.getWidth(), 499, 'Width is 499?')
# self.assertEqual(self.pict.toString(), 'Picture, filename null height 500 width 500',
# 'toString %s != Picture, filename null height 500 width 500' % self.pict.toString())
def testTitleP(self):
'''Test picture - changing title from Picture()'''
self.pict = Picture()
self.assertEqual(
'%s' % self.pict.getTitle(), 'None', 'Title %s != None' % self.pict.getTitle())
self.pict.setTitle("Blank object")
self.assertNotEqual(
'%s' % self.pict.getTitle(), 'None', 'Title did not change')
self.assertEqual(self.pict.getTitle(), 'Blank object',
'Title %s != Blank object' % self.pict.getTitle())
def testTitlePII(self):
'''Test picture - changing title from Picture(int,int)'''
self.pict = Picture(20, 20)
self.assertEqual(
'%s' % self.pict.getTitle(), 'None', 'Title %s != None' % self.pict.getTitle())
self.pict.setTitle("Blank object")
self.assertNotEqual(
'%s' % self.pict.getTitle(), 'None', 'Title did not change')
self.assertEqual(self.pict.getTitle(), 'Blank object',
'Title %s != Blank object' % self.pict.getTitle())
def testAddMessage(self):
'''Test Picture.addMessage'''
self.pict = Picture(150, 50)
self.pict.addMessage("This is a test", 25, 25)
self.pict.addText(media.red, 10, 10, "test")
#.........這裏部分代碼省略.........