wxPython アプリケーションのテスト中に開いたダイアログを処理するには?
誰かがすでに同様の問題を抱えていたので:
問題は、アプリがモーダル ダイアログを開始するとすぐに、モーダル ダイアログが終了するまでコントロールが返されないことです。モーダル ダイアログが終了すると、テスト スクリプトがデータを入力するには遅すぎます。
一般的に、次のワークフローのテスト ケースを書きたいと思います。
- ユーザーがボタン「SomeProcessing」を押す
- 開いたダイアログで、ユーザーは「選択 1」を選択し、OK を押します
- データは選択に基づいて処理され、既知の結果と比較されます (
data_after_processing
)
ステップ 2 を自動的に行うにはどうすればよいですか (以下の例ではDlg_GetUserInput
、手動入力を待っています)。私のGUIテストの理解には欠陥があり、パート3はGUIテストと見なされるべきではないのでしょうか? その場合、おそらくコードを書き直す必要があります...
どんな提案でも大歓迎です!
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
btn = wx.Button(self, label="SomeProcessing")
self.Bind(wx.EVT_BUTTON, self.SomeProcessing, btn)
def SomeProcessing(self,event):
self.dlg = Dlg_GetUserInput(self)
if self.dlg.ShowModal() == wx.ID_OK:
if self.dlg.sel1.GetValue():
print 'sel1 processing'
self.data_after_processing = 'boo'
if self.dlg.sel2.GetValue():
print 'sel2 processing'
self.data_after_processing = 'foo'
class Dlg_GetUserInput(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.sel1 = wx.CheckBox(self, label='Selection 1')
self.sel2 = wx.CheckBox(self, label='Selection 2')
self.OK = wx.Button(self, wx.ID_OK)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.sel1)
sizer.Add(self.sel2)
sizer.Add(self.OK)
self.SetSizer(sizer)
def test():
app = wx.PySimpleApp()
mf = MyFrame(None, 'testgui')
for item in mf.GetChildren():
if item.GetLabel() == 'SomeProcessing':
btn = item
break
event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
mf.GetEventHandler().ProcessEvent(event)
"""
PROBLEM: here I'd like to simulate user input
sel1 in Dlg_GetUserInput
(i.e. mf.dlg.sel1.SetValue())
and check that
data_after_processing == 'boo'
"""
mf.Destroy()
test()