Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

GuiTestingWithWxPython

From ZeroWiki

TDD로 컨트롤을 하나하나 붙이고 위치값을 잡고 리스트박스에 초기값을 설정하는 예제

test_myframe.py

from wxPython.wx import * 
import unittest 
from MyFrame import MyFrame
 
class TestFrame(unittest.TestCase): 
        def setUp(self): 
                self.frame = MyFrame() 
 
        def tearDown(self): 
                self.frame.Destroy() 
                self.frame = None 
 
        def testFramePositionSize(self): 
                expected = (400,400) 
                self.assertEquals(expected, self.frame.GetSizeTuple()) 
                self.assertEquals(expected, self.frame.GetPositionTuple()) 
 
        def testControls(self): 
                pass 
 
        def testbuttonText(self): 
                expected = "testing" 
                result = self.frame.button.GetLabel() 
                self.assertEquals(expected, result) 
 
        def testButtonRect(self): 
                expected = (100,100) 
                result = self.frame.button.GetPositionTuple() 
                self.assertEquals(expected, result) 
                expected = (200,50) 
                result = self.frame.button.GetSizeTuple() 
                self.assertEquals(expected, result) 
 
        def testListBox(self): 
                expected = ('testing1', 'testing2', 'testing3') 
                self.assertEquals(expected, self.frame.getListItemsTuple()) 
 
class TestApp(wxApp): 
        def OnInit(self): 
            return true 

if __name__=="__main__": 
    testApp=TestApp(0)
    unittest.main(argv=(,'-v'))

myframe.py

from wxPython.wx import *

class MyFrame(wxFrame):
	def __init__(self, parent=NULL, id=NewId(), title='test', pos=(400,400), size=(400,400)):
		wxFrame.__init__(self, parent, id, title, pos, size)

		ID_BUTTON = 10000
		self.button = wxButton(self, ID_BUTTON, "testing", pos=(100,100), size=(200,50))
		self.SetAutoLayout(true)
		#pdb.set_trace()
		self.listBox = wxListBox(self, NewId())
		self.listBox.Append('testing1')
		self.listBox.Append('testing2')
		self.listBox.Append('testing3')

	def getListItemsTuple(self):
		retList = []
		for idx in range(self.listBox.Number()):
			retList.append(self.listBox.GetString(idx))

		return tuple(retList)

class MyApp(wxApp):
	def OnInit(self):
		frame = MyFrame()
		frame.Show(true)
		return true
		
if __name__=="__main__":
	App = MyApp(0)
	App.MainLoop()

GuiTesting