[Zope-Checkins] CVS: Zope3/utilities - unittestgui.py:1.1.2.3
Tres Seaver
tseaver@zope.com
Wed, 21 Nov 2001 17:03:04 -0500
Update of /cvs-repository/Zope3/utilities
In directory cvs.zope.org:/tmp/cvs-serv1804/utilities
Modified Files:
Tag: Zope-3x-branch
unittestgui.py
Log Message:
- Unit testing cleanups.
=== Zope3/utilities/unittestgui.py 1.1.2.2 => 1.1.2.3 ===
self.running = 1
self.notifyRunning()
+ warnings = getattr( test, 'warnings', () )
+ for warning in warnings:
+ self.notifyWarning( warning[0], warning[1] )
test.run(self.currentResult)
self.running = 0
self.notifyStopped()
@@ -104,6 +107,9 @@
"Override to set GUI in 'stopped' mode, enabling 'run' button etc."
pass
+ def notifyWarning(self, msg, tb_str):
+ "Override to log a warning message (e.g., couldn't import a test)."
+
def notifyTestFailed(self, test, err):
"Override to indicate that a test has just failed"
pass
@@ -127,16 +133,16 @@
Used by BaseGUITestRunner. Need not be created directly.
"""
def __init__(self, callback):
- unittest.TestResult.__init__(self)
- self.callback = callback
+ unittest.TestResult.__init__(self)
+ self.callback = callback
def addError(self, test, err):
- unittest.TestResult.addError(self, test, err)
- self.callback.notifyTestErrored(test, err)
+ unittest.TestResult.addError(self, test, err)
+ self.callback.notifyTestErrored(test, err)
def addFailure(self, test, err):
- unittest.TestResult.addFailure(self, test, err)
- self.callback.notifyTestFailed(test, err)
+ unittest.TestResult.addFailure(self, test, err)
+ self.callback.notifyTestFailed(test, err)
def stopTest(self, test):
unittest.TestResult.stopTest(self, test)
@@ -196,16 +202,16 @@
"""
self.root = root
# Set up values that will be tied to widgets
- self.suiteNameVar = tk.StringVar()
- self.suiteNameVar.set(initialTestName)
+ self.suiteNameVar = tk.StringVar()
+ self.suiteNameVar.set(initialTestName)
self.statusVar = tk.StringVar()
self.statusVar.set("Idle")
- self.runCountVar = tk.IntVar()
- self.failCountVar = tk.IntVar()
- self.errorCountVar = tk.IntVar()
- self.remainingCountVar = tk.IntVar()
+ self.runCountVar = tk.IntVar()
+ self.failCountVar = tk.IntVar()
+ self.errorCountVar = tk.IntVar()
+ self.remainingCountVar = tk.IntVar()
self.top = tk.Frame()
- self.top.pack(fill=tk.BOTH, expand=1)
+ self.top.pack(fill=tk.BOTH, expand=1)
self.createWidgets()
def createWidgets(self):
@@ -219,11 +225,11 @@
statusFrame.pack(anchor=tk.SW, fill=tk.X, side=tk.BOTTOM)
tk.Label(statusFrame, textvariable=self.statusVar).pack(side=tk.LEFT)
- # Area to enter name of test to run
+ # Area to enter name of test to run
leftFrame = tk.Frame(self.top, borderwidth=3)
leftFrame.pack(fill=tk.BOTH, side=tk.LEFT, anchor=tk.NW, expand=1)
- suiteNameFrame = tk.Frame(leftFrame, borderwidth=3)
- suiteNameFrame.pack(fill=tk.X)
+ suiteNameFrame = tk.Frame(leftFrame, borderwidth=3)
+ suiteNameFrame.pack(fill=tk.X)
tk.Label(suiteNameFrame, text="Enter test name:").pack(side=tk.LEFT)
e = tk.Entry(suiteNameFrame, textvariable=self.suiteNameVar, width=80)
e.pack(side=tk.LEFT, fill=tk.X, expand=1)
@@ -238,12 +244,12 @@
borderwidth=2)
self.progressBar.pack(fill=tk.X, expand=1)
- # Area with buttons to start/stop tests and quit
+ # Area with buttons to start/stop tests and quit
buttonFrame = tk.Frame(self.top, borderwidth=3)
buttonFrame.pack(side=tk.LEFT, anchor=tk.NW, fill=tk.Y)
- self.stopGoButton = tk.Button(buttonFrame, text="Start",
+ self.stopGoButton = tk.Button(buttonFrame, text="Start",
command=self.runClicked)
- self.stopGoButton.pack(fill=tk.X)
+ self.stopGoButton.pack(fill=tk.X)
tk.Button(buttonFrame, text="Close",
command=self.top.quit).pack(side=tk.BOTTOM, fill=tk.X)
tk.Button(buttonFrame, text="About",
@@ -251,7 +257,7 @@
tk.Button(buttonFrame, text="Help",
command=self.showHelpDialog).pack(side=tk.BOTTOM, fill=tk.X)
- # Area with labels reporting results
+ # Area with labels reporting results
for label, var in (('Run:', self.runCountVar),
('Failures:', self.failCountVar),
('Errors:', self.errorCountVar),
@@ -265,10 +271,10 @@
tk.Label(leftFrame, text="Failures and errors:").pack(anchor=tk.W)
listFrame = tk.Frame(leftFrame, relief=tk.SUNKEN, borderwidth=2)
listFrame.pack(fill=tk.BOTH, anchor=tk.NW, expand=1)
- self.errorListbox = tk.Listbox(listFrame, foreground='red',
+ self.errorListbox = tk.Listbox(listFrame, foreground='red',
selectmode=tk.SINGLE,
selectborderwidth=0)
- self.errorListbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=1,
+ self.errorListbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=1,
anchor=tk.NW)
listScroll = tk.Scrollbar(listFrame, command=self.errorListbox.yview)
listScroll.pack(side=tk.LEFT, fill=tk.Y, anchor=tk.N)
@@ -276,6 +282,21 @@
lambda e, self=self: self.showSelectedError())
self.errorListbox.configure(yscrollcommand=listScroll.set)
+ # List box showing warnings
+ tk.Label(leftFrame, text="Warnings:").pack(anchor=tk.W)
+ warnFrame = tk.Frame(leftFrame, relief=tk.SUNKEN, borderwidth=2)
+ warnFrame.pack(fill=tk.BOTH, anchor=tk.NW, expand=1)
+ self.warningListbox = tk.Listbox(warnFrame, foreground='black',
+ selectmode=tk.SINGLE,
+ selectborderwidth=0)
+ self.warningListbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=1,
+ anchor=tk.NW)
+ wListScroll = tk.Scrollbar(warnFrame, command=self.warningListbox.yview)
+ wListScroll.pack(side=tk.LEFT, fill=tk.Y, anchor=tk.N)
+ self.warningListbox.bind("<Double-1>",
+ lambda e, self=self: self.showSelectedWarning())
+ self.warningListbox.configure(yscrollcommand=wListScroll.set)
+
def getSelectedTestName(self):
return self.suiteNameVar.get()
@@ -290,8 +311,11 @@
self.errorCountVar.set(0)
self.remainingCountVar.set(self.totalTests)
self.errorInfo = []
+ self.warnInfo = []
while self.errorListbox.size():
self.errorListbox.delete(0)
+ while self.warningListbox.size():
+ self.warningListbox.delete(0)
#Stopping seems not to work, so simply disable the start button
#self.stopGoButton.config(command=self.stopClicked, text="Stop")
self.stopGoButton.config(state=tk.DISABLED)
@@ -307,6 +331,10 @@
self.statusVar.set(str(test))
self.top.update_idletasks()
+ def notifyWarning(self, msg, tb_str):
+ self.warningListbox.insert(tk.END, "Warning: %s" % msg)
+ self.warnInfo.append((msg,tb_str))
+
def notifyTestFailed(self, test, err):
self.failCountVar.set(1 + self.failCountVar.get())
self.errorListbox.insert(tk.END, "Failure: %s" % test)
@@ -346,6 +374,24 @@
tracebackLines = apply(traceback.format_exception, error + (10,))
tracebackText = string.join(tracebackLines,'')
tk.Label(window, text=tracebackText, justify=tk.LEFT).pack()
+ tk.Button(window, text="Close",
+ command=window.quit).pack(side=tk.BOTTOM)
+ window.bind('<Key-Return>', lambda e, w=window: w.quit())
+ window.mainloop()
+ window.destroy()
+
+ def showSelectedWarning(self):
+ selection = self.warningListbox.curselection()
+ if not selection: return
+ selected = int(selection[0])
+ txt = self.warningListbox.get(selected)
+ window = tk.Toplevel(self.root)
+ window.title(txt)
+ window.protocol('WM_DELETE_WINDOW', window.quit)
+ test, error = self.warnInfo[selected]
+ tk.Label(window, text=str(test),
+ foreground="black", justify=tk.LEFT).pack(anchor=tk.W)
+ tk.Label(window, text=error, justify=tk.LEFT).pack()
tk.Button(window, text="Close",
command=window.quit).pack(side=tk.BOTTOM)
window.bind('<Key-Return>', lambda e, w=window: w.quit())